From 3cf9c06ae4daefe32b27a64af3e579f11cfa60d2 Mon Sep 17 00:00:00 2001 From: luk3yx Date: Wed, 22 Jun 2022 18:00:28 +1200 Subject: [PATCH] Mobile: don't stretch formspec to entire screen if it has a tabheader (#62) --- src/gui/guiFormSpecMenu.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index ca92e8566..da7478c68 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -3289,6 +3289,23 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) mydata.screensize.X, mydata.screensize.Y ); + + // Try and find a tabheader[] element in the formspec + for (unsigned int j = i; j < elements.size(); j++) { + // This could use split() but since we don't parse parameters + // here it's probably faster to use find(). + const size_t pos = elements[j].find('['); + if (pos == std::string::npos) + continue; + + // If we find a tabheader then decrease padded_screensize.Y and + // stop searching through the formspec. + const std::string element_type = trim(elements[j].substr(0, pos)); + if (element_type == "tabheader") { + padded_screensize.Y *= 0.9f; + break; + } + } #else // Pad the screensize with 5% of the screensize on all sides to ensure // that even the largest formspecs don't touch the screen borders.