mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
[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).
This commit is contained in:
@@ -147,8 +147,8 @@ function FileManagerMenu:setUpdateItemTable()
|
||||
value = curr_items,
|
||||
value_min = 6,
|
||||
value_max = 24,
|
||||
ok_text = _("Set items"),
|
||||
title_text = _("Items per page"),
|
||||
keep_shown_on_apply = true,
|
||||
callback = function(spin)
|
||||
G_reader_settings:saveSetting("items_per_page", spin.value)
|
||||
self.ui:onRefresh()
|
||||
@@ -171,7 +171,7 @@ function FileManagerMenu:setUpdateItemTable()
|
||||
value_min = 10,
|
||||
value_max = 72,
|
||||
default_value = default_font_size,
|
||||
ok_text = _("Set size"),
|
||||
keep_shown_on_apply = true,
|
||||
title_text = _("Maximum font size for item"),
|
||||
callback = function(spin)
|
||||
G_reader_settings:saveSetting("items_font_size", spin.value)
|
||||
|
||||
@@ -872,6 +872,7 @@ function ReaderFooter:addToMainMenu(menu_items)
|
||||
default_value = 14,
|
||||
ok_text = _("Set size"),
|
||||
title_text = _("Footer font size"),
|
||||
keep_shown_on_apply = true,
|
||||
callback = function(spin)
|
||||
self.settings.text_font_size = spin.value
|
||||
self.footer_text:free()
|
||||
@@ -927,7 +928,8 @@ function ReaderFooter:addToMainMenu(menu_items)
|
||||
value_hold_step = 20,
|
||||
value_max = 100,
|
||||
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)
|
||||
self.settings.book_title_max_width_pct = spin.value
|
||||
self:refreshFooter(true, true)
|
||||
@@ -952,7 +954,8 @@ function ReaderFooter:addToMainMenu(menu_items)
|
||||
value_hold_step = 20,
|
||||
value_max = 100,
|
||||
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)
|
||||
self.settings.book_chapter_max_width_pct = spin.value
|
||||
self:refreshFooter(true, true)
|
||||
@@ -1339,6 +1342,7 @@ function ReaderFooter:addToMainMenu(menu_items)
|
||||
value_max = value_max,
|
||||
default_value = default_value,
|
||||
title_text = _("Progress bar size"),
|
||||
keep_shown_on_apply = true,
|
||||
callback = function(spin)
|
||||
if self.settings.progress_style_thin then
|
||||
self.settings.progress_style_thin_height = spin.value
|
||||
@@ -1499,6 +1503,7 @@ function ReaderFooter:addToMainMenu(menu_items)
|
||||
value_max = 50,
|
||||
title_text = _("Minimal width"),
|
||||
text = _("Minimal progress bar width in percentage of screen width"),
|
||||
keep_shown_on_apply = true,
|
||||
callback = function(spin)
|
||||
self.settings.progress_bar_min_width_pct = spin.value
|
||||
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",
|
||||
ok_text = _("Set 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.
|
||||
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.
|
||||
|
||||
@@ -388,6 +388,7 @@ function ReaderPageMap:addToMainMenu(menu_items)
|
||||
text_func = function()
|
||||
return T(_("Page labels font size (%1)"), self.label_font_size)
|
||||
end,
|
||||
enabled_func = function() return self.show_page_labels end,
|
||||
callback = function(touchmenu_instance)
|
||||
local SpinWidget = require("ui/widget/spinwidget")
|
||||
local spin_w = SpinWidget:new{
|
||||
@@ -396,8 +397,8 @@ function ReaderPageMap:addToMainMenu(menu_items)
|
||||
value_min = 8,
|
||||
value_max = 20,
|
||||
default_value = self.label_default_font_size,
|
||||
ok_text = _("Set size"),
|
||||
title_text = _("Page labels font size"),
|
||||
keep_shown_on_apply = true,
|
||||
callback = function(spin)
|
||||
self.label_font_size = spin.value
|
||||
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",
|
||||
ok_text = _("Set"),
|
||||
title_text = _("Set overlapped lines"),
|
||||
text = overlap_lines_help_text,
|
||||
info_text = overlap_lines_help_text,
|
||||
callback = function(spin)
|
||||
G_reader_settings:saveSetting("copt_overlap_lines", spin.value)
|
||||
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.
|
||||
These settings will apply to all books with any hyphenation dictionary.
|
||||
'Use language defaults' resets them.]]),
|
||||
keep_shown_on_apply = true,
|
||||
callback = function(left_hyphen_min, right_hyphen_min)
|
||||
G_reader_settings:saveSetting("hyph_left_hyphen_min", left_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{
|
||||
title_text = "",
|
||||
title_face = Font:getFace("x_smalltfont"),
|
||||
info_text = "",
|
||||
info_text = nil,
|
||||
width = nil,
|
||||
height = nil,
|
||||
left_min = 1,
|
||||
@@ -39,9 +39,15 @@ local DoubleSpinWidget = InputContainer:new{
|
||||
right_value = 1,
|
||||
right_default = nil,
|
||||
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_text = _("Use defaults"),
|
||||
-- Optional extra button on bottom
|
||||
extra_text = nil,
|
||||
extra_callback = nil,
|
||||
}
|
||||
|
||||
function DoubleSpinWidget:init()
|
||||
@@ -74,7 +80,7 @@ end
|
||||
function DoubleSpinWidget: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,
|
||||
-- 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 left_widget = NumberPickerWidget:new{
|
||||
@@ -166,7 +172,7 @@ function DoubleSpinWidget:update()
|
||||
margin = Size.margin.small,
|
||||
bordersize = 0,
|
||||
TextBoxWidget:new{
|
||||
text = self.info_text,
|
||||
text = self.info_text or "",
|
||||
face = Font:getFace("x_smallinfofont"),
|
||||
width = self.width * 0.9,
|
||||
}
|
||||
@@ -174,17 +180,20 @@ function DoubleSpinWidget:update()
|
||||
local buttons = {
|
||||
{
|
||||
{
|
||||
text = _("Close"),
|
||||
text = self.cancel_text,
|
||||
callback = function()
|
||||
self:onClose()
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("Apply"),
|
||||
text = self.ok_text,
|
||||
callback = function()
|
||||
if self.callback then
|
||||
self.callback(left_widget:getValue(), right_widget:getValue())
|
||||
end
|
||||
if not self.keep_shown_on_apply then
|
||||
self:onClose()
|
||||
end
|
||||
end,
|
||||
},
|
||||
},
|
||||
@@ -203,6 +212,21 @@ function DoubleSpinWidget:update()
|
||||
}
|
||||
})
|
||||
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{
|
||||
width = self.width - 2*Size.padding.default,
|
||||
@@ -263,6 +287,11 @@ function DoubleSpinWidget:update()
|
||||
end
|
||||
end
|
||||
|
||||
function DoubleSpinWidget:hasMoved()
|
||||
local offset = self.movable:getMovedOffset()
|
||||
return offset.x ~= 0 or offset.y ~= 0
|
||||
end
|
||||
|
||||
function DoubleSpinWidget:onCloseWidget()
|
||||
UIManager:setDirty(nil, function()
|
||||
return "partial", self.widget_frame.dimen
|
||||
|
||||
@@ -10,6 +10,7 @@ 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 NumberPickerWidget = require("ui/widget/numberpickerwidget")
|
||||
local OverlapGroup = require("ui/widget/overlapgroup")
|
||||
local Size = require("ui/size")
|
||||
@@ -22,8 +23,9 @@ local _ = require("gettext")
|
||||
local Screen = Device.screen
|
||||
|
||||
local SpinWidget = InputContainer:new{
|
||||
title_text = "",
|
||||
title_face = Font:getFace("x_smalltfont"),
|
||||
text = nil,
|
||||
info_text = nil,
|
||||
width = Screen:getWidth() * 0.95,
|
||||
height = Screen:getHeight(),
|
||||
value_table = nil,
|
||||
@@ -33,14 +35,15 @@ local SpinWidget = InputContainer:new{
|
||||
value_min = 0,
|
||||
value_step = 1,
|
||||
value_hold_step = 4,
|
||||
ok_text = _("OK"),
|
||||
cancel_text = _("Cancel"),
|
||||
-- extra button on bottom
|
||||
extra_text = nil,
|
||||
extra_callback = nil,
|
||||
-- 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 number to its default value
|
||||
default_value = nil,
|
||||
default_text = _("Use default"),
|
||||
-- Optional extra button on bottom
|
||||
extra_text = nil,
|
||||
extra_callback = nil,
|
||||
}
|
||||
|
||||
function SpinWidget:init()
|
||||
@@ -70,6 +73,11 @@ function SpinWidget:init()
|
||||
end
|
||||
|
||||
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{
|
||||
show_parent = self,
|
||||
width = self.screen_width * 0.2,
|
||||
@@ -81,6 +89,7 @@ function SpinWidget:update()
|
||||
value_step = self.value_step,
|
||||
value_hold_step = self.value_hold_step,
|
||||
precision = self.precision,
|
||||
update_callback = function() picker_update_callback() end,
|
||||
}
|
||||
local value_group = HorizontalGroup:new{
|
||||
align = "center",
|
||||
@@ -134,7 +143,9 @@ function SpinWidget:update()
|
||||
self.value, self.value_index = value_widget:getValue()
|
||||
self:callback(self)
|
||||
end
|
||||
self:onClose()
|
||||
if not self.keep_shown_on_apply then
|
||||
self:onClose()
|
||||
end
|
||||
end,
|
||||
},
|
||||
}
|
||||
@@ -151,19 +162,21 @@ function SpinWidget:update()
|
||||
},
|
||||
})
|
||||
end
|
||||
if self.extra_text then
|
||||
table.insert(buttons,{
|
||||
{
|
||||
text = self.extra_text,
|
||||
callback = function()
|
||||
if self.extra_callback then
|
||||
self.value, self.value_index = value_widget:getValue()
|
||||
self.extra_callback(self)
|
||||
end
|
||||
if self.extra_text then
|
||||
table.insert(buttons,{
|
||||
{
|
||||
text = self.extra_text,
|
||||
callback = function()
|
||||
if self.extra_callback then
|
||||
self.value, self.value_index = value_widget:getValue()
|
||||
self.extra_callback(self)
|
||||
end
|
||||
if not self.keep_shown_on_apply then -- assume extra wants it same as ok
|
||||
self:onClose()
|
||||
end,
|
||||
},
|
||||
})
|
||||
end
|
||||
end,
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
local ok_cancel_buttons = ButtonTable:new{
|
||||
@@ -178,13 +191,13 @@ function SpinWidget:update()
|
||||
value_bar,
|
||||
value_line,
|
||||
}
|
||||
if self.text then
|
||||
if self.info_text then
|
||||
table.insert(vgroup, FrameContainer:new{
|
||||
padding = Size.padding.default,
|
||||
margin = Size.margin.small,
|
||||
bordersize = 0,
|
||||
TextBoxWidget:new{
|
||||
text = self.text,
|
||||
text = self.info_text,
|
||||
face = Font:getFace("x_smallinfofont"),
|
||||
width = self.width * 0.9,
|
||||
}
|
||||
@@ -211,6 +224,9 @@ function SpinWidget:update()
|
||||
background = Blitbuffer.COLOR_WHITE,
|
||||
vgroup,
|
||||
}
|
||||
self.movable = MovableContainer:new{
|
||||
self.spin_frame,
|
||||
}
|
||||
self[1] = WidgetContainer:new{
|
||||
align = "center",
|
||||
dimen =Geom:new{
|
||||
@@ -218,14 +234,21 @@ function SpinWidget:update()
|
||||
w = self.screen_width,
|
||||
h = self.screen_height,
|
||||
},
|
||||
FrameContainer:new{
|
||||
bordersize = 0,
|
||||
self.spin_frame,
|
||||
}
|
||||
self.movable,
|
||||
}
|
||||
UIManager:setDirty(self, function()
|
||||
return "ui", self.spin_frame.dimen
|
||||
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
|
||||
|
||||
function SpinWidget:onCloseWidget()
|
||||
|
||||
@@ -414,7 +414,7 @@ function CoverBrowser:addToMainMenu(menu_items)
|
||||
{
|
||||
text = _("(Detailed list) Files per page"),
|
||||
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()
|
||||
local SpinWidget = require("ui/widget/spinwidget")
|
||||
-- "files_per_page" should have been saved with an adequate value
|
||||
@@ -426,7 +426,7 @@ function CoverBrowser:addToMainMenu(menu_items)
|
||||
value = curr_items,
|
||||
value_min = 4,
|
||||
value_max = 20,
|
||||
ok_text = _("Set files"),
|
||||
keep_shown_on_apply = true,
|
||||
title_text = _("Files per page"),
|
||||
callback = function(spin)
|
||||
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,
|
||||
ok_text = _("Set"),
|
||||
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)
|
||||
self.calendar_nb_book_spans = spin.value
|
||||
touchmenu_instance:updateItems()
|
||||
|
||||
Reference in New Issue
Block a user