mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-22 08:12:48 +00:00
85 lines
2.6 KiB
Text
85 lines
2.6 KiB
Text
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
|
|
|
// FIXME: Skip embedding test on C++ and NodeJS since ComponentFactory is not
|
|
// implemented there!
|
|
//ignore: cpp,js
|
|
|
|
import { Button } from "std-widgets.slint";
|
|
|
|
export component TestCase inherits Rectangle {
|
|
cont1 := ComponentContainer { }
|
|
|
|
cont2 := ComponentContainer { }
|
|
|
|
outside := Button { text: "Outside button"; }
|
|
|
|
in property<component-factory> c1 <=> cont1.component-factory;
|
|
in property<component-factory> c2 <=> cont2.component-factory;
|
|
out property<bool> outside-focus <=> outside.has-focus;
|
|
|
|
|
|
private property <component-factory> some-factory;
|
|
ComponentContainer { component-factory: some-factory; }
|
|
out property <bool> test: some-factory == some-factory;
|
|
}
|
|
|
|
/*
|
|
```cpp
|
|
// ComponentFactory not supported yet!
|
|
```
|
|
|
|
```rust
|
|
let factory = slint::ComponentFactory::new(|ctx| {
|
|
|
|
let compiler = slint_interpreter::Compiler::new();
|
|
let e = spin_on::spin_on(compiler.build_from_source(
|
|
r#"import { Button } from "std-widgets.slint";
|
|
|
|
export component E1 inherits Rectangle {
|
|
background: Colors.red;
|
|
forward-focus: b;
|
|
b := Button {
|
|
text: "red";
|
|
}
|
|
}"#.into(),
|
|
std::path::PathBuf::from("embedded.slint"),
|
|
)).component("E1").unwrap();
|
|
e.create_embedded(ctx).ok()
|
|
});
|
|
|
|
let instance = TestCase::new().unwrap();
|
|
assert!(!instance.get_outside_focus()); // Nothing has focus be default
|
|
slint_testing::send_keyboard_string_sequence(&instance, "\t");
|
|
assert!(instance.get_outside_focus()); // The outside button is the only thing
|
|
// accepting focus at this point.
|
|
|
|
instance.set_c1(factory.clone());
|
|
instance.set_c2(factory);
|
|
|
|
assert!(instance.get_outside_focus()); // embedding does not move the focus
|
|
|
|
// focus the two embedded buttons:
|
|
slint_testing::send_keyboard_string_sequence(&instance, "\t");
|
|
assert!(!instance.get_outside_focus());
|
|
slint_testing::send_keyboard_string_sequence(&instance, "\t");
|
|
assert!(!instance.get_outside_focus());
|
|
|
|
// Go back to outside button
|
|
slint_testing::send_keyboard_string_sequence(&instance, "\t");
|
|
assert!(instance.get_outside_focus());
|
|
|
|
// Focus backwards over the embedded buttons
|
|
slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}");
|
|
assert!(!instance.get_outside_focus());
|
|
slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}");
|
|
assert!(!instance.get_outside_focus());
|
|
|
|
slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}");
|
|
assert!(instance.get_outside_focus());
|
|
```
|
|
|
|
```js
|
|
var _instance = new slint.TestCase();
|
|
```
|
|
*/
|