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 <noreply@anthropic.com>
This commit is contained in:
1 parent
1de09ba8a6
commit
2f71bd70f1
3 files changed
+41
No files matched your search
@@ -1031,6 +1031,33 @@ void App::script() {
|
|||||||
for(const auto &selector:command.at("selectors")){Rml::ElementList nodes;doc_->QuerySelectorAll(nodes,selector.get<std::string>());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)}});}}
|
for(const auto &selector:command.at("selectors")){Rml::ElementList nodes;doc_->QuerySelectorAll(nodes,selector.get<std::string>());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<std::string>()),rows.dump(2));
|
editor::write_atomic(editor::path(command.at("path").get<std::string>()),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<void(Rml::Element *)> 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<Rml::ElementText *>(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<size_t>(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<std::string>()),
|
||||||
|
Json{{"scene", scene_}, {"menu", menu_}, {"scale", scale_}, {"width", dimensions.x}, {"height", dimensions.y}, {"texts", rows}}.dump(1));
|
||||||
|
}
|
||||||
else if (type == "dom")
|
else if (type == "dom")
|
||||||
editor::write_atomic(
|
editor::write_atomic(
|
||||||
editor::path(command.at("path").get<std::string>()),
|
editor::path(command.at("path").get<std::string>()),
|
||||||
|
|||||||
@@ -175,6 +175,7 @@ void App::engine_render() {
|
|||||||
setting_menu_markup_ = true;
|
setting_menu_markup_ = true;
|
||||||
element("canvas")->SetInnerRML(out); ++document_generation_;
|
element("canvas")->SetInnerRML(out); ++document_generation_;
|
||||||
setting_menu_markup_ = false;
|
setting_menu_markup_ = false;
|
||||||
|
sync_window_zoom();
|
||||||
live_detail_pending_ = live_ticker_pending_ = false;
|
live_detail_pending_ = live_ticker_pending_ = false;
|
||||||
scale_chalk_shadow();
|
scale_chalk_shadow();
|
||||||
if (!engine_player_.empty()) {
|
if (!engine_player_.empty()) {
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
#include "modern/ui/view.hpp"
|
#include "modern/ui/view.hpp"
|
||||||
#include "version.hpp"
|
#include "version.hpp"
|
||||||
#include <RmlUi/Core.h>
|
#include <RmlUi/Core.h>
|
||||||
|
#include <RmlUi/Core/ElementText.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -375,6 +376,9 @@ class App final : public Rml::EventListener {
|
|||||||
bool initialized_ = false, closed_ = false, dirty_ = true,
|
bool initialized_ = false, closed_ = false, dirty_ = true,
|
||||||
needs_render_ = true;
|
needs_render_ = true;
|
||||||
double scale_ = 1, canvas_left_ = 0, canvas_top_ = 0;
|
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_,
|
std::string scene_ = "main", menu_, theme_ = "midnight", active_mod_,
|
||||||
selected_mod_, notice_, country_ = "nation:de", league_,
|
selected_mod_, notice_, country_ = "nation:de", league_,
|
||||||
selected_club_;
|
selected_club_;
|
||||||
@@ -874,6 +878,13 @@ class App final : public Rml::EventListener {
|
|||||||
"shadow(" + offset + "px " + offset + "px #386824)");
|
"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() {
|
void resize() {
|
||||||
int w, h, pw, ph;
|
int w, h, pw, ph;
|
||||||
SDL_GetWindowSize(video_.window, &w, &h);
|
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)
|
if (w <= 0 || h <= 0 || pw <= 0 || ph <= 0)
|
||||||
return;
|
return;
|
||||||
scale_ = std::min(double(pw) / 3840, double(ph) / 2160);
|
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_left_ = (pw - 3840 * scale_) / 2;
|
||||||
canvas_top_ = (ph - 2160 * scale_) / 2;
|
canvas_top_ = (ph - 2160 * scale_) / 2;
|
||||||
device_ratio_ = float(pw) / w;
|
device_ratio_ = float(pw) / w;
|
||||||
@@ -994,6 +1006,7 @@ class App final : public Rml::EventListener {
|
|||||||
setting_menu_markup_ = true;
|
setting_menu_markup_ = true;
|
||||||
element("canvas")->SetInnerRML(markup);
|
element("canvas")->SetInnerRML(markup);
|
||||||
++document_generation_;
|
++document_generation_;
|
||||||
|
sync_window_zoom();
|
||||||
live_detail_pending_ = live_ticker_pending_ = false;
|
live_detail_pending_ = live_ticker_pending_ = false;
|
||||||
element("canvas")->SetProperty("overflow", statistics_trophy_.contains("asset") ? "visible" : "hidden");
|
element("canvas")->SetProperty("overflow", statistics_trophy_.contains("asset") ? "visible" : "hidden");
|
||||||
setting_menu_markup_ = false;
|
setting_menu_markup_ = false;
|
||||||
|
|||||||
Reference in new issue
Block a user