2014-10-30 18:42:18 +00:00
local _ = require ( " gettext " )
2019-03-11 09:01:37 +00:00
local Device = require ( " device " )
local Screen = Device.screen
2018-12-08 17:11:55 +00:00
local T = require ( " ffi/util " ) . template
2014-10-30 18:42:18 +00:00
2019-03-11 09:01:37 +00:00
local function isAutoDPI ( ) return Device.screen_dpi_override == nil end
2019-02-19 15:40:03 +00:00
local function dpi ( ) return Screen : getDPI ( ) end
2014-10-30 18:42:18 +00:00
local function custom ( ) return G_reader_settings : readSetting ( " custom_screen_dpi " ) end
2016-06-27 16:43:23 +00:00
local function setDPI ( _dpi )
2014-10-30 18:42:18 +00:00
local InfoMessage = require ( " ui/widget/infomessage " )
local UIManager = require ( " ui/uimanager " )
UIManager : show ( InfoMessage : new {
2019-02-01 09:15:22 +00:00
text = _dpi and T ( _ ( " DPI set to %1. This will take effect after restarting. " ) , _dpi )
or _ ( " DPI set to auto. This will take effect after restarting. " ) ,
2014-10-30 18:42:18 +00:00
} )
2018-12-08 21:12:18 +00:00
G_reader_settings : saveSetting ( " screen_dpi " , _dpi )
2019-03-11 09:01:37 +00:00
Device : setScreenDPI ( _dpi )
2014-10-30 18:42:18 +00:00
end
2019-02-01 09:15:22 +00:00
local dpi_auto = Screen.device . screen_dpi
2018-12-08 21:12:18 +00:00
local dpi_small = 120
local dpi_medium = 160
local dpi_large = 240
local dpi_xlarge = 320
local dpi_xxlarge = 480
local dpi_xxxlarge = 640
2014-10-30 18:42:18 +00:00
return {
text = _ ( " Screen DPI " ) ,
sub_item_table = {
{
2019-02-01 09:15:22 +00:00
text = dpi_auto and T ( _ ( " Auto DPI (%1) " ) , dpi_auto ) or _ ( " Auto DPI " ) ,
2018-12-08 21:12:18 +00:00
help_text = _ ( " The DPI of your screen is automatically detected so items can be drawn with the right amount of pixels. This will usually display at (roughly) the same size on different devices, while remaining sharp. Increasing the DPI setting will result in larger text and icons, while a lower DPI setting will look smaller on the screen. " ) ,
2019-03-11 09:01:37 +00:00
checked_func = isAutoDPI ,
2014-10-30 18:42:18 +00:00
callback = function ( ) setDPI ( ) end
} ,
{
2018-12-08 21:12:18 +00:00
text = T ( _ ( " Small (%1) " ) , dpi_small ) ,
2014-10-30 18:42:18 +00:00
checked_func = function ( )
2019-03-11 09:01:37 +00:00
if isAutoDPI ( ) then return false end
2016-06-27 16:43:23 +00:00
local _dpi , _custom = dpi ( ) , custom ( )
return _dpi and _dpi <= 140 and _dpi ~= _custom
2014-10-30 18:42:18 +00:00
end ,
2018-12-08 21:12:18 +00:00
callback = function ( ) setDPI ( dpi_small ) end
2014-10-30 18:42:18 +00:00
} ,
{
2018-12-08 21:12:18 +00:00
text = T ( _ ( " Medium (%1) " ) , dpi_medium ) ,
2014-10-30 18:42:18 +00:00
checked_func = function ( )
2019-03-11 09:01:37 +00:00
if isAutoDPI ( ) then return false end
2016-06-27 16:43:23 +00:00
local _dpi , _custom = dpi ( ) , custom ( )
return _dpi and _dpi > 140 and _dpi <= 200 and _dpi ~= _custom
2014-10-30 18:42:18 +00:00
end ,
2018-12-08 21:12:18 +00:00
callback = function ( ) setDPI ( dpi_medium ) end
2014-10-30 18:42:18 +00:00
} ,
{
2018-12-08 21:12:18 +00:00
text = T ( _ ( " Large (%1) " ) , dpi_large ) ,
2014-10-30 18:42:18 +00:00
checked_func = function ( )
2019-03-11 09:01:37 +00:00
if isAutoDPI ( ) then return false end
2016-06-27 16:43:23 +00:00
local _dpi , _custom = dpi ( ) , custom ( )
2018-12-08 21:12:18 +00:00
return _dpi and _dpi > 200 and _dpi <= 280 and _dpi ~= _custom
2014-10-30 18:42:18 +00:00
end ,
2018-12-08 21:12:18 +00:00
callback = function ( ) setDPI ( dpi_large ) end
2014-10-30 18:42:18 +00:00
} ,
{
2018-12-08 21:12:18 +00:00
text = T ( _ ( " Extra large (%1) " ) , dpi_xlarge ) ,
checked_func = function ( )
2019-03-11 09:01:37 +00:00
if isAutoDPI ( ) then return false end
2018-12-08 21:12:18 +00:00
local _dpi , _custom = dpi ( ) , custom ( )
return _dpi and _dpi > 280 and _dpi <= 400 and _dpi ~= _custom
end ,
callback = function ( ) setDPI ( dpi_xlarge ) end
} ,
{
text = T ( _ ( " Extra-Extra Large (%1) " ) , dpi_xxlarge ) ,
checked_func = function ( )
2019-03-11 09:01:37 +00:00
if isAutoDPI ( ) then return false end
2018-12-08 21:12:18 +00:00
local _dpi , _custom = dpi ( ) , custom ( )
return _dpi and _dpi > 400 and _dpi <= 560 and _dpi ~= _custom
end ,
callback = function ( ) setDPI ( dpi_xxlarge ) end
} ,
{
text = T ( _ ( " Extra-Extra-Extra Large (%1) " ) , dpi_xxxlarge ) ,
checked_func = function ( )
2019-03-11 09:01:37 +00:00
if isAutoDPI ( ) then return false end
2018-12-08 21:12:18 +00:00
local _dpi , _custom = dpi ( ) , custom ( )
return _dpi and _dpi > 560 and _dpi ~= _custom
end ,
callback = function ( ) setDPI ( dpi_xxxlarge ) end
} ,
{
text_func = function ( )
return T ( _ ( " Custom DPI: %1 (hold to set) " ) , custom ( ) or dpi_auto )
end ,
2014-10-30 18:42:18 +00:00
checked_func = function ( )
2019-03-11 09:01:37 +00:00
if isAutoDPI ( ) then return false end
2016-06-27 16:43:23 +00:00
local _dpi , _custom = dpi ( ) , custom ( )
return _custom and _dpi == _custom
2014-10-30 18:42:18 +00:00
end ,
2018-12-08 21:12:18 +00:00
callback = function ( ) setDPI ( custom ( ) or dpi_auto ) end ,
2014-10-30 18:42:18 +00:00
hold_input = {
2018-12-08 17:11:55 +00:00
title = _ ( " Enter custom screen DPI " ) ,
2014-10-30 18:42:18 +00:00
type = " number " ,
2018-12-08 17:11:55 +00:00
hint = " (90 - 900) " ,
2014-10-30 18:42:18 +00:00
callback = function ( input )
2016-06-27 16:43:23 +00:00
local _dpi = tonumber ( input )
_dpi = _dpi < 90 and 90 or _dpi
2018-12-08 17:11:55 +00:00
_dpi = _dpi > 900 and 900 or _dpi
2016-06-27 16:43:23 +00:00
G_reader_settings : saveSetting ( " custom_screen_dpi " , _dpi )
setDPI ( _dpi )
2014-10-30 18:42:18 +00:00
end ,
2018-12-08 17:11:55 +00:00
ok_text = _ ( " Set custom DPI " ) ,
2014-10-30 18:42:18 +00:00
} ,
} ,
}
}