diff --git a/frontend/ui/data/creoptions.lua b/frontend/ui/data/creoptions.lua index c0854b693..cb5a9189a 100644 --- a/frontend/ui/data/creoptions.lua +++ b/frontend/ui/data/creoptions.lua @@ -335,6 +335,19 @@ Note that your selected font size is not affected by this setting.]]), -- gamma values for these indexes are: labels = {0.8, 1.0, 1.45, 1.90, 2.50, 4.0, 8.0, 15.0}, name_text_hold_callback = optionsutil.showValues, + more_options = true, + more_options_param = { + -- values table taken from crengine/crengine/Tools/GammaGen/gammagen.cpp + 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, + }, }, { name = "font_hinting", diff --git a/frontend/ui/data/optionsutil.lua b/frontend/ui/data/optionsutil.lua index c3a00cc92..37b21fbb2 100644 --- a/frontend/ui/data/optionsutil.lua +++ b/frontend/ui/data/optionsutil.lua @@ -42,16 +42,41 @@ function optionsutil.showValues(configurable, option, prefix) current = arg_table[current] end if option.labels and option.values then - for i=1,#option.labels do - if default == option.values[i] then - default = option.labels[i] - break + 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 - end - for i=1,#option.labels do - if current == option.values[i] then - current = option.labels[i] - break + current = option.more_options_param.value_table[current] + if default ~= _("not set") 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] + end + else + if default ~= _("not set") then + for i=1,#option.labels do + if default == option.values[i] then + default = option.labels[i] + break + end + end + end + for i=1,#option.labels do + if current == option.values[i] then + current = option.labels[i] + break + end end end end diff --git a/frontend/ui/widget/configdialog.lua b/frontend/ui/widget/configdialog.lua index 315a75ba3..76e1e2e75 100644 --- a/frontend/ui/widget/configdialog.lua +++ b/frontend/ui/widget/configdialog.lua @@ -569,7 +569,7 @@ function ConfigOption:init() if arg == "-" or arg == "+" then self.config:onMakeFineTuneDefault(self.options[c].name, self.options[c].name_text, self.options[c].values, self.options[c].labels or self.options[c].args, arg) - else + elseif arg ~= "⋮" then self.config:onMakeDefault(self.options[c].name, self.options[c].name_text, self.options[c].values, self.options[c].labels or self.options[c].args, arg) end @@ -1071,9 +1071,24 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, d if values and event then local SpinWidget = require("ui/widget/spinwidget") local curr_items = self.configurable[name] + local value_index = nil + 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 + end local items = SpinWidget:new{ width = Screen:getWidth() * 0.6, value = curr_items, + value_index = value_index, + value_table = more_options_param.value_table, value_min = more_options_param.value_min or values[1], value_step = more_options_param.value_step or 1, value_hold_step = value_hold_step, @@ -1086,7 +1101,15 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, d ok_text = T(_("Set default")), ok_callback = function() name = self.config_options.prefix.."_"..name - G_reader_settings:saveSetting(name, spin.value) + if more_options_param.value_table then + if more_options_param.args_table then + G_reader_settings:saveSetting(name, more_options_param.args_table[spin.value_index]) + else + G_reader_settings:saveSetting(name, spin.value_index) + end + else + G_reader_settings:saveSetting(name, spin.value) + end self:update() UIManager:setDirty(self, function() return "ui", self.dialog_frame.dimen @@ -1097,10 +1120,26 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, d end, title_text = name_text or _("Set value"), callback = function(spin) - self:onConfigChoice(name, 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 + else + self:onConfigChoice(name, spin.value) + end if event then args = args or {} - self:onConfigEvent(event, spin.value, refresh_callback) + 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], refresh_callback) + else + self:onConfigEvent(event, spin.value_index, refresh_callback) + end + else + self:onConfigEvent(event, spin.value, refresh_callback) + end self:update() end end diff --git a/frontend/ui/widget/numberpickerwidget.lua b/frontend/ui/widget/numberpickerwidget.lua index fae0b5e80..b0e626775 100644 --- a/frontend/ui/widget/numberpickerwidget.lua +++ b/frontend/ui/widget/numberpickerwidget.lua @@ -45,6 +45,7 @@ local NumberPickerWidget = InputContainer:new{ value_step = 1, value_hold_step = 4, value_table = nil, + value_index = nil, wrap = true, update_callback = function() end, -- in case we need calculate number of days in a given month and year @@ -59,10 +60,8 @@ function NumberPickerWidget:init() self.width = self.screen_width * 0.2 end if self.value_table then - self.value_index = 1 + self.value_index = self.value_index or 1 self.value = self.value_table[self.value_index] - self.step = 1 - self.value_hold_step = 1 end self:update() end @@ -275,7 +274,7 @@ end Get value. --]] function NumberPickerWidget:getValue() - return self.value + return self.value, self.value_index end return NumberPickerWidget diff --git a/frontend/ui/widget/spinwidget.lua b/frontend/ui/widget/spinwidget.lua index 2f9ed293d..9aa061789 100644 --- a/frontend/ui/widget/spinwidget.lua +++ b/frontend/ui/widget/spinwidget.lua @@ -27,6 +27,8 @@ local SpinWidget = InputContainer:new{ text = nil, width = Screen:getWidth() * 0.95, height = Screen:getHeight(), + value_table = nil, + value_index = nil, value = 1, value_max = 20, value_min = 0, @@ -73,6 +75,8 @@ function SpinWidget:update() show_parent = self, width = self.screen_width * 0.2, value = self.value, + value_table = self.value_table, + value_index = self.value_index, value_min = self.value_min, value_max = self.value_max, value_step = self.value_step, @@ -136,7 +140,7 @@ function SpinWidget:update() text = self.ok_text, callback = function() if self.callback then - self.value = value_widget:getValue() + self.value, self.value_index = value_widget:getValue() self:callback(self) end self:onClose() @@ -162,7 +166,7 @@ function SpinWidget:update() text = self.extra_text, callback = function() if self.extra_callback then - self.value = value_widget:getValue() + self.value, self.value_index = value_widget:getValue() self.extra_callback(self) end self:onClose()