2021-12-01 11:37:18 +00:00
|
|
|
|
--[[--
|
|
|
|
|
Widget for setting the date or time.
|
|
|
|
|
|
|
|
|
|
Example for input a time:
|
|
|
|
|
local DateTimeWidget = require("ui/widget/datetimewidget")
|
|
|
|
|
local @{gettext|_} = require("gettext")
|
|
|
|
|
|
|
|
|
|
local time_widget = DateTimeWidget:new{
|
|
|
|
|
hour = 10,
|
|
|
|
|
min = 30,
|
|
|
|
|
ok_text = _("Set time"),
|
|
|
|
|
title_text = _("Set time"),
|
2022-05-23 18:32:59 +00:00
|
|
|
|
info_text = _("Some information"),
|
2021-12-01 11:37:18 +00:00
|
|
|
|
callback = function(time)
|
|
|
|
|
-- use time.hour and time.min here
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
UIManager:show(time_widget)
|
|
|
|
|
|
|
|
|
|
Example for input a date:
|
|
|
|
|
local DateTimeWidget = require("ui/widget/datetimewidget")
|
|
|
|
|
local @{gettext|_} = require("gettext")
|
|
|
|
|
|
|
|
|
|
local date_widget = DateTimeWidget:new{
|
|
|
|
|
year = 2021,
|
|
|
|
|
month = 12,
|
|
|
|
|
day = 31,
|
|
|
|
|
ok_text = _("Set date"),
|
|
|
|
|
title_text = _("Set date"),
|
|
|
|
|
callback = function(time)
|
|
|
|
|
-- use time.year, time.month, time.day here
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
UIManager:show(date_widget)
|
|
|
|
|
|
2022-05-23 18:32:59 +00:00
|
|
|
|
Example to input a duration in days, hours and minutes:
|
|
|
|
|
local DateTimeWidget = require("ui/widget/datetimewidget")
|
|
|
|
|
local @{gettext|_} = require("gettext")
|
|
|
|
|
|
|
|
|
|
local date_widget = DateTimeWidget:new{
|
|
|
|
|
day = 5,
|
|
|
|
|
hour = 12,
|
|
|
|
|
min = 0,
|
|
|
|
|
ok_text = _("Set"),
|
|
|
|
|
title_text = _("Set duration"),
|
|
|
|
|
callback = function(time)
|
|
|
|
|
-- use time.day, time.hour, time.min here
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
UIManager:show(date_widget)
|
2021-12-01 11:37:18 +00:00
|
|
|
|
--]]--
|
|
|
|
|
|
2017-09-18 17:04:36 +00:00
|
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
|
|
|
|
local ButtonTable = require("ui/widget/buttontable")
|
|
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
|
|
|
|
local Device = require("device")
|
2022-03-04 20:20:00 +00:00
|
|
|
|
local FocusManager = require("ui/widget/focusmanager")
|
2017-09-18 17:04:36 +00:00
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
|
local GestureRange = require("ui/gesturerange")
|
|
|
|
|
local Font = require("ui/font")
|
|
|
|
|
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
|
|
|
|
local NumberPickerWidget = require("ui/widget/numberpickerwidget")
|
2017-09-13 14:56:20 +00:00
|
|
|
|
local Size = require("ui/size")
|
2022-05-23 18:32:59 +00:00
|
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
2022-01-19 11:02:13 +00:00
|
|
|
|
local TitleBar = require("ui/widget/titlebar")
|
2017-09-18 17:04:36 +00:00
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
|
|
|
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
|
|
|
|
local _ = require("gettext")
|
|
|
|
|
local Screen = Device.screen
|
2021-11-28 21:18:44 +00:00
|
|
|
|
local T = require("ffi/util").template
|
2017-09-18 17:04:36 +00:00
|
|
|
|
|
2022-09-27 23:10:50 +00:00
|
|
|
|
local DateTimeWidget = FocusManager:extend{
|
2017-09-18 17:04:36 +00:00
|
|
|
|
title_face = Font:getFace("x_smalltfont"),
|
2021-09-25 17:59:45 +00:00
|
|
|
|
info_text = nil,
|
2017-09-18 17:04:36 +00:00
|
|
|
|
width = nil,
|
|
|
|
|
height = nil,
|
2021-09-13 15:55:50 +00:00
|
|
|
|
ok_text = _("Apply"),
|
|
|
|
|
cancel_text = _("Close"),
|
2021-09-25 17:59:45 +00:00
|
|
|
|
-- Optional extra button on bottom
|
|
|
|
|
extra_text = nil,
|
|
|
|
|
extra_callback = nil,
|
2017-09-18 17:04:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-25 17:59:45 +00:00
|
|
|
|
function DateTimeWidget:init()
|
2022-05-23 18:32:59 +00:00
|
|
|
|
self.nb_pickers = 0
|
|
|
|
|
if self.year then
|
|
|
|
|
self.nb_pickers = self.nb_pickers + 1
|
|
|
|
|
end
|
|
|
|
|
if self.month then
|
|
|
|
|
self.nb_pickers = self.nb_pickers + 1
|
|
|
|
|
end
|
|
|
|
|
if self.day then
|
|
|
|
|
self.nb_pickers = self.nb_pickers + 1
|
|
|
|
|
end
|
|
|
|
|
if self.hour then
|
|
|
|
|
self.nb_pickers = self.nb_pickers + 1
|
|
|
|
|
end
|
|
|
|
|
if self.min then
|
|
|
|
|
self.nb_pickers = self.nb_pickers + 1
|
|
|
|
|
end
|
|
|
|
|
if self.sec then
|
|
|
|
|
self.nb_pickers = self.nb_pickers + 1
|
|
|
|
|
end
|
|
|
|
|
|
2022-03-04 20:20:00 +00:00
|
|
|
|
self.layout = {}
|
2017-09-13 14:56:20 +00:00
|
|
|
|
self.screen_width = Screen:getWidth()
|
|
|
|
|
self.screen_height = Screen:getHeight()
|
2022-05-23 18:32:59 +00:00
|
|
|
|
local width_scale_factor = 0.6
|
|
|
|
|
if self.nb_pickers == 3 then
|
|
|
|
|
width_scale_factor = 0.8
|
|
|
|
|
elseif self.nb_pickers == 4 then
|
|
|
|
|
width_scale_factor = 0.85
|
|
|
|
|
elseif self.nb_pickers >=5 then
|
|
|
|
|
width_scale_factor = 0.95
|
|
|
|
|
end
|
|
|
|
|
self.width = self.width or math.floor(math.min(self.screen_width, self.screen_height) * width_scale_factor)
|
2017-09-18 17:04:36 +00:00
|
|
|
|
if Device:hasKeys() then
|
2022-10-27 00:01:51 +00:00
|
|
|
|
self.key_events.Close = { { Device.input.group.Back } }
|
2017-09-18 17:04:36 +00:00
|
|
|
|
end
|
|
|
|
|
if Device:isTouchDevice() then
|
2022-10-27 00:01:51 +00:00
|
|
|
|
self.ges_events.TapClose = {
|
|
|
|
|
GestureRange:new{
|
|
|
|
|
ges = "tap",
|
|
|
|
|
range = Geom:new{
|
|
|
|
|
w = self.screen_width,
|
|
|
|
|
h = self.screen_height,
|
|
|
|
|
}
|
2017-09-18 17:04:36 +00:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
end
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
|
|
|
|
|
|
-- Actually the widget layout
|
2022-03-04 20:20:00 +00:00
|
|
|
|
self:createLayout()
|
2017-09-18 17:04:36 +00:00
|
|
|
|
end
|
|
|
|
|
|
2022-03-04 20:20:00 +00:00
|
|
|
|
function DateTimeWidget:createLayout()
|
2022-09-27 23:10:50 +00:00
|
|
|
|
-- Empty table w/ the methods we use NOP'ed
|
|
|
|
|
local dummy_widget = {}
|
|
|
|
|
function dummy_widget:free() end
|
|
|
|
|
function dummy_widget:getValue() end
|
|
|
|
|
function dummy_widget:update() end
|
|
|
|
|
|
|
|
|
|
-- The following calculation is stolen from NumberPickerWidget
|
2022-05-23 18:32:59 +00:00
|
|
|
|
local number_picker_widgets_width = math.floor(math.min(self.screen_width, self.screen_height) * 0.2)
|
|
|
|
|
if self.nb_pickers > 3 then
|
|
|
|
|
number_picker_widgets_width = math.floor(number_picker_widgets_width * 3 / self.nb_pickers)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if self.year then
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self.year_widget = NumberPickerWidget:new{
|
2022-05-23 18:32:59 +00:00
|
|
|
|
show_parent = self,
|
|
|
|
|
value = self.year,
|
|
|
|
|
value_min = self.year_min or 2021,
|
|
|
|
|
value_max = self.year_max or 2525,
|
|
|
|
|
value_step = 1,
|
|
|
|
|
value_hold_step = self.year_hold_step or 4,
|
|
|
|
|
width = number_picker_widgets_width,
|
|
|
|
|
}
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self:mergeLayoutInHorizontal(self.year_widget)
|
2022-05-23 18:32:59 +00:00
|
|
|
|
else
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self.year_widget = dummy_widget
|
2022-03-04 20:20:00 +00:00
|
|
|
|
end
|
2022-05-23 18:32:59 +00:00
|
|
|
|
if self.month then
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self.month_widget = NumberPickerWidget:new{
|
2022-05-23 18:32:59 +00:00
|
|
|
|
show_parent = self,
|
|
|
|
|
value = self.month,
|
|
|
|
|
value_min = self.month_min or 1,
|
|
|
|
|
value_max = self.month_max or 12,
|
|
|
|
|
value_step = 1,
|
|
|
|
|
value_hold_step = self.month_hold_step or 3,
|
|
|
|
|
width = number_picker_widgets_width,
|
|
|
|
|
}
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self:mergeLayoutInHorizontal(self.month_widget)
|
2022-05-23 18:32:59 +00:00
|
|
|
|
else
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self.month_widget = dummy_widget
|
2022-05-23 18:32:59 +00:00
|
|
|
|
end
|
|
|
|
|
if self.day then
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self.day_widget = NumberPickerWidget:new{
|
2022-05-23 18:32:59 +00:00
|
|
|
|
show_parent = self,
|
|
|
|
|
value = self.day,
|
|
|
|
|
value_min = self.day_min or 1,
|
|
|
|
|
value_max = self.day_max or 31,
|
|
|
|
|
value_step = 1,
|
|
|
|
|
value_hold_step = self.day_hold_step or 3,
|
|
|
|
|
width = number_picker_widgets_width,
|
|
|
|
|
}
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self:mergeLayoutInHorizontal(self.day_widget)
|
2022-05-23 18:32:59 +00:00
|
|
|
|
else
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self.day_widget = dummy_widget
|
2022-05-23 18:32:59 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if self.hour then
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self.hour_widget = NumberPickerWidget:new{
|
2022-05-23 18:32:59 +00:00
|
|
|
|
show_parent = self,
|
|
|
|
|
value = self.hour,
|
|
|
|
|
value_min = self.hour_min or 0,
|
|
|
|
|
value_max = self.hour_max or 23,
|
|
|
|
|
value_step = 1,
|
|
|
|
|
value_hold_step = self.hour_hold_step or 4,
|
|
|
|
|
width = number_picker_widgets_width,
|
|
|
|
|
}
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self:mergeLayoutInHorizontal(self.hour_widget)
|
2022-05-23 18:32:59 +00:00
|
|
|
|
else
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self.hour_widget = dummy_widget
|
2022-05-23 18:32:59 +00:00
|
|
|
|
end
|
|
|
|
|
if self.min then
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self.min_widget = NumberPickerWidget:new{
|
2022-05-23 18:32:59 +00:00
|
|
|
|
show_parent = self,
|
|
|
|
|
value = self.min,
|
|
|
|
|
value_min = self.min_min or 0,
|
|
|
|
|
value_max = self.min_max or 59,
|
|
|
|
|
value_step = 1,
|
|
|
|
|
value_hold_step = self.min_hold_step or 10,
|
|
|
|
|
width = number_picker_widgets_width,
|
|
|
|
|
}
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self:mergeLayoutInHorizontal(self.min_widget)
|
2022-05-23 18:32:59 +00:00
|
|
|
|
else
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self.min_widget = dummy_widget
|
2022-05-23 18:32:59 +00:00
|
|
|
|
end
|
|
|
|
|
if self.sec then
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self.sec_widget = NumberPickerWidget:new{
|
2022-05-23 18:32:59 +00:00
|
|
|
|
show_parent = self,
|
|
|
|
|
value = self.sec,
|
|
|
|
|
value_min = self.sec_min or 0,
|
|
|
|
|
value_max = self.sec_max or 59,
|
|
|
|
|
value_step = 1,
|
|
|
|
|
value_hold_step = self.sec_hold_step or 10,
|
|
|
|
|
width = number_picker_widgets_width,
|
|
|
|
|
}
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self:mergeLayoutInHorizontal(self.sec_widget)
|
2022-05-23 18:32:59 +00:00
|
|
|
|
else
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self.sec_widget = dummy_widget
|
2022-05-23 18:32:59 +00:00
|
|
|
|
end
|
|
|
|
|
|
2022-09-27 23:10:50 +00:00
|
|
|
|
local separator_date = TextWidget:new{
|
2022-05-23 18:32:59 +00:00
|
|
|
|
text = "–",
|
|
|
|
|
face = self.title_face,
|
|
|
|
|
bold = true,
|
2017-09-18 17:04:36 +00:00
|
|
|
|
}
|
2022-09-27 23:10:50 +00:00
|
|
|
|
local separator_time = TextWidget:new{
|
2022-05-29 20:32:16 +00:00
|
|
|
|
text = ":",
|
2022-05-23 18:32:59 +00:00
|
|
|
|
face = self.title_face,
|
|
|
|
|
bold = true,
|
2017-09-18 17:04:36 +00:00
|
|
|
|
}
|
2022-09-27 23:10:50 +00:00
|
|
|
|
local separator_date_time = TextWidget:new{
|
2022-05-29 20:32:16 +00:00
|
|
|
|
text = "/",
|
2017-09-18 17:04:36 +00:00
|
|
|
|
face = self.title_face,
|
|
|
|
|
bold = true,
|
|
|
|
|
}
|
|
|
|
|
local date_group = HorizontalGroup:new{
|
2022-05-23 18:32:59 +00:00
|
|
|
|
align = "center",
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self.year_widget, -- 1
|
2022-05-23 18:32:59 +00:00
|
|
|
|
separator_date, -- 2
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self.month_widget, -- 3
|
2022-05-23 18:32:59 +00:00
|
|
|
|
separator_date, -- 4
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self.day_widget, -- 5
|
2022-05-23 18:32:59 +00:00
|
|
|
|
separator_date_time, -- 6
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self.hour_widget, -- 7
|
2022-05-23 18:32:59 +00:00
|
|
|
|
separator_time, -- 8
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self.min_widget, -- 9
|
2022-05-23 18:32:59 +00:00
|
|
|
|
separator_time, -- 10
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self.sec_widget, -- 11
|
2022-05-23 18:32:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-- remove empty widgets plus trailling placeholder
|
|
|
|
|
for i = #date_group, 1, -2 do
|
|
|
|
|
if date_group[i] == dummy_widget then
|
|
|
|
|
table.remove(date_group, i)
|
|
|
|
|
table.remove(date_group, i-1)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- clean up leading separator
|
|
|
|
|
if date_group[1] == separator_date or date_group[1] == separator_date_time or date_group[1] == separator_time then
|
2021-09-25 17:59:45 +00:00
|
|
|
|
table.remove(date_group, 1)
|
|
|
|
|
end
|
2017-09-18 17:04:36 +00:00
|
|
|
|
|
2022-01-19 11:02:13 +00:00
|
|
|
|
local title_bar = TitleBar:new{
|
|
|
|
|
width = self.width,
|
|
|
|
|
align = "left",
|
|
|
|
|
with_bottom_line = true,
|
|
|
|
|
title = self.title_text,
|
|
|
|
|
title_shrink_font_to_fit = true,
|
|
|
|
|
info_text = self.info_text,
|
|
|
|
|
show_parent = self,
|
2017-09-18 17:04:36 +00:00
|
|
|
|
}
|
2021-11-28 21:18:44 +00:00
|
|
|
|
|
|
|
|
|
local buttons = {}
|
|
|
|
|
if self.default_value then
|
|
|
|
|
table.insert(buttons, {
|
2017-09-18 17:04:36 +00:00
|
|
|
|
{
|
2021-11-28 21:18:44 +00:00
|
|
|
|
text = self.default_text or T(_("Default value: %1"), self.default_value),
|
2017-09-18 17:04:36 +00:00
|
|
|
|
callback = function()
|
2021-11-28 21:18:44 +00:00
|
|
|
|
if self.default_callback then
|
2022-05-23 18:32:59 +00:00
|
|
|
|
self.default_callback({
|
2022-09-27 23:10:50 +00:00
|
|
|
|
year = self.year_widget:getValue(),
|
|
|
|
|
month = self.month_widget:getValue(),
|
|
|
|
|
day = self.day_widget:getValue(),
|
|
|
|
|
hour = self.hour_widget:getValue(),
|
|
|
|
|
minute = self.min_widget:getValue(),
|
|
|
|
|
second = self.sec_widget:getValue(),
|
2022-05-23 18:32:59 +00:00
|
|
|
|
})
|
2021-11-28 21:18:44 +00:00
|
|
|
|
end
|
|
|
|
|
if not self.keep_shown_on_apply then -- assume extra wants it same as ok
|
|
|
|
|
self:onClose()
|
2017-09-18 17:04:36 +00:00
|
|
|
|
end
|
|
|
|
|
end,
|
|
|
|
|
},
|
2021-11-28 21:18:44 +00:00
|
|
|
|
})
|
|
|
|
|
end
|
2021-09-25 17:59:45 +00:00
|
|
|
|
if self.extra_text then
|
2021-11-28 21:18:44 +00:00
|
|
|
|
table.insert(buttons, {
|
2021-09-25 17:59:45 +00:00
|
|
|
|
{
|
|
|
|
|
text = self.extra_text,
|
|
|
|
|
callback = function()
|
2021-11-28 21:18:44 +00:00
|
|
|
|
self.extra_callback(self)
|
2021-09-25 17:59:45 +00:00
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
end
|
2021-11-28 21:18:44 +00:00
|
|
|
|
table.insert(buttons, {
|
|
|
|
|
{
|
|
|
|
|
text = self.cancel_text,
|
|
|
|
|
callback = function()
|
2022-05-23 18:32:59 +00:00
|
|
|
|
if self.cancel_callback then
|
|
|
|
|
self.cancel_callback(self)
|
|
|
|
|
end
|
2021-11-28 21:18:44 +00:00
|
|
|
|
self:onClose()
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text = self.ok_text,
|
|
|
|
|
callback = function()
|
|
|
|
|
if self.callback then
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self.year = self.year_widget:getValue()
|
|
|
|
|
self.month = self.month_widget:getValue()
|
|
|
|
|
self.day = self.day_widget:getValue()
|
|
|
|
|
self.hour = self.hour_widget:getValue()
|
|
|
|
|
self.min = self.min_widget:getValue()
|
|
|
|
|
self.sec = self.sec_widget:getValue()
|
2021-11-28 21:18:44 +00:00
|
|
|
|
self:callback(self)
|
|
|
|
|
end
|
|
|
|
|
self:onClose()
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
})
|
2017-09-18 17:04:36 +00:00
|
|
|
|
|
|
|
|
|
local ok_cancel_buttons = ButtonTable:new{
|
2017-10-08 15:53:25 +00:00
|
|
|
|
width = self.width - 2*Size.padding.default,
|
2017-09-18 17:04:36 +00:00
|
|
|
|
buttons = buttons,
|
2017-10-08 15:53:25 +00:00
|
|
|
|
zero_sep = true,
|
2017-09-18 17:04:36 +00:00
|
|
|
|
show_parent = self,
|
|
|
|
|
}
|
2022-03-04 20:20:00 +00:00
|
|
|
|
self:mergeLayoutInVertical(ok_cancel_buttons)
|
2017-09-18 17:04:36 +00:00
|
|
|
|
|
|
|
|
|
self.date_frame = FrameContainer:new{
|
2017-09-13 14:56:20 +00:00
|
|
|
|
radius = Size.radius.window,
|
|
|
|
|
bordersize = Size.border.window,
|
2017-09-18 17:04:36 +00:00
|
|
|
|
padding = 0,
|
|
|
|
|
margin = 0,
|
|
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
|
|
|
|
VerticalGroup:new{
|
|
|
|
|
align = "left",
|
2022-01-19 11:02:13 +00:00
|
|
|
|
title_bar,
|
2017-09-18 17:04:36 +00:00
|
|
|
|
CenterContainer:new{
|
|
|
|
|
dimen = Geom:new{
|
2021-09-13 15:55:50 +00:00
|
|
|
|
w = self.width,
|
2020-06-12 23:56:36 +00:00
|
|
|
|
h = math.floor(date_group:getSize().h * 1.2),
|
2017-09-18 17:04:36 +00:00
|
|
|
|
},
|
|
|
|
|
date_group
|
|
|
|
|
},
|
2017-10-08 15:53:25 +00:00
|
|
|
|
CenterContainer:new{
|
|
|
|
|
dimen = Geom:new{
|
|
|
|
|
w = self.width,
|
|
|
|
|
h = ok_cancel_buttons:getSize().h,
|
|
|
|
|
},
|
|
|
|
|
ok_cancel_buttons
|
|
|
|
|
}
|
2017-09-18 17:04:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self[1] = WidgetContainer:new{
|
|
|
|
|
align = "center",
|
2018-02-07 17:45:46 +00:00
|
|
|
|
dimen = Geom:new{
|
2017-09-18 17:04:36 +00:00
|
|
|
|
x = 0, y = 0,
|
|
|
|
|
w = self.screen_width,
|
|
|
|
|
h = self.screen_height,
|
|
|
|
|
},
|
|
|
|
|
FrameContainer:new{
|
|
|
|
|
bordersize = 0,
|
2017-09-13 14:56:20 +00:00
|
|
|
|
padding = Size.padding.default,
|
2017-09-18 17:04:36 +00:00
|
|
|
|
self.date_frame,
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-04 20:20:00 +00:00
|
|
|
|
self:refocusWidget()
|
2017-09-18 17:04:36 +00:00
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
|
return "ui", self.date_frame.dimen
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
2022-05-23 18:32:59 +00:00
|
|
|
|
function DateTimeWidget:update(year, month, day, hour, min, sec)
|
2022-09-27 23:10:50 +00:00
|
|
|
|
self.year_widget.value = year
|
|
|
|
|
self.year_widget:update()
|
|
|
|
|
self.month_widget.value = month
|
|
|
|
|
self.month_widget:update()
|
|
|
|
|
self.day_widget.value = day
|
|
|
|
|
self.day_widget:update()
|
|
|
|
|
self.hour_widget.value = hour
|
|
|
|
|
self.hour_widget:update()
|
|
|
|
|
self.min_widget.value = min
|
|
|
|
|
self.min_widget:update()
|
|
|
|
|
self.sec_widget.value = sec
|
|
|
|
|
self.sec_widget:update()
|
2021-11-28 21:18:44 +00:00
|
|
|
|
end
|
|
|
|
|
|
2021-09-25 17:59:45 +00:00
|
|
|
|
function DateTimeWidget:onCloseWidget()
|
2022-09-27 23:10:50 +00:00
|
|
|
|
-- Let our main WidgetContainer free its child widgets
|
|
|
|
|
self[1]:free()
|
2022-05-23 18:32:59 +00:00
|
|
|
|
|
2017-09-18 17:04:36 +00:00
|
|
|
|
UIManager:setDirty(nil, function()
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
|
return "ui", self.date_frame.dimen
|
2017-09-18 17:04:36 +00:00
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
2021-09-25 17:59:45 +00:00
|
|
|
|
function DateTimeWidget:onShow()
|
2017-09-18 17:04:36 +00:00
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
|
return "ui", self.date_frame.dimen
|
|
|
|
|
end)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
2021-09-25 17:59:45 +00:00
|
|
|
|
function DateTimeWidget:onTapClose(arg, ges_ev)
|
2017-09-18 17:04:36 +00:00
|
|
|
|
if ges_ev.pos:notIntersectWith(self.date_frame.dimen) then
|
|
|
|
|
self:onClose()
|
|
|
|
|
end
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
2021-09-25 17:59:45 +00:00
|
|
|
|
function DateTimeWidget:onClose()
|
2017-09-18 17:04:36 +00:00
|
|
|
|
UIManager:close(self)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
2021-09-25 17:59:45 +00:00
|
|
|
|
return DateTimeWidget
|