2019-09-01 13:35:29 +00:00
|
|
|
--[[--
|
|
|
|
A customizable number picker.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
local NumberPickerWidget = require("ui/widget/numberpickerwidget")
|
|
|
|
local numberpicker = NumberPickerWidget:new{
|
|
|
|
-- for floating point (decimals), use something like "%.2f"
|
|
|
|
precision = "%02d",
|
|
|
|
value = 0,
|
|
|
|
value_min = 0,
|
|
|
|
value_max = 23,
|
|
|
|
value_step = 1,
|
|
|
|
value_hold_step = 4,
|
|
|
|
wrap = true,
|
|
|
|
}
|
|
|
|
--]]
|
|
|
|
|
2017-09-17 14:41:54 +00:00
|
|
|
local Button = require("ui/widget/button")
|
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
|
|
|
local Device = require("device")
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local Font = require("ui/font")
|
2019-09-11 19:39:58 +00:00
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
2017-09-17 14:41:54 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2017-09-24 11:03:14 +00:00
|
|
|
local InputDialog = require("ui/widget/inputdialog")
|
2017-09-13 14:56:20 +00:00
|
|
|
local Size = require("ui/size")
|
2017-09-17 14:41:54 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
|
|
|
local VerticalSpan = require("ui/widget/verticalspan")
|
|
|
|
local _ = require("gettext")
|
2019-09-11 19:39:58 +00:00
|
|
|
local T = require("ffi/util").template
|
2017-09-17 14:41:54 +00:00
|
|
|
local Screen = Device.screen
|
|
|
|
|
|
|
|
local NumberPickerWidget = InputContainer:new{
|
2017-09-13 14:56:20 +00:00
|
|
|
spinner_face = Font:getFace("smalltfont"),
|
2017-09-17 14:41:54 +00:00
|
|
|
precision = "%02d",
|
|
|
|
width = nil,
|
|
|
|
height = nil,
|
|
|
|
value = 0,
|
|
|
|
value_min = 0,
|
|
|
|
value_max = 23,
|
|
|
|
value_step = 1,
|
|
|
|
value_hold_step = 4,
|
|
|
|
value_table = nil,
|
2019-09-23 22:24:45 +00:00
|
|
|
value_index = nil,
|
2018-04-19 12:24:04 +00:00
|
|
|
wrap = true,
|
2017-09-18 17:04:36 +00:00
|
|
|
-- in case we need calculate number of days in a given month and year
|
|
|
|
date_month = nil,
|
|
|
|
date_year = nil,
|
2017-09-17 14:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function NumberPickerWidget:init()
|
2017-09-13 14:56:20 +00:00
|
|
|
self.screen_width = Screen:getWidth()
|
|
|
|
self.screen_height = Screen:getHeight()
|
2017-09-17 14:41:54 +00:00
|
|
|
if self.width == nil then
|
2020-06-12 23:56:36 +00:00
|
|
|
self.width = math.floor(self.screen_width * 0.2)
|
2017-09-17 14:41:54 +00:00
|
|
|
end
|
|
|
|
if self.value_table then
|
2019-09-23 22:24:45 +00:00
|
|
|
self.value_index = self.value_index or 1
|
2017-09-17 14:41:54 +00:00
|
|
|
self.value = self.value_table[self.value_index]
|
|
|
|
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
|
|
|
-- Widget layout
|
2017-09-13 14:56:20 +00:00
|
|
|
local bordersize = Size.border.default
|
|
|
|
local margin = Size.margin.default
|
2017-09-17 14:41:54 +00:00
|
|
|
local button_up = Button:new{
|
|
|
|
text = "▲",
|
2017-09-13 14:56:20 +00:00
|
|
|
bordersize = bordersize,
|
|
|
|
margin = margin,
|
2017-09-17 14:41:54 +00:00
|
|
|
radius = 0,
|
|
|
|
text_font_size = 24,
|
|
|
|
width = self.width,
|
|
|
|
show_parent = self.show_parent,
|
|
|
|
callback = function()
|
2017-09-18 17:04:36 +00:00
|
|
|
if self.date_month and self.date_year then
|
|
|
|
self.value_max = self:getDaysInMonth(self.date_month:getValue(), self.date_year:getValue())
|
|
|
|
end
|
2018-04-19 12:24:04 +00:00
|
|
|
self.value = self:changeValue(self.value, self.value_step, self.value_max, self.value_min, self.wrap)
|
2017-09-17 14:41:54 +00:00
|
|
|
self:update()
|
|
|
|
end,
|
|
|
|
hold_callback = function()
|
2017-09-18 17:04:36 +00:00
|
|
|
if self.date_month and self.date_year then
|
|
|
|
self.value_max = self:getDaysInMonth(self.date_month:getValue(), self.date_year:getValue())
|
|
|
|
end
|
2018-04-19 12:24:04 +00:00
|
|
|
self.value = self:changeValue(self.value, self.value_hold_step, self.value_max, self.value_min, self.wrap)
|
2017-09-17 14:41:54 +00:00
|
|
|
self:update()
|
|
|
|
end
|
|
|
|
}
|
|
|
|
local button_down = Button:new{
|
|
|
|
text = "▼",
|
2017-09-13 14:56:20 +00:00
|
|
|
bordersize = bordersize,
|
|
|
|
margin = margin,
|
2017-09-17 14:41:54 +00:00
|
|
|
radius = 0,
|
|
|
|
text_font_size = 24,
|
|
|
|
width = self.width,
|
|
|
|
show_parent = self.show_parent,
|
|
|
|
callback = function()
|
2017-09-18 17:04:36 +00:00
|
|
|
if self.date_month and self.date_year then
|
|
|
|
self.value_max = self:getDaysInMonth(self.date_month:getValue(), self.date_year:getValue())
|
|
|
|
end
|
2018-04-19 12:24:04 +00:00
|
|
|
self.value = self:changeValue(self.value, self.value_step * -1, self.value_max, self.value_min, self.wrap)
|
2017-09-17 14:41:54 +00:00
|
|
|
self:update()
|
|
|
|
end,
|
|
|
|
hold_callback = function()
|
2017-09-18 17:04:36 +00:00
|
|
|
if self.date_month and self.date_year then
|
|
|
|
self.value_max = self:getDaysInMonth(self.date_month:getValue(), self.date_year:getValue())
|
|
|
|
end
|
2018-04-19 12:24:04 +00:00
|
|
|
self.value = self:changeValue(self.value, self.value_hold_step * -1, self.value_max, self.value_min, self.wrap)
|
2017-09-17 14:41:54 +00:00
|
|
|
self:update()
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
local empty_space = VerticalSpan:new{
|
2020-06-12 23:56:36 +00:00
|
|
|
width = math.ceil(self.screen_height * 0.01)
|
2017-09-17 14:41:54 +00:00
|
|
|
}
|
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
|
|
|
|
|
|
|
self.formatted_value = self.value
|
2019-10-21 13:20:40 +00:00
|
|
|
if not self.value_table then
|
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
|
|
|
self.formatted_value = string.format(self.precision, self.formatted_value)
|
2017-09-17 14:41:54 +00:00
|
|
|
end
|
|
|
|
|
2019-09-11 19:39:58 +00:00
|
|
|
local input_dialog
|
2017-09-24 11:03:14 +00:00
|
|
|
local callback_input = nil
|
|
|
|
if self.value_table == nil then
|
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
|
|
|
callback_input = function()
|
2021-06-05 18:58:10 +00:00
|
|
|
if self.date_month and self.date_year then
|
|
|
|
self.value_max = self:getDaysInMonth(self.date_month:getValue(), self.date_year:getValue())
|
|
|
|
end
|
2019-09-11 19:39:58 +00:00
|
|
|
input_dialog = InputDialog:new{
|
2017-09-24 11:03:14 +00:00
|
|
|
title = _("Enter number"),
|
2021-04-16 20:01:24 +00:00
|
|
|
input_hint = T("%1 (%2 - %3)", self.formatted_value, self.value_min, self.value_max),
|
2017-09-24 11:03:14 +00:00
|
|
|
input_type = "number",
|
|
|
|
buttons = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Cancel"),
|
|
|
|
callback = function()
|
2019-09-11 19:39:58 +00:00
|
|
|
UIManager:close(input_dialog)
|
2017-09-24 11:03:14 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("OK"),
|
|
|
|
is_enter_default = true,
|
|
|
|
callback = function()
|
2019-09-11 19:39:58 +00:00
|
|
|
local input_value = tonumber(input_dialog:getInputText())
|
2017-09-24 11:03:14 +00:00
|
|
|
if input_value and input_value >= self.value_min and input_value <= self.value_max then
|
|
|
|
self.value = input_value
|
|
|
|
self:update()
|
2019-09-11 19:39:58 +00:00
|
|
|
UIManager:close(input_dialog)
|
|
|
|
elseif input_value and input_value < self.value_min then
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
text = T(_("This value should be %1 or more."), self.value_min),
|
|
|
|
timeout = 2,
|
|
|
|
})
|
|
|
|
elseif input_value and input_value > self.value_max then
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
text = T(_("This value should be %1 or less."), self.value_max),
|
|
|
|
timeout = 2,
|
|
|
|
})
|
|
|
|
else
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
text = _("Invalid value. Please enter a valid value."),
|
|
|
|
timeout = 2
|
|
|
|
})
|
2017-09-24 11:03:14 +00:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2019-09-11 19:39:58 +00:00
|
|
|
UIManager:show(input_dialog)
|
|
|
|
input_dialog:onShowKeyboard()
|
2017-09-24 11:03:14 +00:00
|
|
|
end
|
|
|
|
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
|
|
|
self.text_value = Button:new{
|
|
|
|
text = tostring(self.formatted_value),
|
2017-09-24 11:03:14 +00:00
|
|
|
bordersize = 0,
|
|
|
|
padding = 0,
|
2019-10-21 13:20:40 +00:00
|
|
|
text_font_face = self.spinner_face.font,
|
|
|
|
text_font_size = self.spinner_face.orig_size,
|
2017-09-17 14:41:54 +00:00
|
|
|
width = self.width,
|
2019-10-21 13:20:40 +00:00
|
|
|
max_width = self.width,
|
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
|
|
|
show_parent = self.show_parent,
|
2017-09-24 11:03:14 +00:00
|
|
|
callback = callback_input,
|
2017-09-17 14:41:54 +00:00
|
|
|
}
|
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
|
|
|
|
|
|
|
local widget_spinner = VerticalGroup:new{
|
2017-09-17 14:41:54 +00:00
|
|
|
align = "center",
|
|
|
|
button_up,
|
|
|
|
empty_space,
|
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
|
|
|
self.text_value,
|
2017-09-17 14:41:54 +00:00
|
|
|
empty_space,
|
|
|
|
button_down,
|
|
|
|
}
|
|
|
|
|
|
|
|
self.frame = FrameContainer:new{
|
|
|
|
bordersize = 0,
|
2017-09-13 14:56:20 +00:00
|
|
|
padding = Size.padding.default,
|
2017-09-17 14:41:54 +00:00
|
|
|
CenterContainer:new{
|
|
|
|
align = "center",
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = widget_spinner:getSize().w,
|
|
|
|
h = widget_spinner:getSize().h
|
|
|
|
},
|
|
|
|
widget_spinner
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.dimen = self.frame:getSize()
|
|
|
|
self[1] = self.frame
|
|
|
|
UIManager:setDirty(self.show_parent, function()
|
|
|
|
return "ui", self.dimen
|
|
|
|
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
|
|
|
end
|
|
|
|
|
|
|
|
--[[--
|
|
|
|
Update.
|
|
|
|
--]]
|
|
|
|
function NumberPickerWidget:update()
|
|
|
|
self.formatted_value = self.value
|
|
|
|
if not self.value_table then
|
|
|
|
self.formatted_value = string.format(self.precision, self.formatted_value)
|
|
|
|
end
|
|
|
|
|
|
|
|
self.text_value:setText(tostring(self.formatted_value), self.width)
|
|
|
|
|
|
|
|
UIManager:setDirty(self.show_parent, function()
|
|
|
|
return "ui", self.dimen
|
|
|
|
end)
|
2017-09-17 14:41:54 +00:00
|
|
|
end
|
|
|
|
|
2019-09-01 13:35:29 +00:00
|
|
|
--[[--
|
|
|
|
Change value.
|
|
|
|
--]]
|
2018-04-19 12:24:04 +00:00
|
|
|
function NumberPickerWidget:changeValue(value, step, max, min, wrap)
|
2017-09-17 14:41:54 +00:00
|
|
|
if self.value_index then
|
|
|
|
self.value_index = self.value_index + step
|
|
|
|
if self.value_index > #self.value_table then
|
2018-04-19 12:24:04 +00:00
|
|
|
self.value_index = wrap and 1 or #self.value_table
|
2017-09-17 14:41:54 +00:00
|
|
|
elseif
|
|
|
|
self.value_index < 1 then
|
2018-04-19 12:24:04 +00:00
|
|
|
self.value_index = wrap and #self.value_table or 1
|
2017-09-17 14:41:54 +00:00
|
|
|
end
|
|
|
|
value = self.value_table[self.value_index]
|
|
|
|
else
|
|
|
|
value = value + step
|
|
|
|
if value > max then
|
2018-04-19 12:24:04 +00:00
|
|
|
value = wrap and min or max
|
2017-09-17 14:41:54 +00:00
|
|
|
elseif value < min then
|
2018-04-19 12:24:04 +00:00
|
|
|
value = wrap and max or min
|
2017-09-17 14:41:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return value
|
|
|
|
end
|
|
|
|
|
2019-09-01 13:35:29 +00:00
|
|
|
--[[--
|
|
|
|
Get days in month.
|
|
|
|
--]]
|
2017-09-18 17:04:36 +00:00
|
|
|
function NumberPickerWidget:getDaysInMonth(month, year)
|
|
|
|
local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
|
|
|
|
local days = days_in_month[month]
|
|
|
|
-- check for leap year
|
|
|
|
if (month == 2) then
|
|
|
|
if year % 4 == 0 then
|
|
|
|
if year % 100 == 0 then
|
|
|
|
if year % 400 == 0 then
|
|
|
|
days = 29
|
|
|
|
end
|
|
|
|
else
|
|
|
|
days = 29
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return days
|
|
|
|
end
|
|
|
|
|
2019-09-01 13:35:29 +00:00
|
|
|
--[[--
|
|
|
|
Get value.
|
|
|
|
--]]
|
2017-09-17 14:41:54 +00:00
|
|
|
function NumberPickerWidget:getValue()
|
2019-09-23 22:24:45 +00:00
|
|
|
return self.value, self.value_index
|
2017-09-17 14:41:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return NumberPickerWidget
|