mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
BottomMenu: show real sizes for margins and font size (#9205)
This commit is contained in:
@@ -239,6 +239,10 @@ function Device:setScreenDPI(dpi_override)
|
||||
self.input.gesture_detector:init()
|
||||
end
|
||||
|
||||
function Device:getDeviceScreenDPI()
|
||||
return self.display_dpi
|
||||
end
|
||||
|
||||
function Device:getPowerDevice()
|
||||
return self.powerd
|
||||
end
|
||||
|
||||
@@ -223,7 +223,9 @@ In the top menu → Settings → Status bar, you can choose whether the bottom m
|
||||
DCREREADER_CONFIG_T_MARGIN_SIZES_XX_HUGE,
|
||||
},
|
||||
hide_on_apply = true,
|
||||
name_text_hold_callback = optionsutil.showValues,
|
||||
name_text_hold_callback = function(configurable, opt, prefix)
|
||||
optionsutil.showValues(configurable, opt, prefix, nil, "mm")
|
||||
end,
|
||||
more_options = true,
|
||||
more_options_param = {
|
||||
-- Allow this to tune both top and bottom margins, handling
|
||||
@@ -275,7 +277,9 @@ In the top menu → Settings → Status bar, you can choose whether the bottom m
|
||||
DCREREADER_CONFIG_B_MARGIN_SIZES_XX_HUGE,
|
||||
},
|
||||
hide_on_apply = true,
|
||||
name_text_hold_callback = optionsutil.showValues,
|
||||
name_text_hold_callback = function(configurable, opt, prefix)
|
||||
optionsutil.showValues(configurable, opt, prefix, nil, "mm")
|
||||
end,
|
||||
help_text = _([[In the top menu → Settings → Status bar, you can choose whether the bottom margin applies from the bottom of the screen, or from above the status bar.]]),
|
||||
more_options = true,
|
||||
more_options_param = {
|
||||
@@ -451,7 +455,7 @@ Note that your selected font size is not affected by this setting.]]),
|
||||
name = "font_size",
|
||||
name_text = _("Font Size"),
|
||||
}
|
||||
optionsutil.showValues(configurable, opt, prefix)
|
||||
optionsutil.showValues(configurable, opt, prefix, nil, "pt")
|
||||
end,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -2,11 +2,14 @@
|
||||
This module contains miscellaneous helper functions for the creoptions and koptoptions.
|
||||
]]
|
||||
|
||||
local Device = require("device")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local _ = require("gettext")
|
||||
local C_ = _.pgettext
|
||||
local T = require("ffi/util").template
|
||||
local logger = require("logger")
|
||||
local Screen = Device.screen
|
||||
|
||||
local optionsutil = {}
|
||||
|
||||
@@ -14,7 +17,44 @@ function optionsutil.enableIfEquals(configurable, option, value)
|
||||
return configurable[option] == value
|
||||
end
|
||||
|
||||
function optionsutil.showValues(configurable, option, prefix, document)
|
||||
-- Converts px size to mm, inch or pt
|
||||
-- if the `metric_length`-setting is not set or true -> mm
|
||||
-- if the `metric_length`-setting is false -> inch
|
||||
-- if format == "pt" -> pt
|
||||
local function convertSizeTo(px, format)
|
||||
local format_factor = 1 -- we are defaulting on mm
|
||||
|
||||
if format == "pt" then
|
||||
format_factor = format_factor * 2660 / 1000 -- see https://www.wikiwand.com/en/Metric_typographic_units
|
||||
elseif format == "in" then
|
||||
format_factor = 1 / 25.4
|
||||
end
|
||||
|
||||
local display_dpi = Device:getDeviceScreenDPI() or Screen:getDPI() -- use device hardcoded dpi if available
|
||||
return Screen:scaleBySize(px) / display_dpi * 25.4 * format_factor
|
||||
end
|
||||
|
||||
local function real_size_string(ko_size, unit)
|
||||
if not ko_size or not unit then return "" end
|
||||
ko_size = tonumber(ko_size)
|
||||
local shown_unit
|
||||
if unit == "pt" then
|
||||
shown_unit = C_("Font size", "pt")
|
||||
elseif unit == "mm" then
|
||||
shown_unit = C_("Length", "mm")
|
||||
elseif unit == "in" then
|
||||
shown_unit = C_("Length", "in")
|
||||
else
|
||||
shown_unit = unit -- for future units
|
||||
end
|
||||
if ko_size then
|
||||
return string.format(" (%.2f %s)", convertSizeTo(ko_size, unit), shown_unit)
|
||||
else
|
||||
return ""
|
||||
end
|
||||
end
|
||||
|
||||
function optionsutil.showValues(configurable, option, prefix, document, unit)
|
||||
local default = G_reader_settings:readSetting(prefix.."_"..option.name)
|
||||
local current = configurable[option.name]
|
||||
local value_default, value_current
|
||||
@@ -123,7 +163,12 @@ function optionsutil.showValues(configurable, option, prefix, document)
|
||||
current, value_current, default)
|
||||
end
|
||||
else
|
||||
text = T(_("%1\n%2\nCurrent value: %3\nDefault value: %4"), name_text, help_text, current, default)
|
||||
if unit ~= "pt" then
|
||||
unit = G_reader_settings:nilOrTrue("metric_length") and "mm" or "in"
|
||||
end
|
||||
text = T(_("%1\n%2\nCurrent value: %3%4\nDefault value: %5%6"), name_text, help_text,
|
||||
current, real_size_string(current, unit),
|
||||
default, real_size_string(default, unit))
|
||||
end
|
||||
UIManager:show(InfoMessage:new{ text=text })
|
||||
end
|
||||
@@ -131,26 +176,30 @@ end
|
||||
function optionsutil.showValuesHMargins(configurable, option)
|
||||
local default = G_reader_settings:readSetting("copt_"..option.name)
|
||||
local current = configurable[option.name]
|
||||
local unit = G_reader_settings:nilOrTrue("metric_length") and "mm" or "in"
|
||||
if not default then
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = T(_([[
|
||||
Current margins:
|
||||
left: %1
|
||||
right: %2
|
||||
left: %1%2
|
||||
right: %3%4
|
||||
Default margins: not set]]),
|
||||
current[1], current[2])
|
||||
current[1], real_size_string(current[1], unit),
|
||||
current[2], real_size_string(current[2], unit))
|
||||
})
|
||||
else
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = T(_([[
|
||||
Current margins:
|
||||
left: %1
|
||||
right: %2
|
||||
left: %1%2
|
||||
right: %3%4
|
||||
Default margins:
|
||||
left: %3
|
||||
right: %4]]),
|
||||
current[1], current[2],
|
||||
default[1], default[2])
|
||||
left: %5%6
|
||||
right: %7%8]]),
|
||||
current[1], real_size_string(current[1], unit),
|
||||
current[2], real_size_string(current[2], unit),
|
||||
default[1], real_size_string(default[1], unit),
|
||||
default[2], real_size_string(default[2], unit))
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -608,4 +608,21 @@ common_settings.screenshot = {
|
||||
keep_menu_open = true,
|
||||
}
|
||||
|
||||
common_settings.units = {
|
||||
text = _("Units"),
|
||||
sub_item_table = {
|
||||
{
|
||||
text = _("Metric length"),
|
||||
checked_func = function()
|
||||
return G_reader_settings:readSetting("metric_length", true)
|
||||
end,
|
||||
callback = function(touchmenu_instance)
|
||||
G_reader_settings:toggle("metric_length")
|
||||
if touchmenu_instance then touchmenu_instance:updateItems() end
|
||||
end,
|
||||
keep_menu_open = true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return common_settings
|
||||
|
||||
@@ -46,6 +46,7 @@ local order = {
|
||||
"font_ui_fallbacks",
|
||||
"----------------------------",
|
||||
"time",
|
||||
"units",
|
||||
"device_status_alarm",
|
||||
"charging_led", -- if Device:canToggleChargingLED()
|
||||
"autostandby",
|
||||
|
||||
@@ -89,6 +89,7 @@ local order = {
|
||||
"font_ui_fallbacks",
|
||||
"----------------------------",
|
||||
"time",
|
||||
"units",
|
||||
"device_status_alarm",
|
||||
"charging_led", -- if Device:canToggleChargingLED()
|
||||
"autostandby",
|
||||
|
||||
Reference in New Issue
Block a user