Map QA selector input through public RmlUI projection (by Codex)

This commit is contained in:
Codex authored and Codex committed 2026-10-27 07:30:46 +01:00
1 parent d8beaecd6f
commit 9061123c7e
6 files changed
+169 -3

No files matched your search

+66
View File
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
// Exercise the production control builder and stylesheet with synthetic labels.
#include "modern/ui/controls.hpp"
#include "modern/ui/script_locator.hpp"
#include <RmlUi/Core/ElementText.h>
#include <RmlUi/Core/Elements/ElementFormControlSelect.h>
#include <RmlUi/Core/FontEngineInterface.h>
@@ -89,6 +90,69 @@ size_t visible_text_lines(Rml::Element &node) {
count += visible_text_lines(*node.GetChild(i));
return count;
}
struct ClickListener final : Rml::EventListener {
int clicks = 0;
void ProcessEvent(Rml::Event &event) override {
if (event.GetType() == "click")
++clicks;
}
};
void script_locator_cases(Rml::Context &context, float density) {
struct Case {
const char *transform;
Rml::Vector2f expected;
bool blocked;
};
for (const auto &test :
{Case{"none", {700, 730}, false},
Case{"translate(70dp,-160dp)", {770, 570}, false},
Case{"scale(1.5)", {800, 795}, false},
Case{"rotate(90deg)", {370, 800}, false}, Case{"scale(0)", {}, true},
Case{"none", {}, true}}) {
const bool covered = test.blocked && std::string(test.transform) == "none";
auto *doc = context.LoadDocumentFromMemory(
"<rml><head><style>body{margin:0;font-family:Modern;font-size:20dp;}"
"#parent{position:absolute;left:500dp;top:600dp;width:600dp;height:"
"300dp;transform-origin:0 0;transform:" +
std::string(test.transform) +
";}"
"#target{position:absolute;left:100dp;top:80dp;width:200dp;height:"
"100dp;margin:0;padding:0;border:0;}"
"#label{position:absolute;left:0;right:0;top:0;bottom:0;}"
"#cover{position:absolute;left:500dp;top:600dp;width:600dp;height:"
"300dp;z-index:999;}"
"</style></head><body><div id='parent'><button id='target'><span "
"id='label'>Click</span></button></div>" +
(covered ? std::string("<div id='cover'></div>") : std::string()) +
"</body></rml>");
require(doc, "Script locator document missing");
doc->Show();
context.Update();
context.Render();
auto *target = doc->GetElementById("target");
const auto point = script_click_point(context, *target);
if (test.blocked)
require(!point,
"Singular/covered locator silently clicks another element");
else {
require(bool(point),
"Transformed script locator rejected visible control");
require(std::abs(point->x - test.expected.x * density) <= 1.f &&
std::abs(point->y - test.expected.y * density) <= 1.f,
"Script locator did not map the visible transformed center");
ClickListener listener;
target->AddEventListener("click", &listener);
context.ProcessMouseMove(point->x, point->y, 0);
context.ProcessMouseButtonDown(0, 0);
context.ProcessMouseButtonUp(0, 0);
require(listener.clicks == 1,
"Script locator point did not click requested control");
target->RemoveEventListener("click", &listener);
}
doc->Close();
context.Update();
}
}
} // namespace
int main(int argc, char **argv) try {
require(argc == 2, "Pass the Modern asset directory");
@@ -266,6 +330,8 @@ int main(int argc, char **argv) try {
context->Update();
}
doc->Close();
context->Update();
script_locator_cases(*context,density);
Rml::RemoveContext("controls");
}
Rml::Shutdown();