DoubleSpinWidget, SpinWidget: add units, make usage more consistent (#9046)

This commit is contained in:
zwim
2022-05-24 00:25:50 +02:00
committed by GitHub
parent 13274d6212
commit d5d5867d4e
18 changed files with 184 additions and 75 deletions

View File

@@ -7,6 +7,7 @@ local SpinWidget = require("ui/widget/spinwidget")
local UIManager = require("ui/uimanager")
local powerd = Device:getPowerDevice()
local _ = require("gettext")
local C_ = _.pgettext
local T = require("ffi/util").template
local ReaderDeviceStatus = InputContainer:new{
@@ -36,8 +37,8 @@ function ReaderDeviceStatus:init()
UIManager:close(self.battery_confirm_box)
end
self.battery_confirm_box = ConfirmBox:new {
text = is_charging and T(_("High battery level: %1%\n\nDismiss battery level alert?"), battery_capacity)
or T(_("Low battery level: %1%\n\nDismiss battery level alert?"), battery_capacity),
text = is_charging and T(_("High battery level: %1 %\n\nDismiss battery level alert?"), battery_capacity)
or T(_("Low battery level: %1 %\n\nDismiss battery level alert?"), battery_capacity),
ok_text = _("Dismiss"),
dismissable = false,
ok_callback = function()
@@ -154,6 +155,7 @@ function ReaderDeviceStatus:addToMainMenu(menu_items)
value_min = 1,
value_max = 60,
default_value = 10,
unit = C_("Time", "min"),
value_hold_step = 5,
title_text = _("Battery check interval"),
callback = function(spin)
@@ -172,7 +174,7 @@ function ReaderDeviceStatus:addToMainMenu(menu_items)
table.insert(menu_items.device_status_alarm.sub_item_table,
{
text_func = function()
return T(_("Thresholds: %1% %2%"), self.battery_threshold, self.battery_threshold_high)
return T(_("Thresholds: %1 % / %2 %"), self.battery_threshold, self.battery_threshold_high)
end,
enabled_func = function()
return G_reader_settings:isTrue("device_status_battery_alarm")
@@ -199,16 +201,12 @@ High level threshold is checked when the device is charging.]]),
right_default = 100,
right_hold_step = 5,
default_values = true,
unit = "%",
callback = function(left_value, right_value)
if not left_value then -- "Default" button pressed
left_value = 20
right_value = 100
end
self.battery_threshold = left_value
self.battery_threshold_high = right_value
G_reader_settings:saveSetting("device_status_battery_threshold", self.battery_threshold)
G_reader_settings:saveSetting("device_status_battery_threshold_high", self.battery_threshold_high)
UIManager:close(thresholds_widget)
touchmenu_instance:updateItems()
powerd:setDismissBatteryStatus(false)
end,
@@ -249,6 +247,7 @@ High level threshold is checked when the device is charging.]]),
value_min = 1,
value_max = 60,
default_value = 5,
unit = C_("Time", "min"),
value_hold_step = 5,
title_text = _("Memory check interval"),
callback = function(spin)
@@ -278,6 +277,7 @@ High level threshold is checked when the device is charging.]]),
value_min = 20,
value_max = 500,
default_value = 100,
unit = C_("Data storage size", "MB"),
value_step = 5,
value_hold_step = 10,
title_text = _("Memory alert threshold"),

View File

