mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
ConfigDialog: show button with default values in spinwidgets (#9558)
This commit is contained in:
@@ -586,16 +586,15 @@ Note that your selected font size is not affected by this setting.]]),
|
||||
name_text_hold_callback = optionsutil.showValues,
|
||||
more_options = true,
|
||||
more_options_param = {
|
||||
-- values table taken from crengine/crengine/Tools/GammaGen/gammagen.cpp
|
||||
-- Values table taken from crengine/crengine/Tools/GammaGen/gammagen.cpp.
|
||||
-- crengine counts the index of the table starting from 0.
|
||||
-- Index is stored in the settings and passed to crengine as-is.
|
||||
-- ConfigDialog adds value_table_shift to the index to display the value from the table.
|
||||
value_table = { 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9,
|
||||
0.95, 0.98, 1, 1.02, 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45,
|
||||
1.5, 1.6, 1.7, 1.8, 1.9, 2, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9,
|
||||
3, 3.5, 4, 4.5, 5, 5.5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
|
||||
args_table = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
|
||||
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
|
||||
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 29, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56 },
|
||||
value_step = 1,
|
||||
value_table_shift = 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -90,25 +90,10 @@ function optionsutil.showValues(configurable, option, prefix, document, unit)
|
||||
end
|
||||
elseif option.labels and option.values then
|
||||
if option.more_options_param and option.more_options_param.value_table then
|
||||
if option.more_options_param.args_table then
|
||||
for k,v in pairs(option.more_options_param.args_table) do
|
||||
if v == current then
|
||||
current = k
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
current = option.more_options_param.value_table[current]
|
||||
local table_shift = option.more_options_param.value_table_shift or 0
|
||||
current = option.more_options_param.value_table[current + table_shift]
|
||||
if default then
|
||||
if option.more_options_param.args_table then
|
||||
for k,v in pairs(option.more_options_param.args_table) do
|
||||
if v == default then
|
||||
default = k
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
default = option.more_options_param.value_table[default]
|
||||
default = option.more_options_param.value_table[default + table_shift]
|
||||
end
|
||||
else
|
||||
if default then
|
||||
|
||||
@@ -1148,12 +1148,15 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, m
|
||||
if more_options_param.left_min then -- DoubleSpinWidget
|
||||
local DoubleSpinWidget = require("ui/widget/doublespinwidget")
|
||||
-- (No support for value_table - add it if needed)
|
||||
local curr_values
|
||||
local curr_values, default_values
|
||||
if more_options_param.names then -- allows managing 2 different settings
|
||||
curr_values = { self.configurable[more_options_param.names[1]],
|
||||
self.configurable[more_options_param.names[2]] }
|
||||
default_values = { G_reader_settings:readSetting(self.config_options.prefix.."_"..more_options_param.names[1]),
|
||||
G_reader_settings:readSetting(self.config_options.prefix.."_"..more_options_param.names[2]) }
|
||||
else
|
||||
curr_values = self.configurable[name]
|
||||
default_values = G_reader_settings:readSetting(self.config_options.prefix.."_"..name)
|
||||
end
|
||||
widget = DoubleSpinWidget:new{
|
||||
width_factor = more_options_param.widget_width_factor,
|
||||
@@ -1171,6 +1174,9 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, m
|
||||
right_max = more_options_param.right_max,
|
||||
right_step = more_options_param.right_step,
|
||||
right_hold_step = more_options_param.right_hold_step,
|
||||
default_values = true,
|
||||
left_default = default_values[1],
|
||||
right_default = default_values[2],
|
||||
keep_shown_on_apply = true,
|
||||
unit = more_options_param.unit,
|
||||
precision = more_options_param.precision,
|
||||
@@ -1226,6 +1232,9 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, m
|
||||
setting_name = self.config_options.prefix.."_"..name
|
||||
G_reader_settings:saveSetting(setting_name, value_tables)
|
||||
end
|
||||
widget.left_default = left_value
|
||||
widget.right_default = right_value
|
||||
widget:update()
|
||||
self:update()
|
||||
UIManager:setDirty(self, function()
|
||||
return "ui", self.dialog_frame.dimen
|
||||
@@ -1243,18 +1252,12 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, m
|
||||
value_hold_step = values[2] - values[1]
|
||||
end
|
||||
local curr_items = self.configurable[name]
|
||||
local value_index = nil
|
||||
local value_index
|
||||
local default_value = G_reader_settings:readSetting(self.config_options.prefix.."_"..name)
|
||||
if more_options_param.value_table then
|
||||
if more_options_param.args_table then
|
||||
for k,v in pairs(more_options_param.args_table) do
|
||||
if v == curr_items then
|
||||
value_index = k
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
value_index = curr_items
|
||||
end
|
||||
local table_shift = more_options_param.value_table_shift or 0
|
||||
value_index = curr_items + table_shift
|
||||
default_value = default_value + table_shift
|
||||
end
|
||||
widget = SpinWidget:new{
|
||||
width_factor = more_options_param.widget_width_factor,
|
||||
@@ -1269,6 +1272,7 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, m
|
||||
value_max = more_options_param.value_max or values[#values],
|
||||
unit = more_options_param.unit,
|
||||
precision = more_options_param.precision,
|
||||
default_value = default_value,
|
||||
keep_shown_on_apply = true,
|
||||
close_callback = function()
|
||||
if when_applied_callback then
|
||||
@@ -1277,15 +1281,14 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, m
|
||||
end
|
||||
end,
|
||||
callback = function(spin)
|
||||
local spin_value
|
||||
if more_options_param.value_table then
|
||||
if more_options_param.args_table then
|
||||
self:onConfigChoice(name, more_options_param.args_table[spin.value_index])
|
||||
else
|
||||
self:onConfigChoice(name, spin.value_index)
|
||||
end
|
||||
local table_shift = more_options_param.value_table_shift or 0
|
||||
spin_value = spin.value_index - table_shift
|
||||
else
|
||||
self:onConfigChoice(name, spin.value)
|
||||
spin_value = spin.value
|
||||
end
|
||||
self:onConfigChoice(name, spin_value)
|
||||
if event then
|
||||
-- Repainting (with when_applied_callback) if hide_on_picker_show
|
||||
-- is done in close_callback, but we want onConfigEvent to
|
||||
@@ -1294,15 +1297,7 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, m
|
||||
local dummy_callback = when_applied_callback and function() end
|
||||
args = args or {}
|
||||
Notification:setNotifySource(Notification.SOURCE_BOTTOM_MENU_MORE)
|
||||
if more_options_param.value_table then
|
||||
if more_options_param.args_table then
|
||||
self:onConfigEvent(event, more_options_param.args_table[spin.value_index], dummy_callback)
|
||||
else
|
||||
self:onConfigEvent(event, spin.value_index, dummy_callback)
|
||||
end
|
||||
else
|
||||
self:onConfigEvent(event, spin.value, dummy_callback)
|
||||
end
|
||||
self:onConfigEvent(event, spin_value, dummy_callback)
|
||||
UIManager:tickAfterNext(function()
|
||||
Notification:resetNotifySource()
|
||||
end)
|
||||
@@ -1321,16 +1316,17 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, m
|
||||
text = T(_("Set default %1 to %2?"), (name_text or ""), value_string),
|
||||
ok_text = T(_("Set as default")),
|
||||
ok_callback = function()
|
||||
local setting_name = self.config_options.prefix.."_"..name
|
||||
local spin_value
|
||||
if more_options_param.value_table then
|
||||
if more_options_param.args_table then
|
||||
G_reader_settings:saveSetting(setting_name, more_options_param.args_table[spin.value_index])
|
||||
else
|
||||
G_reader_settings:saveSetting(setting_name, spin.value_index)
|
||||
end
|
||||
local table_shift = more_options_param.value_table_shift or 0
|
||||
spin_value = spin.value_index - table_shift
|
||||
widget.default_value = spin.value_index
|
||||
else
|
||||
G_reader_settings:saveSetting(setting_name, spin.value)
|
||||
spin_value = spin.value
|
||||
widget.default_value = spin.value
|
||||
end
|
||||
G_reader_settings:saveSetting(self.config_options.prefix.."_"..name, spin_value)
|
||||
widget:update()
|
||||
self:update()
|
||||
UIManager:setDirty(self, function()
|
||||
return "ui", self.dialog_frame.dimen
|
||||
|
||||
@@ -134,12 +134,28 @@ function SpinWidget:update(numberpicker_value, numberpicker_value_index)
|
||||
unit = "\xE2\x80\xAF" .. self.unit -- use Narrow No-Break Space (NNBSP) here
|
||||
end
|
||||
end
|
||||
local value
|
||||
if self.default_text then
|
||||
value = self.default_text
|
||||
else
|
||||
if self.value_table then
|
||||
value = self.value_table[self.default_value]
|
||||
else
|
||||
value = self.default_value
|
||||
end
|
||||
if self.precision then
|
||||
value = string.format(self.precision, value)
|
||||
end
|
||||
end
|
||||
table.insert(buttons, {
|
||||
{
|
||||
text = self.default_text or T(_("Default value: %1%2"),
|
||||
self.precision and string.format(self.precision, self.default_value) or self.default_value, unit),
|
||||
text = T(_("Default value: %1%2"), value, unit),
|
||||
callback = function()
|
||||
value_widget.value = self.default_value
|
||||
if value_widget.value_table then
|
||||
value_widget.value_index = self.default_value
|
||||
else
|
||||
value_widget.value = self.default_value
|
||||
end
|
||||
value_widget:update()
|
||||
end,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user