From 2f71bd70f134d4072527f73a197339dd9d1f95ff Mon Sep 17 00:00:00 2001 From: Weyoune Date: Sat, 14 Nov 2026 10:14:54 +0100 Subject: [PATCH] Zoom menu windows to the screen and add a text size audit to the UI script driver A menu window is shown as large as the screen allows instead of at the scale of the whole 3840 x 2160 stage (about 15 % larger on a 16:10 laptop). The script command text-audit lists every visible text with its drawn size and whether its box is too narrow. Co-Authored-By: Claude Fable 5.2 --- src/modern/ui/controls.inc | 27 +++++++++++++++++++++++++++ src/modern/ui/engine_screens.inc | 1 + src/modern/ui/view.cpp | 13 +++++++++++++ 3 files changed, 41 insertions(+) diff --git a/src/modern/ui/controls.inc b/src/modern/ui/controls.inc index ddbc983..d6fc36b 100644 --- a/src/modern/ui/controls.inc +++ b/src/modern/ui/controls.inc @@ -1031,6 +1031,33 @@ void App::script() { for(const auto &selector:command.at("selectors")){Rml::ElementList nodes;doc_->QuerySelectorAll(nodes,selector.get());for(auto *node:nodes){auto at=node->GetAbsoluteOffset(Rml::BoxArea::Border),size=node->GetBox().GetSize(Rml::BoxArea::Border);rows.push_back({{"selector",selector},{"id",node->GetId()},{"x",at.x},{"y",at.y},{"width",size.x},{"height",size.y},{"scroll_top",node->GetScrollTop()},{"scroll_height",node->GetScrollHeight()},{"client_height",node->GetClientHeight()},{"font_size",node->GetComputedValues().font_size()},{"rml",node->GetInnerRML()},{"visible",node->IsVisible(true)}});}} editor::write_atomic(editor::path(command.at("path").get()),rows.dump(2)); } + else if (type == "text-audit") { + // Readability check: every visible text with the size it is drawn at (in screen + // pixels) and whether its box is too narrow for it. + context_->Update(); + Json rows = Json::array(); + const auto dimensions = context_->GetDimensions(); + std::function walk = [&](Rml::Element *node) { + if (!node->IsVisible(true)) return; + std::string text; + for (int i = 0; i < node->GetNumChildren(); ++i) + if (auto *part = dynamic_cast(node->GetChild(i))) text += part->GetText(); + const auto first = text.find_first_not_of(" \t\r\n"), last = text.find_last_not_of(" \t\r\n"); + if (first != std::string::npos) { + const auto box = node->GetAbsoluteOffset(Rml::BoxArea::Border); + const auto size = node->GetBox().GetSize(Rml::BoxArea::Border); + // only what is on the screen counts + if (box.x + size.x > 0 && box.y + size.y > 0 && box.x < float(dimensions.x) && box.y < float(dimensions.y)) + rows.push_back({{"px", node->GetComputedValues().font_size()}, {"text", text.substr(first, std::min(last - first + 1, 70))}, + {"id", node->GetId()}, {"class", node->GetClassNames()}, {"tag", node->GetTagName()}, + {"overflow", node->GetScrollWidth() > node->GetClientWidth() + 1.5f}}); + } + for (int i = 0; i < node->GetNumChildren(); ++i) walk(node->GetChild(i)); + }; + walk(doc_); + editor::write_atomic(editor::path(command.at("path").get()), + Json{{"scene", scene_}, {"menu", menu_}, {"scale", scale_}, {"width", dimensions.x}, {"height", dimensions.y}, {"texts", rows}}.dump(1)); + } else if (type == "dom") editor::write_atomic( editor::path(command.at("path").get()), diff --git a/src/modern/ui/engine_screens.inc b/src/modern/ui/engine_screens.inc index 8518d03..be1430a 100644 --- a/src/modern/ui/engine_screens.inc +++ b/src/modern/ui/engine_screens.inc @@ -175,6 +175,7 @@ void App::engine_render() { setting_menu_markup_ = true; element("canvas")->SetInnerRML(out); ++document_generation_; setting_menu_markup_ = false; + sync_window_zoom(); live_detail_pending_ = live_ticker_pending_ = false; scale_chalk_shadow(); if (!engine_player_.empty()) { diff --git a/src/modern/ui/view.cpp b/src/modern/ui/view.cpp index ec9f43b..153afb8 100644 --- a/src/modern/ui/view.cpp +++ b/src/modern/ui/view.cpp @@ -48,6 +48,7 @@ #include "modern/ui/view.hpp" #include "version.hpp" #include +#include #include #include #include @@ -375,6 +376,9 @@ class App final : public Rml::EventListener { bool initialized_ = false, closed_ = false, dirty_ = true, needs_render_ = true; double scale_ = 1, canvas_left_ = 0, canvas_top_ = 0; + // A menu window (2720 x 2040 at the middle of the stage) is shown as large as the screen + // allows; the desk behind it is cropped. Without a window the whole stage is fitted. + bool window_zoom_ = false; std::string scene_ = "main", menu_, theme_ = "midnight", active_mod_, selected_mod_, notice_, country_ = "nation:de", league_, selected_club_; @@ -874,6 +878,13 @@ class App final : public Rml::EventListener { "shadow(" + offset + "px " + offset + "px #386824)"); } } + // Called after the stage was rebuilt: zoom in when it now shows a menu window. + void sync_window_zoom() { + const bool wanted = doc_->QuerySelector(".window") != nullptr; + if (wanted == window_zoom_) return; + window_zoom_ = wanted; + resize(); + } void resize() { int w, h, pw, ph; SDL_GetWindowSize(video_.window, &w, &h); @@ -881,6 +892,7 @@ class App final : public Rml::EventListener { if (w <= 0 || h <= 0 || pw <= 0 || ph <= 0) return; scale_ = std::min(double(pw) / 3840, double(ph) / 2160); + if (window_zoom_) scale_ = std::max(scale_, std::min(double(pw) / 2760, double(ph) / 2080)); canvas_left_ = (pw - 3840 * scale_) / 2; canvas_top_ = (ph - 2160 * scale_) / 2; device_ratio_ = float(pw) / w; @@ -994,6 +1006,7 @@ class App final : public Rml::EventListener { setting_menu_markup_ = true; element("canvas")->SetInnerRML(markup); ++document_generation_; + sync_window_zoom(); live_detail_pending_ = live_ticker_pending_ = false; element("canvas")->SetProperty("overflow", statistics_trophy_.contains("asset") ? "visible" : "hidden"); setting_menu_markup_ = false;