From a857c46e6eb3d826ba06de0bd2479c40db5b1bf0 Mon Sep 17 00:00:00 2001 From: Gregor Parzefall <82708541+grorp@users.noreply.github.com> Date: Mon, 5 Jun 2023 12:01:54 +0200 Subject: [PATCH] Make the settings GUI more usable on Android (#13543) --- .luacheckrc | 1 + builtin/mainmenu/settings/dlg_settings.lua | 31 +++++++++++----------- src/script/cpp_api/s_base.cpp | 7 +++++ 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index a922bdea9..b048e41e4 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -70,6 +70,7 @@ files["builtin/mainmenu"] = { read_globals = { "PLATFORM", + "TOUCHSCREEN_GUI", }, } diff --git a/builtin/mainmenu/settings/dlg_settings.lua b/builtin/mainmenu/settings/dlg_settings.lua index 20d788fee..dc56e5767 100644 --- a/builtin/mainmenu/settings/dlg_settings.lua +++ b/builtin/mainmenu/settings/dlg_settings.lua @@ -110,12 +110,6 @@ add_page({ }) -local tabsize = { - width = 15.5, - height= 12, -} - - local function load_settingtypes() local page = nil local section = nil @@ -316,21 +310,26 @@ local function get_formspec(dialogdata) local page_id = dialogdata.page_id or "most_used" local page = filtered_page_by_id[page_id] - local scrollbar_w = 0.4 - if PLATFORM == "Android" then - scrollbar_w = 0.6 - end + local extra_h = 1 -- not included in tabsize.height + local tabsize = { + width = TOUCHSCREEN_GUI and 16.5 or 15.5, + height = TOUCHSCREEN_GUI and (10 - extra_h) or 12, + } - local left_pane_width = 4.25 + local scrollbar_w = TOUCHSCREEN_GUI and 0.6 or 0.4 + + local left_pane_width = TOUCHSCREEN_GUI and 4.5 or 4.25 local search_width = left_pane_width + scrollbar_w - (0.75 * 2) + local technical_names_w = TOUCHSCREEN_GUI and 6 or 5 local show_technical_names = core.settings:get_bool("show_technical_names") formspec_show_hack = not formspec_show_hack local fs = { "formspec_version[6]", - "size[", tostring(tabsize.width), ",", tostring(tabsize.height + 1), "]", + "size[", tostring(tabsize.width), ",", tostring(tabsize.height + extra_h), "]", + TOUCHSCREEN_GUI and "padding[0.01,0.01]" or "", "bgcolor[#0000]", -- HACK: this is needed to allow resubmitting the same formspec @@ -340,9 +339,11 @@ local function get_formspec(dialogdata) "button[0,", tostring(tabsize.height + 0.2), ";3,0.8;back;", fgettext("Back"), "]", - ("box[%f,%f;5,0.8;#0000008C]"):format(tabsize.width - 5, tabsize.height + 0.2), - "checkbox[", tostring(tabsize.width - 4.75), ",", tostring(tabsize.height + 0.6), ";show_technical_names;", - fgettext("Show technical names"), ";", tostring(show_technical_names), "]", + ("box[%f,%f;%f,0.8;#0000008C]"):format( + tabsize.width - technical_names_w, tabsize.height + 0.2, technical_names_w), + ("checkbox[%f,%f;show_technical_names;%s;%s]"):format( + tabsize.width - technical_names_w + 0.25, tabsize.height + 0.6, + fgettext("Show technical names"), tostring(show_technical_names)), "field[0.25,0.25;", tostring(search_width), ",0.75;search_query;;", core.formspec_escape(dialogdata.query or ""), "]", diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index c2b2f8a90..bb3e56502 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -153,6 +153,13 @@ ScriptApiBase::ScriptApiBase(ScriptingType type): lua_pushstring(m_luastack, porting::getPlatformName()); lua_setglobal(m_luastack, "PLATFORM"); +#ifdef HAVE_TOUCHSCREENGUI + lua_pushboolean(m_luastack, true); +#else + lua_pushboolean(m_luastack, false); +#endif + lua_setglobal(m_luastack, "TOUCHSCREEN_GUI"); + // Make sure Lua uses the right locale setlocale(LC_NUMERIC, "C"); }