[UX] Normalize SpinWidget and DoubleSpinWidget

- Use same names for options;
- Have them both movable
- Add option to keep widget shown on Apply (and use that
  when appropriate: when the value may have an immediate
  visual effect, so one can tweak it without having to
  go thru menus to re-open it again).
reviewable/pr6137/r1
poire-z 4 years ago
parent d69a992e1d
commit e5206922c6

@ -147,8 +147,8 @@ function FileManagerMenu:setUpdateItemTable()
value = curr_items, value = curr_items,
value_min = 6, value_min = 6,
value_max = 24, value_max = 24,
ok_text = _("Set items"),
title_text = _("Items per page"), title_text = _("Items per page"),
keep_shown_on_apply = true,
callback = function(spin) callback = function(spin)
G_reader_settings:saveSetting("items_per_page", spin.value) G_reader_settings:saveSetting("items_per_page", spin.value)
self.ui:onRefresh() self.ui:onRefresh()
@ -171,7 +171,7 @@ function FileManagerMenu:setUpdateItemTable()
value_min = 10, value_min = 10,
value_max = 72, value_max = 72,
default_value = default_font_size, default_value = default_font_size,
ok_text = _("Set size"), keep_shown_on_apply = true,
title_text = _("Maximum font size for item"), title_text = _("Maximum font size for item"),
callback = function(spin) callback = function(spin)
G_reader_settings:saveSetting("items_font_size", spin.value) G_reader_settings:saveSetting("items_font_size", spin.value)

@ -872,6 +872,7 @@ function ReaderFooter:addToMainMenu(menu_items)
default_value = 14, default_value = 14,
ok_text = _("Set size"), ok_text = _("Set size"),
title_text = _("Footer font size"), title_text = _("Footer font size"),
keep_shown_on_apply = true,
callback = function(spin) callback = function(spin)
self.settings.text_font_size = spin.value self.settings.text_font_size = spin.value
self.footer_text:free() self.footer_text:free()
@ -927,7 +928,8 @@ function ReaderFooter:addToMainMenu(menu_items)
value_hold_step = 20, value_hold_step = 20,
value_max = 100, value_max = 100,
title_text = _("Maximum width"), title_text = _("Maximum width"),
text = _("Maximum book title width in percentage of screen width"), info_text = _("Maximum book title width in percentage of screen width"),
keep_shown_on_apply = true,
callback = function(spin) callback = function(spin)
self.settings.book_title_max_width_pct = spin.value self.settings.book_title_max_width_pct = spin.value
self:refreshFooter(true, true) self:refreshFooter(true, true)
@ -952,7 +954,8 @@ function ReaderFooter:addToMainMenu(menu_items)
value_hold_step = 20, value_hold_step = 20,
value_max = 100, value_max = 100,
title_text = _("Maximum width"), title_text = _("Maximum width"),
text = _("Maximum chapter width in percentage of screen width"), info_text = _("Maximum chapter width in percentage of screen width"),
keep_shown_on_apply = true,
callback = function(spin) callback = function(spin)
self.settings.book_chapter_max_width_pct = spin.value self.settings.book_chapter_max_width_pct = spin.value
self:refreshFooter(true, true) self:refreshFooter(true, true)
@ -1339,6 +1342,7 @@ function ReaderFooter:addToMainMenu(menu_items)
value_max = value_max, value_max = value_max,
default_value = default_value, default_value = default_value,
title_text = _("Progress bar size"), title_text = _("Progress bar size"),
keep_shown_on_apply = true,
callback = function(spin) callback = function(spin)
if self.settings.progress_style_thin then if self.settings.progress_style_thin then
self.settings.progress_style_thin_height = spin.value self.settings.progress_style_thin_height = spin.value
@ -1499,6 +1503,7 @@ function ReaderFooter:addToMainMenu(menu_items)
value_max = 50, value_max = 50,
title_text = _("Minimal width"), title_text = _("Minimal width"),
text = _("Minimal progress bar width in percentage of screen width"), text = _("Minimal progress bar width in percentage of screen width"),
keep_shown_on_apply = true,
callback = function(spin) callback = function(spin)
self.settings.progress_bar_min_width_pct = spin.value self.settings.progress_bar_min_width_pct = spin.value
self:refreshFooter(true, true) self:refreshFooter(true, true)

