Share settings page helpers, add GUI cursor/scale API

- move create_trackbar_setting/update_trackbar_label/create_checkbox from
  settings_audio/display/graphics pages to core:settings_common module
- GUI scale trackbar shows the really applied scale, e.g. '3 (effective 2)'
- add gui.get_scale(), gui.get_max_scale(), gui.get_cursor_pos() (UI units);
  document that input.get_mouse_pos() returns window pixels
- InventoryView default color is defined once (InventoryView::DEFAULT_COLOR)
  instead of duplicated literals; 'color' attribute still overrides it
This commit is contained in:
loki5512344 2026-10-03 13:12:30 +00:00
parent 851c1a0e27
commit 33e132a231
15 changed files with 173 additions and 123 deletions

View file

@ -1,39 +1,8 @@
function create_trackbar_setting(id, name, step, postfix, tooltip, changeonrelease)
local info = app.get_setting_info(id)
postfix = postfix or ""
tooltip = tooltip or ""
changeonrelease = changeonrelease or ""
document.root:add(gui.template("track_setting", {
id=id,
name=gui.str(name, "settings"),
value=app.get_setting(id),
min=info.min,
max=info.max,
step=step,
postfix=postfix,
tooltip=tooltip,
changeonrelease=changeonrelease
}))
update_trackbar_label(app.get_setting(id), id, name, postfix)
end
function update_trackbar_label(x, id, name, postfix)
-- updating label
document[id..".L"].text = string.format(
"%s: %s%s",
gui.str(name, "settings"),
app.str_setting(id),
postfix
)
end
function create_checkbox(id, name, tooltip)
tooltip = tooltip or ''
document.root:add(string.format(
"<checkbox consumer='function(x) app.set_setting(\"%s\", x) end' checked='%s' tooltip='%s'>%s</checkbox>",
id, app.str_setting(id), gui.str(tooltip, "settings"), gui.str(name, "settings")
))
end
local settings = require "core:settings_common".new(document, {})
-- 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
create_checkbox = settings.create_checkbox
function on_open()
create_trackbar_setting("chunks.load-distance", "Load Distance", 1)