mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
UI: Expand the "Units" configuration menu to include "Pixels"
Rename it to "Dimension units", and make it a radio submenu. Migrate the previous metric_length setting to this new dimension_units one. Update optionsutil to follow it.
This commit is contained in:
@@ -10,7 +10,7 @@ local util = require("util")
|
||||
local _ = require("gettext")
|
||||
|
||||
-- Date at which the last migration snippet was added
|
||||
local CURRENT_MIGRATION_DATE = 20240914
|
||||
local CURRENT_MIGRATION_DATE = 20240915
|
||||
|
||||
-- Retrieve the date of the previous migration, if any
|
||||
local last_migration_date = G_reader_settings:readSetting("last_migration_date", 0)
|
||||
@@ -722,5 +722,15 @@ if last_migration_date < 20240914 then
|
||||
G_reader_settings:delSetting("save_document")
|
||||
end
|
||||
|
||||
-- 20240915, metric_length -> dimension_units, https://github.com/koreader/koreader/pull/12507
|
||||
if last_migration_date < 20240915 then
|
||||
logger.info("Performing one-time migration for 20240915")
|
||||
|
||||
if G_reader_settings:has("metric_length") then
|
||||
G_reader_settings:saveSetting("dimension_units", G_reader_settings:nilOrTrue("metric_length") and "mm" or "in")
|
||||
G_reader_settings:delSetting("metric_length")
|
||||
end
|
||||
end
|
||||
|
||||
-- We're done, store the current migration date
|
||||
G_reader_settings:saveSetting("last_migration_date", CURRENT_MIGRATION_DATE)
|
||||
|
||||
@@ -17,10 +17,7 @@ function optionsutil.enableIfEquals(configurable, option, value)
|
||||
return configurable[option] == value
|
||||
end
|
||||
|
||||
-- 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
|
||||
-- Converts flex px/pt sizes to absolute px, mm, inch or pt
|
||||
local function convertSizeTo(px, format)
|
||||
local format_factor
|
||||
|
||||
@@ -75,7 +72,7 @@ function optionsutil.showValues(configurable, option, prefix, document, unit)
|
||||
local value_default, value_current
|
||||
unit = unit or option.name_text_unit
|
||||
if unit and unit ~= "pt" then
|
||||
unit = G_reader_settings:nilOrTrue("metric_length") and "mm" or "in"
|
||||
unit = G_reader_settings:readSetting("dimension_units", "mm")
|
||||
end
|
||||
if option.toggle and option.values then
|
||||
-- build a table so we can see if current/default settings map
|
||||
@@ -180,7 +177,7 @@ 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"
|
||||
local unit = G_reader_settings:readSetting("dimension_units", "mm")
|
||||
if not default then
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = T(_([[
|
||||
|
||||
@@ -716,20 +716,15 @@ common_settings.keyboard_layout = {
|
||||
common_settings.font_ui_fallbacks = dofile("frontend/ui/elements/font_ui_fallbacks.lua")
|
||||
|
||||
common_settings.units = {
|
||||
text = _("Units"),
|
||||
text_func = function()
|
||||
local unit = G_reader_settings:readSetting("dimension_units", "mm")
|
||||
return T(_("Dimension units: %1"), unit)
|
||||
end,
|
||||
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,
|
||||
},
|
||||
},
|
||||
genGenericMenuEntry(_("Metric system"), "dimension_units", "mm", nil, true),
|
||||
genGenericMenuEntry(_("Imperial system"), "dimension_units", "in", nil, true),
|
||||
genGenericMenuEntry(_("Pixels"), "dimension_units", "px", nil, true),
|
||||
}
|
||||
}
|
||||
|
||||
common_settings.screenshot = {
|
||||
|
||||
Reference in New Issue
Block a user