From d3e02d05c62bcbbe5492c4d37a27aa585a19742e Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 3 Aug 2019 16:45:17 +0200 Subject: [PATCH] Fix: set custom screen DPI (#5165) Settings -> Screen -> Screen DPI When custom DPI is not set we see ugly information with %1: --- .../ui/elements/screen_dpi_menu_table.lua | 52 +++++++++++++------ 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/frontend/ui/elements/screen_dpi_menu_table.lua b/frontend/ui/elements/screen_dpi_menu_table.lua index 001a48233..f622c308a 100644 --- a/frontend/ui/elements/screen_dpi_menu_table.lua +++ b/frontend/ui/elements/screen_dpi_menu_table.lua @@ -20,6 +20,27 @@ local function setDPI(_dpi) Device:setScreenDPI(_dpi) end +local function spinWidgetSetDPI(touchmenu_instance) + local SpinWidget = require("ui/widget/spinwidget") + local UIManager = require("ui/uimanager") + local items = SpinWidget:new{ + width = Screen:getWidth() * 0.6, + value = custom() or dpi(), + value_min = 90, + value_max = 900, + value_step = 10, + value_hold_step = 50, + ok_text = _("Set DPI"), + title_text = _("Set custom screen DPI"), + callback = function(spin) + G_reader_settings:saveSetting("custom_screen_dpi", spin.value) + setDPI(spin.value) + touchmenu_instance:updateItems() + end + } + UIManager:show(items) +end + local dpi_auto = Screen.device.screen_dpi local dpi_small = 120 local dpi_medium = 160 @@ -93,27 +114,28 @@ return { }, { text_func = function() - return T(_("Custom DPI: %1 (hold to set)"), custom() or dpi_auto) + local custom_dpi = custom() or dpi_auto + if custom_dpi then + return T(_("Custom DPI: %1 (hold to set)"), custom() or dpi_auto) + else + return _("Custom DPI") + end end, checked_func = function() if isAutoDPI() then return false end local _dpi, _custom = dpi(), custom() return _custom and _dpi == _custom end, - callback = function() setDPI(custom() or dpi_auto) end, - hold_input = { - title = _("Enter custom screen DPI"), - type = "number", - hint = "(90 - 900)", - callback = function(input) - local _dpi = tonumber(input) - _dpi = _dpi < 90 and 90 or _dpi - _dpi = _dpi > 900 and 900 or _dpi - G_reader_settings:saveSetting("custom_screen_dpi", _dpi) - setDPI(_dpi) - end, - ok_text = _("Set custom DPI"), - }, + callback = function(touchmenu_instance) + if custom() then + setDPI(custom() or dpi_auto) + else + spinWidgetSetDPI(touchmenu_instance) + end + end, + hold_callback = function(touchmenu_instance) + spinWidgetSetDPI(touchmenu_instance) + end, }, } }