Fractional GUI scale (0.5 step), fit menu to window, fix settings pages

- display.gui-scale is now a number: 0 (auto) or 0.5..4 in 0.5 steps
- explicit scale is no longer limited by window size (tiled windows);
  only an open menu page is shrunk to fit the window
- snap Batch2D vertices to pixels on fractional scale (fixes dots above text)
- pass app to settings_common via options (not visible inside modules)
- gui.get_scale() returns a number
This commit is contained in:
loki5512344 2026-10-03 15:28:03 +02:00
parent 33e132a231
commit 48d5d54b77
13 changed files with 76 additions and 41 deletions

View file

@ -1,4 +1,4 @@
local settings = require "core:settings_common".new(document, {})
local settings = require "core:settings_common".new(document, {app=app})
-- templates call these functions by name, so they must be global
create_trackbar_setting = settings.create_trackbar_setting
update_trackbar_label = settings.update_trackbar_label

View file

@ -10,20 +10,18 @@ tostring_overrides["display.framerate"] = function(x)
end
tostring_overrides["display.gui-scale"] = function(x)
-- scale is limited by the window size, show what is really applied
local effective = gui.get_max_scale()
if x > 0 then
effective = math.min(x, effective)
end
if x == 0 then
return string.format("%s (%d)", gui.str("Auto"), effective)
elseif effective < x then
return string.format("%d (%s %d)", x, gui.str("Effective"), effective)
return string.format("%s (%d)", gui.str("Auto"), gui.get_max_scale())
end
local effective = gui.get_scale()
if effective ~= x then
-- menu is limited by window size
return string.format("%s (%s %s)", tostring(x), gui.str("Effective"), tostring(effective))
end
return tostring(x)
end
local settings = require "core:settings_common".new(document, {tostring_overrides=tostring_overrides})
local settings = require "core:settings_common".new(document, {app=app, tostring_overrides=tostring_overrides})
-- templates call these functions by name, so they must be global
create_trackbar_setting = settings.create_trackbar_setting
update_trackbar_label = settings.update_trackbar_label
@ -32,7 +30,7 @@ create_checkbox = settings.create_checkbox
function on_open()
create_trackbar_setting("camera.fov", "FOV", 1, "°")
create_trackbar_setting("display.framerate", "Framerate", 1, "", "", true)
create_trackbar_setting("display.gui-scale", "GUI Scale", 1, "", "display.gui-scale.tooltip", true)
create_trackbar_setting("display.gui-scale", "GUI Scale", 0.5, "", "display.gui-scale.tooltip", true)
document.root:add(string.format(
"<select context='settings' onselect='function(opt) app.set_setting(\"display.window-mode\", tonumber(opt)) end' selected='%s'>"..

View file

@ -1,4 +1,4 @@
local settings = require "core:settings_common".new(document, {})
local settings = require "core:settings_common".new(document, {app=app})
-- templates call these functions by name, so they must be global
create_trackbar_setting = settings.create_trackbar_setting
update_trackbar_label = settings.update_trackbar_label

View file

@ -3,6 +3,7 @@
-- Usage in a page script:
--
-- local settings = require "core:settings_common".new(document, {
-- app = app,
-- tostring_overrides = {["display.framerate"] = function(x) ... end}
-- })
-- -- templates call these functions by name, so they must be global
@ -15,9 +16,11 @@ local settings_common = {}
--- Create helpers bound to the page document.
--- @param document the page document
--- @param options table (optional) with fields:
--- app: the page's `app` library (not visible inside modules)
--- tostring_overrides: {[setting_id] = function(value) -> string}
function settings_common.new(document, options)
options = options or {}
local app = options.app
local tostring_overrides = options.tostring_overrides or {}
local this = {}

View file

@ -43,7 +43,7 @@ pack.remove-confirm=Удалить весь поставляемый паком/
audio.acoustic-effects.tooltip=Акустические эффекты могут не поддерживаться системой
audio.volume-contrast.tooltip=Меньше - громкие звуки приглушаются до уровня тихих (ночной режим)
audio.recording-enabled.tooltip=Включает функции записи звука
display.gui-scale.tooltip=Размер интерфейса: Авто или 1-4. Слишком большой масштаб уменьшается под размер окна
display.gui-scale.tooltip=Размер интерфейса: Авто или 0.5-4. Меню уменьшается, если не помещается в окно
graphics.enable-fog.tooltip=Отображать туман / дымку
graphics.gamma.tooltip=Кривая яркости освещения
graphics.backlight.tooltip=Подсветка, предотвращающая полную темноту