@ -257,7 +257,7 @@ From the footnote popup, you can jump to the footnote location in the book by sw
precision = "%+d", precision = "%+d",
ok_text = _("Set font size"), ok_text = _("Set font size"),
title_text = _("Set footnote popup font size"), title_text = _("Set footnote popup font size"),
text = _([[ info_text = _([[
The footnote popup font adjusts to the font size you've set for the document. The footnote popup font adjusts to the font size you've set for the document.
You can specify here how much smaller or larger it should be relative to the document font size. You can specify here how much smaller or larger it should be relative to the document font size.
A negative value will make it smaller, while a positive one will make it larger. A negative value will make it smaller, while a positive one will make it larger.

@ -388,6 +388,7 @@ function ReaderPageMap:addToMainMenu(menu_items)
text_func = function() text_func = function()
return T(_("Page labels font size (%1)"), self.label_font_size) return T(_("Page labels font size (%1)"), self.label_font_size)
end, end,
enabled_func = function() return self.show_page_labels end,
callback = function(touchmenu_instance) callback = function(touchmenu_instance)
local SpinWidget = require("ui/widget/spinwidget") local SpinWidget = require("ui/widget/spinwidget")
local spin_w = SpinWidget:new{ local spin_w = SpinWidget:new{
@ -396,8 +397,8 @@ function ReaderPageMap:addToMainMenu(menu_items)
value_min = 8, value_min = 8,
value_max = 20, value_max = 20,
default_value = self.label_default_font_size, default_value = self.label_default_font_size,
ok_text = _("Set size"),
title_text = _("Page labels font size"), title_text = _("Page labels font size"),
keep_shown_on_apply = true,
callback = function(spin) callback = function(spin)
self.label_font_size = spin.value self.label_font_size = spin.value
G_reader_settings:saveSetting("pagemap_label_font_size", self.label_font_size) G_reader_settings:saveSetting("pagemap_label_font_size", self.label_font_size)

@ -455,7 +455,7 @@ You can set how many lines are shown.]])
precision = "%d", precision = "%d",
ok_text = _("Set"), ok_text = _("Set"),
title_text = _("Set overlapped lines"), title_text = _("Set overlapped lines"),
text = overlap_lines_help_text, info_text = overlap_lines_help_text,
callback = function(spin) callback = function(spin)
G_reader_settings:saveSetting("copt_overlap_lines", spin.value) G_reader_settings:saveSetting("copt_overlap_lines", spin.value)
touchmenu_instance:updateItems() touchmenu_instance:updateItems()

@ -420,6 +420,7 @@ When the book's language tag is not among our presets, no specific features will
Set minimum length before hyphenation occurs. Set minimum length before hyphenation occurs.
These settings will apply to all books with any hyphenation dictionary. These settings will apply to all books with any hyphenation dictionary.
'Use language defaults' resets them.]]), 'Use language defaults' resets them.]]),
keep_shown_on_apply = true,
callback = function(left_hyphen_min, right_hyphen_min) callback = function(left_hyphen_min, right_hyphen_min)
G_reader_settings:saveSetting("hyph_left_hyphen_min", left_hyphen_min) G_reader_settings:saveSetting("hyph_left_hyphen_min", left_hyphen_min)
G_reader_settings:saveSetting("hyph_right_hyphen_min", right_hyphen_min) G_reader_settings:saveSetting("hyph_right_hyphen_min", right_hyphen_min)