@@ -630,14 +630,14 @@ function ReaderFooter:set_custom_text(touchmenu_instance)
title = "Enter a custom text",
fields = {
{
text = self.custom_text or "",
text = self.custom_text or "",
description = _("Custom string:"),
input_type = "string",
},
{
text = self.custom_text_repetitions,
description =_("Number of repetitions:"),
input_type = "number",
input_type = "number",
},
},
buttons = {
@@ -1198,7 +1198,7 @@ function ReaderFooter:addToMainMenu(menu_items)
value_max = 36,
default_value = 14,
ok_text = _("Set size"),
title_text = _("Footer font size"),
title_text = _("Footer font size"),
keep_shown_on_apply = true,
callback = function(spin)
self.settings.text_font_size = spin.value
@@ -1251,7 +1251,7 @@ function ReaderFooter:addToMainMenu(menu_items)
value_max = 98,
default_value = DMINIBAR_CONTAINER_HEIGHT,
ok_text = _("Set height"),
title_text = _("Container height"),
title_text = _("Container height"),
keep_shown_on_apply = true,
callback = function(spin)
self.settings.container_height = spin.value
@@ -1277,7 +1277,7 @@ function ReaderFooter:addToMainMenu(menu_items)
value_max = 49,
default_value = 1,
ok_text = _("Set margin"),
title_text = _("Container bottom margin"),
title_text = _("Container bottom margin"),
keep_shown_on_apply = true,
callback = function(spin)
self.settings.container_bottom_padding = spin.value
@@ -1295,7 +1295,7 @@ function ReaderFooter:addToMainMenu(menu_items)
sub_item_table = {
{
text_func = function()
return T(_("Book title: %1%"), self.settings.book_title_max_width_pct)
return T(_("Book title: %1 %"), self.settings.book_title_max_width_pct)
end,
callback = function(touchmenu_instance)
local SpinWidget = require("ui/widget/spinwidget")
@@ -1305,7 +1305,8 @@ function ReaderFooter:addToMainMenu(menu_items)
value_step = 5,
value_hold_step = 20,
value_max = 100,
title_text = _("Maximum width"),
unit = "%",
title_text = _("Maximum width"),
info_text = _("Maximum book title width in percentage of screen width"),
keep_shown_on_apply = true,
callback = function(spin)
@@ -1320,7 +1321,7 @@ function ReaderFooter:addToMainMenu(menu_items)
},
{
text_func = function()
return T(_("Current chapter: %1%"), self.settings.book_chapter_max_width_pct)
return T(_("Current chapter: %1 %"), self.settings.book_chapter_max_width_pct)
end,
callback = function(touchmenu_instance)
local SpinWidget = require("ui/widget/spinwidget")
@@ -1330,7 +1331,8 @@ function ReaderFooter:addToMainMenu(menu_items)
value_step = 5,
value_hold_step = 20,
value_max = 100,
title_text = _("Maximum width"),
unit = "%",
title_text = _("Maximum width"),
info_text = _("Maximum chapter width in percentage of screen width"),
keep_shown_on_apply = true,
callback = function(spin)
@@ -1572,7 +1574,7 @@ With this enabled, the current page is included, so the count goes from n to 1 i
table.insert(sub_items[settings_submenu_num].sub_item_table, 4, {
text_func = function()
if self.settings.battery_hide_threshold <= (Device:hasAuxBattery() and 200 or 100) then
return T(_("Hide battery status if level higher than: %1%"), self.settings.battery_hide_threshold)
return T(_("Hide battery status if level higher than: %1 %"), self.settings.battery_hide_threshold)
else
return _("Hide battery status")
end
@@ -1591,8 +1593,9 @@ With this enabled, the current page is included, so the count goes from n to 1 i
value_min = 0,
value_max = Device:hasAuxBattery() and 200 or 100,
default_value = Device:hasAuxBattery() and 200 or 100,
unit = "%",
value_hold_step = 10,
title_text = _("Hide battery threshold"),
title_text = _("Hide battery threshold"),
callback = function(spin)
self.settings.battery_hide_threshold = spin.value
self:refreshFooter(true, true)
@@ -1747,7 +1750,7 @@ With this enabled, the current page is included, so the count goes from n to 1 i
value_hold_step = 2,
value_max = value_max,
default_value = default_value,
title_text = _("Progress bar size"),
title_text = _("Progress bar size"),
keep_shown_on_apply = true,
callback = function(spin)
if self.settings.progress_style_thin then
@@ -1907,7 +1910,7 @@ With this enabled, the current page is included, so the count goes from n to 1 i
},
{
text_func = function()
return T(_("Minimal width: %1%"), self.settings.progress_bar_min_width_pct)
return T(_("Minimal width: %1 %"), self.settings.progress_bar_min_width_pct)
end,
enabled_func = function()
return self.settings.progress_bar_position == "alongside" and not self.settings.disable_progress_bar
@@ -1921,7 +1924,8 @@ With this enabled, the current page is included, so the count goes from n to 1 i
value_step = 5,
value_hold_step = 20,
value_max = 50,
title_text = _("Minimal width"),
unit = "%",
title_text = _("Minimal width"),
text = _("Minimal progress bar width in percentage of screen width"),
keep_shown_on_apply = true,
callback = function(spin)

View File

@@ -397,9 +397,12 @@ function ReaderHighlight:addToMainMenu(menu_items)
text = _("Long-press on text"),
sub_item_table = {
{
text = _("Highlight long-press interval"),
text_func = function()
return T(_("Highlight long-press interval: %1 s"),
G_reader_settings:readSetting("highlight_long_hold_threshold_s", 3))
end,
keep_menu_open = true,
callback = function()
callback = function(touchmenu_instance)
local SpinWidget = require("ui/widget/spinwidget")
local items = SpinWidget:new{
title_text = _("Highlight long-press interval"),
@@ -408,15 +411,17 @@ If a touch is not released in this interval, it is considered a long-press. On d
The interval value is in seconds and can range from 3 to 20 seconds.]]),
width = math.floor(Screen:getWidth() * 0.75),
value = G_reader_settings:readSetting("highlight_long_hold_threshold", 3),
value = G_reader_settings:readSetting("highlight_long_hold_threshold_s", 3),
value_min = 3,
value_max = 20,
value_step = 1,
value_hold_step = 5,
unit = C_("Time", "s"),
ok_text = _("Set interval"),
default_value = 3,
callback = function(spin)
G_reader_settings:saveSetting("highlight_long_hold_threshold", spin.value)
G_reader_settings:saveSetting("highlight_long_hold_threshold_s", spin.value)
if touchmenu_instance then touchmenu_instance:updateItems() end
end
}
UIManager:show(items)
@@ -1425,7 +1430,7 @@ function ReaderHighlight:onHoldRelease()
local long_final_hold = false
if self.hold_last_time then
local hold_duration = time.now() - self.hold_last_time
local long_hold_threshold_s = G_reader_settings:readSetting("highlight_long_hold_threshold", 3) -- seconds
local long_hold_threshold_s = G_reader_settings:readSetting("highlight_long_hold_threshold_s", 3) -- seconds
if hold_duration > time.s(long_hold_threshold_s) then
-- We stayed 3 seconds before release without updating selection
long_final_hold = true

View File

@@ -5,6 +5,7 @@ local UIManager = require("ui/uimanager")
local logger = require("logger")
local time = require("ui/time")
local _ = require("gettext")
local C_ = _.pgettext
local T = require("ffi/util").template
local Screen = Device.screen
@@ -162,6 +163,7 @@ Default value: %1 ms]]), scroll_activation_delay_default_ms),
value_max = 2000,
value_step = 100,
value_hold_step = 500,
unit = C_("Time", "ms"),
ok_text = _("Set delay"),
default_value = scroll_activation_delay_default_ms,
callback = function(spin)

