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 CloseButton = require("ui/widget/closebutton")
|
|
|
|
|
local Device = require("device")
|
|
|
|
|
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 InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
|
local LineWidget = require("ui/widget/linewidget")
|
|
|
|
|
local OverlapGroup = require("ui/widget/overlapgroup")
|
|
|
|
|
local NumberPickerWidget = require("ui/widget/numberpickerwidget")
|
2017-09-13 14:56:20 +00:00
|
|
|
|
local Size = require("ui/size")
|
2017-09-18 17:04:36 +00:00
|
|
|
|
local TextBoxWidget = require("ui/widget/textboxwidget")
|
|
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
local DateWidget = InputContainer:new{
|
|
|
|
|
title_face = Font:getFace("x_smalltfont"),
|
|
|
|
|
width = nil,
|
|
|
|
|
height = nil,
|
|
|
|
|
day = 1,
|
|
|
|
|
month = 1,
|
|
|
|
|
year = 2017,
|
|
|
|
|
ok_text = _("OK"),
|
|
|
|
|
cancel_text = _("Cancel"),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function DateWidget:init()
|
|
|
|
|
self.medium_font_face = Font:getFace("ffont")
|
|
|
|
|
self.light_bar = {}
|
2017-09-13 14:56:20 +00:00
|
|
|
|
self.screen_width = Screen:getWidth()
|
|
|
|
|
self.screen_height = Screen:getHeight()
|
2020-06-12 23:56:36 +00:00
|
|
|
|
self.width = math.floor(self.screen_width * 0.95)
|
2017-09-18 17:04:36 +00:00
|
|
|
|
if Device:hasKeys() then
|
|
|
|
|
self.key_events = {
|
2018-02-07 17:45:46 +00:00
|
|
|
|
Close = { {"Back"}, doc = "close date widget" }
|
2017-09-18 17:04:36 +00:00
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
if Device:isTouchDevice() then
|
|
|
|
|
self.ges_events = {
|
2018-02-07 17:45:46 +00:00
|
|
|
|
TapClose = {
|
2017-09-18 17:04:36 +00:00
|
|
|
|
GestureRange:new{
|
|
|
|
|
ges = "tap",
|
|
|
|
|
range = Geom:new{
|
|
|
|
|
w = self.screen_width,
|
|
|
|
|
h = self.screen_height,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
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
|
2017-09-18 17:04:36 +00:00
|
|
|
|
self:update()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function DateWidget:update()
|
|
|
|
|
local year_widget = NumberPickerWidget:new{
|
|
|
|
|
show_parent = self,
|
2020-06-12 23:56:36 +00:00
|
|
|
|
width = math.floor(self.screen_width * 0.2),
|
2017-09-18 17:04:36 +00:00
|
|
|
|
value = self.year,
|
|
|
|
|
value_min = 2017,
|
|
|
|
|
value_max = 2037,
|
|
|
|
|
value_step = 1,
|
|
|
|
|
value_hold_step = 4,
|
|
|
|
|
}
|
|
|
|
|
local month_widget = NumberPickerWidget:new{
|
|
|
|
|
show_parent = self,
|
2020-06-12 23:56:36 +00:00
|
|
|
|
width = math.floor(self.screen_width * 0.2),
|
2017-09-18 17:04:36 +00:00
|
|
|
|
value = self.month,
|
|
|
|
|
value_min = 1,
|
|
|
|
|
value_max = 12,
|
|
|
|
|
value_step = 1,
|
|
|
|
|
value_hold_step = 3,
|
|
|
|
|
}
|
|
|
|
|
local day_widget = NumberPickerWidget:new{
|
|
|
|
|
show_parent = self,
|
2020-06-12 23:56:36 +00:00
|
|
|
|
width = math.floor(self.screen_width * 0.2),
|
2017-09-18 17:04:36 +00:00
|
|
|
|
value = self.day,
|
|
|
|
|
value_min = 1,
|
|
|
|
|
value_max = 31,
|
|
|
|
|
value_step = 1,
|
|
|
|
|
value_hold_step = 5,
|
|
|
|
|
date_month = month_widget,
|
|
|
|
|
date_year = year_widget,
|
|
|
|
|
}
|
|
|
|
|
local dash_space = TextBoxWidget:new{
|
|
|
|
|
text = "–",
|
|
|
|
|
alignment = "center",
|
|
|
|
|
face = self.title_face,
|
|
|
|
|
bold = true,
|
2020-06-12 23:56:36 +00:00
|
|
|
|
width = math.floor(self.screen_width * 0.1),
|
2017-09-18 17:04:36 +00:00
|
|
|
|
}
|
|
|
|
|
local date_group = HorizontalGroup:new{
|
|
|
|
|
align = "center",
|
|
|
|
|
year_widget,
|
|
|
|
|
dash_space,
|
|
|
|
|
month_widget,
|
|
|
|
|
dash_space,
|
|
|
|
|
day_widget,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local date_title = FrameContainer:new{
|
2017-09-13 14:56:20 +00:00
|
|
|
|
padding = Size.padding.default,
|
2017-10-16 15:51:56 +00:00
|
|
|
|
margin = Size.margin.title,
|
2017-09-18 17:04:36 +00:00
|
|
|
|
bordersize = 0,
|
|
|
|
|
TextWidget:new{
|
|
|
|
|
text = self.title_text,
|
|
|
|
|
face = self.title_face,
|
|
|
|
|
bold = true,
|
2020-06-12 23:56:36 +00:00
|
|
|
|
width = math.floor(self.screen_width * 0.95),
|
2017-09-18 17:04:36 +00:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
local date_line = LineWidget:new{
|
|
|
|
|
dimen = Geom:new{
|
|
|
|
|
w = self.width,
|
2017-09-13 14:56:20 +00:00
|
|
|
|
h = Size.line.thick,
|
2017-09-18 17:04:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
local date_bar = OverlapGroup:new{
|
|
|
|
|
dimen = {
|
|
|
|
|
w = self.width,
|
|
|
|
|
h = date_title:getSize().h
|
|
|
|
|
},
|
|
|
|
|
date_title,
|
2017-10-16 15:51:56 +00:00
|
|
|
|
CloseButton:new{ window = self, padding_top = Size.margin.title, },
|
2017-09-18 17:04:36 +00:00
|
|
|
|
}
|
|
|
|
|
local buttons = {
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
text = self.cancel_text,
|
|
|
|
|
callback = function()
|
|
|
|
|
self:onClose()
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text = self.ok_text,
|
|
|
|
|
callback = function()
|
|
|
|
|
if self.callback then
|
|
|
|
|
self.year = year_widget:getValue()
|
|
|
|
|
self.month = month_widget:getValue()
|
|
|
|
|
self.day = day_widget:getValue()
|
|
|
|
|
self:callback(self)
|
|
|
|
|
end
|
|
|
|
|
self:onClose()
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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",
|
|
|
|
|
date_bar,
|
|
|
|
|
date_line,
|
|
|
|
|
CenterContainer:new{
|
|
|
|
|
dimen = Geom:new{
|
2020-06-12 23:56:36 +00:00
|
|
|
|
w = math.floor(self.screen_width * 0.95),
|
|
|
|
|
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,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
|
return "ui", self.date_frame.dimen
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function DateWidget:onCloseWidget()
|
|
|
|
|
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)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function DateWidget:onShow()
|
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
|
return "ui", self.date_frame.dimen
|
|
|
|
|
end)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function DateWidget:onAnyKeyPressed()
|
|
|
|
|
UIManager:close(self)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
2018-02-07 17:45:46 +00:00
|
|
|
|
function DateWidget: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
|
|
|
|
|
|
|
|
|
|
function DateWidget:onClose()
|
|
|
|
|
UIManager:close(self)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return DateWidget
|