@ -26,7 +26,7 @@ local Screen = Device.screen
local DoubleSpinWidget = InputContainer:new{ local DoubleSpinWidget = InputContainer:new{
title_text = "", title_text = "",
title_face = Font:getFace("x_smalltfont"), title_face = Font:getFace("x_smalltfont"),
info_text = "", info_text = nil,
width = nil, width = nil,
height = nil, height = nil,
left_min = 1, left_min = 1,
@ -39,9 +39,15 @@ local DoubleSpinWidget = InputContainer:new{
right_value = 1, right_value = 1,
right_default = nil, right_default = nil,
right_text = _("Right"), right_text = _("Right"),
-- set this to see extra default button cancel_text = _("Close"),
ok_text = _("Apply"),
keep_shown_on_apply = false,
-- Set this to add default button that restores numbers to their default values
default_values = nil, default_values = nil,
default_text = _("Use defaults"), default_text = _("Use defaults"),
-- Optional extra button on bottom
extra_text = nil,
extra_callback = nil,
} }
function DoubleSpinWidget:init() function DoubleSpinWidget:init()
@ -74,7 +80,7 @@ end
function DoubleSpinWidget:update() function DoubleSpinWidget:update()
-- This picker_update_callback will be redefined later. It is needed -- This picker_update_callback will be redefined later. It is needed
-- so we can have our MovableContainer repainted on NumberPickerWidgets -- so we can have our MovableContainer repainted on NumberPickerWidgets
-- update It is needed if we have enabled transparency on MovableContainer, -- update. It is needed if we have enabled transparency on MovableContainer,
-- otherwise the NumberPicker area gets opaque on update. -- otherwise the NumberPicker area gets opaque on update.
local picker_update_callback = function() end local picker_update_callback = function() end
local left_widget = NumberPickerWidget:new{ local left_widget = NumberPickerWidget:new{
@ -166,7 +172,7 @@ function DoubleSpinWidget:update()
margin = Size.margin.small, margin = Size.margin.small,
bordersize = 0, bordersize = 0,
TextBoxWidget:new{ TextBoxWidget:new{
text = self.info_text, text = self.info_text or "",
face = Font:getFace("x_smallinfofont"), face = Font:getFace("x_smallinfofont"),
width = self.width * 0.9, width = self.width * 0.9,
} }
@ -174,17 +180,20 @@ function DoubleSpinWidget:update()
local buttons = { local buttons = {
{ {
{ {
text = _("Close"), text = self.cancel_text,
callback = function() callback = function()
self:onClose() self:onClose()
end, end,
}, },
{ {
text = _("Apply"), text = self.ok_text,
callback = function() callback = function()
if self.callback then if self.callback then
self.callback(left_widget:getValue(), right_widget:getValue()) self.callback(left_widget:getValue(), right_widget:getValue())
end end
if not self.keep_shown_on_apply then
self:onClose()
end
end, end,
}, },
}, },
@ -203,6 +212,21 @@ function DoubleSpinWidget:update()
} }
}) })
end end
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
local button_table = ButtonTable:new{ local button_table = ButtonTable:new{
width = self.width - 2*Size.padding.default, width = self.width - 2*Size.padding.default,
@ -263,6 +287,11 @@ function DoubleSpinWidget:update()
end end
end end
function DoubleSpinWidget:hasMoved()
local offset = self.movable:getMovedOffset()
return offset.x ~= 0 or offset.y ~= 0
end
function DoubleSpinWidget:onCloseWidget() function DoubleSpinWidget:onCloseWidget()
UIManager:setDirty(nil, function() UIManager:setDirty(nil, function()
return "partial", self.widget_frame.dimen return "partial", self.widget_frame.dimen

@ -10,6 +10,7 @@ local Font = require("ui/font")
local HorizontalGroup = require("ui/widget/horizontalgroup") local HorizontalGroup = require("ui/widget/horizontalgroup")
local InputContainer = require("ui/widget/container/inputcontainer") local InputContainer = require("ui/widget/container/inputcontainer")
local LineWidget = require("ui/widget/linewidget") local LineWidget = require("ui/widget/linewidget")
local MovableContainer = require("ui/widget/container/movablecontainer")
local NumberPickerWidget = require("ui/widget/numberpickerwidget") local NumberPickerWidget = require("ui/widget/numberpickerwidget")
local OverlapGroup = require("ui/widget/overlapgroup") local OverlapGroup = require("ui/widget/overlapgroup")
local Size = require("ui/size") local Size = require("ui/size")
@ -22,8 +23,9 @@ local _ = require("gettext")
local Screen = Device.screen local Screen = Device.screen
local SpinWidget = InputContainer:new{ local SpinWidget = InputContainer:new{
title_text = "",
title_face = Font:getFace("x_smalltfont"), title_face = Font:getFace("x_smalltfont"),
text = nil, info_text = nil,
width = Screen:getWidth() * 0.95, width = Screen:getWidth() * 0.95,
height = Screen:getHeight(), height = Screen:getHeight(),
value_table = nil, value_table = nil,
@ -33,14 +35,15 @@ local SpinWidget = InputContainer:new{
value_min = 0, value_min = 0,
value_step = 1, value_step = 1,
value_hold_step = 4, value_hold_step = 4,
ok_text = _("OK"), cancel_text = _("Close"),
cancel_text = _("Cancel"), ok_text = _("Apply"),
-- extra button on bottom keep_shown_on_apply = false,
extra_text = nil, -- Set this to add default button that restores number to its default value
extra_callback = nil,
-- set this to see extra default button
default_value = nil, default_value = nil,
default_text = _("Use default"), default_text = _("Use default"),
-- Optional extra button on bottom
extra_text = nil,
extra_callback = nil,
} }
function SpinWidget:init() function SpinWidget:init()
@ -70,6 +73,11 @@ function SpinWidget:init()
end end
function SpinWidget:update() function SpinWidget:update()
-- This picker_update_callback will be redefined later. It is needed
-- so we can have our MovableContainer repainted on NumberPickerWidgets
-- update. It is needed if we have enabled transparency on MovableContainer,
-- otherwise the NumberPicker area gets opaque on update.
local picker_update_callback = function() end
local value_widget = NumberPickerWidget:new{ local value_widget = NumberPickerWidget:new{
show_parent = self, show_parent = self,
width = self.screen_width * 0.2, width = self.screen_width * 0.2,
@ -81,6 +89,7 @@ function SpinWidget:update()
value_step = self.value_step, value_step = self.value_step,
value_hold_step = self.value_hold_step, value_hold_step = self.value_hold_step,
precision = self.precision, precision = self.precision,
update_callback = function() picker_update_callback() end,
} }
local value_group = HorizontalGroup:new{ local value_group = HorizontalGroup:new{
align = "center", align = "center",
@ -134,7 +143,9 @@ function SpinWidget:update()
self.value, self.value_index = value_widget:getValue() self.value, self.value_index = value_widget:getValue()
self:callback(self) self:callback(self)
end end
self:onClose() if not self.keep_shown_on_apply then
self:onClose()
end
end, end,
}, },
} }
@ -151,19 +162,21 @@ function SpinWidget:update()
}, },
}) })
end end
if self.extra_text then if self.extra_text then
table.insert(buttons,{ table.insert(buttons,{
{ {
text = self.extra_text, text = self.extra_text,
callback = function() callback = function()
if self.extra_callback then if self.extra_callback then
self.value, self.value_index = value_widget:getValue() self.value, self.value_index = value_widget:getValue()
self.extra_callback(self) self.extra_callback(self)
end end
if not self.keep_shown_on_apply then -- assume extra wants it same as ok
self:onClose() self:onClose()
end, end
}, end,
}) },
})
end end
local ok_cancel_buttons = ButtonTable:new{ local ok_cancel_buttons = ButtonTable:new{
@ -178,13 +191,13 @@ function SpinWidget:update()
value_bar, value_bar,
value_line, value_line,
} }
if self.text then if self.info_text then
table.insert(vgroup, FrameContainer:new{ table.insert(vgroup, FrameContainer:new{
padding = Size.padding.default, padding = Size.padding.default,
margin = Size.margin.small, margin = Size.margin.small,
bordersize = 0, bordersize = 0,
TextBoxWidget:new{ TextBoxWidget:new{
text = self.text, text = self.info_text,
face = Font:getFace("x_smallinfofont"), face = Font:getFace("x_smallinfofont"),
width = self.width * 0.9, width = self.width * 0.9,
} }
@ -211,6 +224,9 @@ function SpinWidget:update()
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,
vgroup, vgroup,
} }
self.movable = MovableContainer:new{
self.spin_frame,
}
self[1] = WidgetContainer:new{ self[1] = WidgetContainer:new{
align = "center", align = "center",
dimen =Geom:new{ dimen =Geom:new{
@ -218,14 +234,21 @@ function SpinWidget:update()
w = self.screen_width, w = self.screen_width,
h = self.screen_height, h = self.screen_height,
}, },
FrameContainer:new{ self.movable,
bordersize = 0,
self.spin_frame,
}
} }
UIManager:setDirty(self, function() UIManager:setDirty(self, function()
return "ui", self.spin_frame.dimen return "ui", self.spin_frame.dimen
end) end)
picker_update_callback = function()
UIManager:setDirty("all", function()
return "ui", self.movable.dimen
end)
end
end
function SpinWidget:hasMoved()
local offset = self.movable:getMovedOffset()
return offset.x ~= 0 or offset.y ~= 0
end end
function SpinWidget:onCloseWidget() function SpinWidget:onCloseWidget()

@ -414,7 +414,7 @@ function CoverBrowser:addToMainMenu(menu_items)
{ {
text = _("(Detailed list) Files per page"), text = _("(Detailed list) Files per page"),
help_text = _([[This sets the number of files and directories per page in non-'classic' display modes.]]), help_text = _([[This sets the number of files and directories per page in non-'classic' display modes.]]),
keep_menu_open = true, -- Best to not "keep_menu_open = true", to see how this apply on the full view
callback = function() callback = function()
local SpinWidget = require("ui/widget/spinwidget") local SpinWidget = require("ui/widget/spinwidget")
-- "files_per_page" should have been saved with an adequate value -- "files_per_page" should have been saved with an adequate value
@ -426,7 +426,7 @@ function CoverBrowser:addToMainMenu(menu_items)
value = curr_items, value = curr_items,
value_min = 4, value_min = 4,
value_max = 20, value_max = 20,
ok_text = _("Set files"), keep_shown_on_apply = true,
title_text = _("Files per page"), title_text = _("Files per page"),
callback = function(spin) callback = function(spin)
BookInfoManager:saveSetting("files_per_page", spin.value) BookInfoManager:saveSetting("files_per_page", spin.value)

@ -791,7 +791,7 @@ The max value ensures a page you stay on for a long time (because you fell aslee
value_max = 5, value_max = 5,
ok_text = _("Set"), ok_text = _("Set"),
title_text = _("Books per calendar day"), title_text = _("Books per calendar day"),
text = _("Set the max number of book spans to show for a day"), info_text = _("Set the max number of book spans to show for a day"),
callback = function(spin) callback = function(spin)
self.calendar_nb_book_spans = spin.value self.calendar_nb_book_spans = spin.value
touchmenu_instance:updateItems() touchmenu_instance:updateItems()

Loading…
Cancel
Save