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:
MichaelandClaude Fable 5.2 committed 2026-11-14 10:14:54 +01:00
1 parent 1de09ba8a6
commit 2f71bd70f1
3 files changed
+41

No files matched your search

+27
View File
@@ -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)}});}}
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")
editor::write_atomic(
editor::path(command.at("path").get<std::string>()),