View File

@@ -349,7 +349,7 @@ When the book's language tag is not among our presets, no specific features will
if G_reader_settings:has("hyph_left_hyphen_min") or
G_reader_settings:has("hyph_right_hyphen_min") then
-- @translators to RTL language translators: %1/left is the min length of the start of a hyphenated word, %2/right is the min length of the end of a hyphenated word (note that there is yet no support for hyphenation with RTL languages, so this will mostly apply to LTR documents)
return T(_("Left/right minimal sizes: %1 - %2"),
return T(_("Left/right minimal sizes: %1 / %2"),
G_reader_settings:readSetting("hyph_left_hyphen_min"),
G_reader_settings:readSetting("hyph_right_hyphen_min"))
end
@@ -376,7 +376,7 @@ When the book's language tag is not among our presets, no specific features will
-- the hyphenation changes happening
width_factor = 0.6,
default_values = true,
default_text = _("Use language defaults"),
default_text = T(_("Language defaults: %1 / %2"), alg_left_hyphen_min, alg_right_hyphen_min),
title_text = _("Hyphenation limits"),
info_text = _([[
Set minimum length before hyphenation occurs.
@@ -384,6 +384,9 @@ 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)
if left_hyphen_min == alg_left_hyphen_min and right_hyphen_min == alg_right_hyphen_min then
left_hyphen_min, right_hyphen_min = nil, nil -- don't store default values
end
G_reader_settings:saveSetting("hyph_left_hyphen_min", left_hyphen_min)
G_reader_settings:saveSetting("hyph_right_hyphen_min", right_hyphen_min)
self.ui.document:setHyphLeftHyphenMin(G_reader_settings:readSetting("hyph_left_hyphen_min") or 0)