2018-04-19 12:24:04 +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 MovableContainer = require("ui/widget/container/movablecontainer")
|
|
|
|
local OverlapGroup = require("ui/widget/overlapgroup")
|
|
|
|
local NumberPickerWidget = require("ui/widget/numberpickerwidget")
|
|
|
|
local Size = require("ui/size")
|
|
|
|
local TextBoxWidget = require("ui/widget/textboxwidget")
|
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
|
|
|
local VerticalSpan = require("ui/widget/verticalspan")
|
|
|
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
|
|
|
local _ = require("gettext")
|
|
|
|
local Screen = Device.screen
|
|
|
|
|
2019-12-11 22:12:55 +00:00
|
|
|
local DoubleSpinWidget = InputContainer:new{
|
|
|
|
title_text = "",
|
2018-04-19 12:24:04 +00:00
|
|
|
title_face = Font:getFace("x_smalltfont"),
|
2020-05-09 11:16:09 +00:00
|
|
|
info_text = nil,
|
2018-04-19 12:24:04 +00:00
|
|
|
width = nil,
|
|
|
|
height = nil,
|
|
|
|
left_min = 1,
|
2019-12-11 22:12:55 +00:00
|
|
|
left_max = 20,
|
|
|
|
left_value = 1,
|
2018-04-19 12:24:04 +00:00
|
|
|
left_default = nil,
|
2019-12-11 22:12:55 +00:00
|
|
|
left_text = _("Left"),
|
2018-04-19 12:24:04 +00:00
|
|
|
right_min = 1,
|
2019-12-11 22:12:55 +00:00
|
|
|
right_max = 20,
|
|
|
|
right_value = 1,
|
2018-04-19 12:24:04 +00:00
|
|
|
right_default = nil,
|
2019-12-11 22:12:55 +00:00
|
|
|
right_text = _("Right"),
|
2020-05-09 11:16:09 +00:00
|
|
|
cancel_text = _("Close"),
|
|
|
|
ok_text = _("Apply"),
|
2021-01-11 17:14:17 +00:00
|
|
|
cancel_callback = nil,
|
|
|
|
callback = nil,
|
|
|
|
close_callback = nil,
|
2020-05-09 11:16:09 +00:00
|
|
|
keep_shown_on_apply = false,
|
|
|
|
-- Set this to add default button that restores numbers to their default values
|
2019-12-11 22:12:55 +00:00
|
|
|
default_values = nil,
|
|
|
|
default_text = _("Use defaults"),
|
2020-05-09 11:16:09 +00:00
|
|
|
-- Optional extra button on bottom
|
|
|
|
extra_text = nil,
|
|
|
|
extra_callback = nil,
|
2018-04-19 12:24:04 +00:00
|
|
|
}
|
|
|
|
|
2019-12-11 22:12:55 +00:00
|
|
|
function DoubleSpinWidget:init()
|
2018-04-19 12:24:04 +00:00
|
|
|
self.medium_font_face = Font:getFace("ffont")
|
|
|
|
self.screen_width = Screen:getWidth()
|
|
|
|
self.screen_height = Screen:getHeight()
|
2020-06-12 23:56:36 +00:00
|
|
|
self.width = self.width or math.floor(self.screen_width * 0.8)
|
|
|
|
self.picker_width = math.floor(self.screen_width * 0.25)
|
2018-04-19 12:24:04 +00:00
|
|
|
if Device:hasKeys() then
|
|
|
|
self.key_events = {
|
|
|
|
Close = { {"Back"}, doc = "close time widget" }
|
|
|
|
}
|
|
|
|
end
|
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.ges_events = {
|
|
|
|
TapClose = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = Geom:new{
|
|
|
|
w = self.screen_width,
|
|
|
|
h = self.screen_height,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2019-12-11 22:12:55 +00:00
|
|
|
}
|
2018-04-19 12:24:04 +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
|
2018-04-19 12:24:04 +00:00
|
|
|
self:update()
|
|
|
|
end
|
|
|
|
|
2019-12-11 22:12:55 +00:00
|
|
|
function DoubleSpinWidget:update()
|
2018-04-19 12:24:04 +00:00
|
|
|
local left_widget = NumberPickerWidget:new{
|
|
|
|
show_parent = self,
|
|
|
|
width = self.picker_width,
|
|
|
|
value = self.left_value,
|
|
|
|
value_min = self.left_min,
|
|
|
|
value_max = self.left_max,
|
2020-02-16 00:03:12 +00:00
|
|
|
value_step = self.left_step,
|
|
|
|
value_hold_step = self.left_hold_step,
|
2018-04-19 12:24:04 +00:00
|
|
|
wrap = false,
|
|
|
|
}
|
|
|
|
local right_widget = NumberPickerWidget:new{
|
|
|
|
show_parent = self,
|
|
|
|
width = self.picker_width,
|
|
|
|
value = self.right_value,
|
|
|
|
value_min = self.right_min,
|
|
|
|
value_max = self.right_max,
|
2020-02-16 00:03:12 +00:00
|
|
|
value_step = self.right_step,
|
|
|
|
value_hold_step = self.right_hold_step,
|
2018-04-19 12:24:04 +00:00
|
|
|
wrap = false,
|
|
|
|
}
|
2019-12-11 22:12:55 +00:00
|
|
|
local left_vertical_group = VerticalGroup:new{
|
2018-04-19 12:24:04 +00:00
|
|
|
align = "center",
|
2019-12-11 22:12:55 +00:00
|
|
|
VerticalSpan:new{ width = Size.span.vertical_large },
|
|
|
|
TextWidget:new{
|
|
|
|
text = self.left_text,
|
|
|
|
face = self.title_face,
|
|
|
|
max_width = 0.95 * self.width / 2,
|
2018-04-19 12:24:04 +00:00
|
|
|
},
|
2019-12-11 22:12:55 +00:00
|
|
|
left_widget,
|
|
|
|
}
|
|
|
|
local right_vertical_group = VerticalGroup:new{
|
|
|
|
align = "center",
|
|
|
|
VerticalSpan:new{ width = Size.span.vertical_large },
|
|
|
|
TextWidget:new{
|
|
|
|
text = self.right_text,
|
|
|
|
face = self.title_face,
|
|
|
|
max_width = 0.95 * self.width / 2,
|
|
|
|
},
|
|
|
|
right_widget,
|
|
|
|
}
|
|
|
|
local widget_group = HorizontalGroup:new{
|
|
|
|
align = "center",
|
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.width / 2,
|
|
|
|
h = left_vertical_group:getSize().h,
|
2018-04-19 12:24:04 +00:00
|
|
|
},
|
2019-12-11 22:12:55 +00:00
|
|
|
left_vertical_group
|
2018-04-19 12:24:04 +00:00
|
|
|
},
|
2019-12-11 22:12:55 +00:00
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.width / 2,
|
|
|
|
h = right_vertical_group:getSize().h,
|
|
|
|
},
|
|
|
|
right_vertical_group
|
|
|
|
}
|
2018-04-19 12:24:04 +00:00
|
|
|
}
|
2019-12-11 22:12:55 +00:00
|
|
|
local widget_title = FrameContainer:new{
|
2018-04-19 12:24:04 +00:00
|
|
|
padding = Size.padding.default,
|
|
|
|
margin = Size.margin.title,
|
|
|
|
bordersize = 0,
|
|
|
|
TextWidget:new{
|
|
|
|
text = self.title_text,
|
|
|
|
face = self.title_face,
|
|
|
|
bold = true,
|
|
|
|
width = self.width,
|
|
|
|
},
|
|
|
|
}
|
2019-12-11 22:12:55 +00:00
|
|
|
local widget_line = LineWidget:new{
|
2018-04-19 12:24:04 +00:00
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.width,
|
|
|
|
h = Size.line.thick,
|
|
|
|
}
|
|
|
|
}
|
2019-12-11 22:12:55 +00:00
|
|
|
local widget_bar = OverlapGroup:new{
|
2018-04-19 12:24:04 +00:00
|
|
|
dimen = {
|
|
|
|
w = self.width,
|
2019-12-11 22:12:55 +00:00
|
|
|
h = widget_title:getSize().h
|
2018-04-19 12:24:04 +00:00
|
|
|
},
|
2019-12-11 22:12:55 +00:00
|
|
|
widget_title,
|
2018-04-19 12:24:04 +00:00
|
|
|
CloseButton:new{ window = self, padding_top = Size.margin.title, },
|
|
|
|
}
|
2021-01-02 22:15:48 +00:00
|
|
|
local widget_info
|
|
|
|
if self.info_text then
|
|
|
|
widget_info = FrameContainer:new{
|
|
|
|
padding = Size.padding.default,
|
|
|
|
margin = Size.margin.small,
|
|
|
|
bordersize = 0,
|
|
|
|
TextBoxWidget:new{
|
|
|
|
text = self.info_text,
|
|
|
|
face = Font:getFace("x_smallinfofont"),
|
|
|
|
width = math.floor(self.width * 0.9),
|
|
|
|
}
|
2018-04-19 12:24:04 +00:00
|
|
|
}
|
2021-01-02 22:15:48 +00:00
|
|
|
else
|
|
|
|
widget_info = VerticalSpan:new{ width = 0 }
|
|
|
|
end
|
2018-04-19 12:24:04 +00:00
|
|
|
local buttons = {
|
|
|
|
{
|
|
|
|
{
|
2020-05-09 11:16:09 +00:00
|
|
|
text = self.cancel_text,
|
2018-04-19 12:24:04 +00:00
|
|
|
callback = function()
|
2021-01-11 17:14:17 +00:00
|
|
|
if self.cancel_callback then
|
|
|
|
self.cancel_callback()
|
|
|
|
end
|
2018-04-19 12:24:04 +00:00
|
|
|
self:onClose()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
2020-05-09 11:16:09 +00:00
|
|
|
text = self.ok_text,
|
2018-04-19 12:24:04 +00:00
|
|
|
callback = function()
|
|
|
|
if self.callback then
|
|
|
|
self.callback(left_widget:getValue(), right_widget:getValue())
|
|
|
|
end
|
2020-05-09 11:16:09 +00:00
|
|
|
if not self.keep_shown_on_apply then
|
|
|
|
self:onClose()
|
|
|
|
end
|
2018-04-19 12:24:04 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
2019-12-11 22:12:55 +00:00
|
|
|
}
|
|
|
|
if self.default_values then
|
|
|
|
table.insert(buttons,{
|
2018-04-19 12:24:04 +00:00
|
|
|
{
|
2019-12-11 22:12:55 +00:00
|
|
|
text = self.default_text,
|
2018-04-19 12:24:04 +00:00
|
|
|
callback = function()
|
|
|
|
left_widget.value = self.left_default
|
|
|
|
right_widget.value = self.right_default
|
|
|
|
left_widget:update()
|
|
|
|
right_widget:update()
|
|
|
|
self.callback(nil, nil)
|
|
|
|
end,
|
2019-12-11 22:12:55 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
end
|
2020-05-09 11:16:09 +00:00
|
|
|
if self.extra_text then
|
|
|
|
table.insert(buttons,{
|
|
|
|
{
|
|
|
|
text = self.extra_text,
|
|
|
|
callback = function()
|
|
|
|
if self.extra_callback then
|
|
|
|
self.extra_callback(left_widget:getValue(), right_widget:getValue())
|
|
|
|
end
|
|
|
|
if not self.keep_shown_on_apply then -- assume extra wants it same as ok
|
|
|
|
self:onClose()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
end
|
2018-04-19 12:24:04 +00:00
|
|
|
|
|
|
|
local button_table = ButtonTable:new{
|
|
|
|
width = self.width - 2*Size.padding.default,
|
|
|
|
buttons = buttons,
|
|
|
|
zero_sep = true,
|
|
|
|
show_parent = self,
|
|
|
|
}
|
|
|
|
|
2019-12-11 22:12:55 +00:00
|
|
|
self.widget_frame = FrameContainer:new{
|
2018-04-19 12:24:04 +00:00
|
|
|
radius = Size.radius.window,
|
|
|
|
padding = 0,
|
|
|
|
margin = 0,
|
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
|
|
|
VerticalGroup:new{
|
|
|
|
align = "left",
|
2019-12-11 22:12:55 +00:00
|
|
|
widget_bar,
|
|
|
|
widget_line,
|
|
|
|
widget_info,
|
2018-04-19 12:24:04 +00:00
|
|
|
VerticalSpan:new{ width = Size.span.vertical_large },
|
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.width,
|
2019-12-11 22:12:55 +00:00
|
|
|
h = widget_group:getSize().h,
|
2018-04-19 12:24:04 +00:00
|
|
|
},
|
2019-12-11 22:12:55 +00:00
|
|
|
widget_group
|
2018-04-19 12:24:04 +00:00
|
|
|
},
|
|
|
|
VerticalSpan:new{ width = Size.span.vertical_large },
|
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.width,
|
|
|
|
h = button_table:getSize().h,
|
|
|
|
},
|
|
|
|
button_table
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.movable = MovableContainer:new{
|
2019-12-11 22:12:55 +00:00
|
|
|
self.widget_frame,
|
2018-04-19 12:24:04 +00:00
|
|
|
}
|
|
|
|
self[1] = WidgetContainer:new{
|
|
|
|
align = "center",
|
|
|
|
dimen = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = self.screen_width,
|
|
|
|
h = self.screen_height,
|
|
|
|
},
|
|
|
|
self.movable,
|
|
|
|
}
|
2021-02-02 03:27:14 +00:00
|
|
|
-- If we're translucent, Button itself will handle that post-callback, in order to preserve alpha without flickering.
|
|
|
|
if not self.movable.alpha then
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
return "ui", self.widget_frame.dimen
|
|
|
|
end)
|
2018-04-19 12:24:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-09 11:16:09 +00:00
|
|
|
function DoubleSpinWidget:hasMoved()
|
|
|
|
local offset = self.movable:getMovedOffset()
|
|
|
|
return offset.x ~= 0 or offset.y ~= 0
|
|
|
|
end
|
|
|
|
|
2019-12-11 22:12:55 +00:00
|
|
|
function DoubleSpinWidget:onCloseWidget()
|
2018-04-19 12:24:04 +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.widget_frame.dimen
|
2018-04-19 12:24:04 +00:00
|
|
|
end)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2019-12-11 22:12:55 +00:00
|
|
|
function DoubleSpinWidget:onShow()
|
2018-04-19 12:24:04 +00:00
|
|
|
UIManager:setDirty(self, function()
|
2019-12-11 22:12:55 +00:00
|
|
|
return "ui", self.widget_frame.dimen
|
2018-04-19 12:24:04 +00:00
|
|
|
end)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2019-12-11 22:12:55 +00:00
|
|
|
function DoubleSpinWidget:onAnyKeyPressed()
|
2021-01-11 17:14:17 +00:00
|
|
|
self:onClose()
|
2018-04-19 12:24:04 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2019-12-11 22:12:55 +00:00
|
|
|
function DoubleSpinWidget:onTapClose(arg, ges_ev)
|
|
|
|
if ges_ev.pos:notIntersectWith(self.widget_frame.dimen) then
|
2018-04-19 12:24:04 +00:00
|
|
|
self:onClose()
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2019-12-11 22:12:55 +00:00
|
|
|
function DoubleSpinWidget:onClose()
|
2018-04-19 12:24:04 +00:00
|
|
|
UIManager:close(self)
|
2021-01-11 17:14:17 +00:00
|
|
|
if self.close_callback then
|
|
|
|
self.close_callback()
|
|
|
|
end
|
2018-04-19 12:24:04 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2019-12-11 22:12:55 +00:00
|
|
|
return DoubleSpinWidget
|