1#![allow(deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/focus"#]
2// Copyright © SixtyFPS GmbH <info@slint.dev>
3// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
4
5TestCase := Window {
6 width: 100phx;
7 height: 100phx;
8 FocusScope {
9 key-pressed(event) => {
10 r1 += event.text;
11 return event.text == "a" ? accept : reject;
12 }
13
14 FocusScope {
15 key-pressed(event) => {
16 r2 += event.text;
17 return event.text == "b" ? accept : reject;
18 }
19 Rectangle {
20 FocusScope {
21 key-pressed(event) => {
22 r3 += event.text;
23 return event.text == "c" ? accept : reject;
24 }
25
26 if (toggle) : FocusScope {
27 key-pressed(event) => {
28 r4 += event.text;
29 return event.text == "d" ? accept : reject;
30 }
31 FocusScope {
32 key-pressed(event) => {
33 r5 += event.text;
34 return event.text == "e" ? accept : reject;
35 }
36 TouchArea {
37 clicked => {
38 parent.focus();
39 }
40 }
41 }
42 }
43 }
44 }
45 }
46 }
47
48 property<bool> toggle: true;
49 property<string> r1;
50 property<string> r2;
51 property<string> r3;
52 property<string> r4;
53 property<string> r5;
54}
55
56/*
57```rust
58let instance = TestCase::new().unwrap();
59slint_testing::send_mouse_click(&instance, 50., 50.);
60slint_testing::send_keyboard_string_sequence(&instance, "__abcdefghij__");
61assert_eq!(instance.get_r1(), "__afghij__");
62assert_eq!(instance.get_r2(), "__abfghij__");
63assert_eq!(instance.get_r3(), "__abcfghij__");
64assert_eq!(instance.get_r4(), "__abcdfghij__");
65assert_eq!(instance.get_r5(), "__abcdefghij__");
66```
67
68```cpp
69auto handle = TestCase::create();
70const TestCase &instance = *handle;
71slint_testing::send_mouse_click(&instance, 50., 50.);
72slint_testing::send_keyboard_string_sequence(&instance, "__abcdefghij__");
73assert_eq(instance.get_r1(), "__afghij__");
74assert_eq(instance.get_r2(), "__abfghij__");
75assert_eq(instance.get_r3(), "__abcfghij__");
76assert_eq(instance.get_r4(), "__abcdfghij__");
77assert_eq(instance.get_r5(), "__abcdefghij__");
78```
79
80```js
81var instance = new slint.TestCase();
82slintlib.private_api.send_mouse_click(instance, 50., 50.);
83slintlib.private_api.send_keyboard_string_sequence(instance, "__abcdefghij__");
84assert.equal(instance.r1, "__afghij__");
85assert.equal(instance.r2, "__abfghij__");
86assert.equal(instance.r3, "__abcfghij__");
87assert.equal(instance.r4, "__abcdfghij__");
88assert.equal(instance.r5, "__abcdefghij__");
89
90```
91*/
92}
93
94#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
95 use i_slint_backend_testing as slint_testing;
96 slint_testing::init();
97 let instance = TestCase::new().unwrap();
98 slint_testing::send_mouse_click(&instance, x:50., y:50.);
99 slint_testing::send_keyboard_string_sequence(&instance, sequence:"__abcdefghij__");
100 assert_eq!(instance.get_r1(), "__afghij__");
101 assert_eq!(instance.get_r2(), "__abfghij__");
102 assert_eq!(instance.get_r3(), "__abcfghij__");
103 assert_eq!(instance.get_r4(), "__abcdfghij__");
104 assert_eq!(instance.get_r5(), "__abcdefghij__");
105 Ok(())
106}