mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +00:00
Allow to simulate key event with the interpreter (C++)
This commit is contained in:
parent
7f9bb18b9a
commit
7b63bb7d65
2 changed files with 41 additions and 1 deletions
|
@ -836,3 +836,18 @@ public:
|
|||
};
|
||||
|
||||
}
|
||||
|
||||
namespace sixtyfps::testing {
|
||||
/// Send a key events to the given component instance
|
||||
inline void send_keyboard_string_sequence(const sixtyfps::interpreter::ComponentInstance *component,
|
||||
const sixtyfps::SharedString &str,
|
||||
KeyboardModifiers modifiers = {})
|
||||
{
|
||||
cbindgen_private::ComponentWindowOpaque win;
|
||||
cbindgen_private::sixtyfps_interpreter_component_instance_window(
|
||||
reinterpret_cast<const cbindgen_private::ErasedComponentBox *>(component), &win);
|
||||
cbindgen_private::send_keyboard_string_sequence(
|
||||
&str, modifiers, reinterpret_cast<cbindgen_private::ComponentWindow *>(&win));
|
||||
cbindgen_private::sixtyfps_component_window_drop(&win);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -417,4 +417,29 @@ SCENARIO("Component Definition Name")
|
|||
ComponentCompiler compiler;
|
||||
auto comp_def = *compiler.build_from_source("export IHaveAName := Rectangle { }", "");
|
||||
REQUIRE(comp_def.name() == "IHaveAName");
|
||||
}
|
||||
}
|
||||
|
||||
SCENARIO("Send key events")
|
||||
{
|
||||
using namespace sixtyfps::interpreter;
|
||||
using namespace sixtyfps;
|
||||
|
||||
ComponentCompiler compiler;
|
||||
auto comp_def = compiler.build_from_source(R"(
|
||||
export Dummy := Rectangle {
|
||||
forward-focus: scope;
|
||||
property <string> result;
|
||||
scope := FocusScope {
|
||||
key-pressed(event) => {
|
||||
result += event.text;
|
||||
return accept;
|
||||
}
|
||||
}
|
||||
}
|
||||
)",
|
||||
"");
|
||||
REQUIRE(comp_def.has_value());
|
||||
auto instance = comp_def->create();
|
||||
sixtyfps::testing::send_keyboard_string_sequence(&*instance, "Hello keys!", {});
|
||||
REQUIRE(*instance->get_property("result")->to_string() == "Hello keys!");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue