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
5SubElement := Rectangle {
6 property text <=> input.text;
7 property <bool> has-focus: input.has-focus;
8 forward_focus: input;
9 input := TextInput {
10 width: 100%;
11 height: 100%;
12 }
13}
14
15TestCase := Rectangle {
16 width: 400phx;
17 height: 400phx;
18
19 callback focus_input1();
20 focus_input1 => { input1.focus(); }
21
22 callback focus_input2();
23 focus_input2 => { input2.focus(); }
24
25 Rectangle {
26 input1 := TextInput {
27 width: parent.width;
28 height: 200phx;
29 }
30 }
31
32 input2 := SubElement {
33 y: 200phx;
34 width: parent.width;
35 height: 200phx;
36 }
37
38 if (false) : SubElement { }
39
40 property<bool> input1_focused: input1.has_focus;
41 property<string> input1_text: input1.text;
42 property<bool> input2_focused: input2.has_focus;
43 property<string> input2_text: input2.text;
44}
45
46/*
47```rust
48let instance = TestCase::new().unwrap();
49assert!(!instance.get_input1_focused());
50assert!(!instance.get_input2_focused());
51
52instance.invoke_focus_input1();
53assert!(instance.get_input1_focused());
54assert!(!instance.get_input2_focused());
55
56instance.invoke_focus_input2();
57assert!(!instance.get_input1_focused());
58assert!(instance.get_input2_focused());
59```
60
61```cpp
62auto handle = TestCase::create();
63const TestCase &instance = *handle;
64assert(!instance.get_input1_focused());
65assert(!instance.get_input2_focused());
66
67instance.invoke_focus_input1();
68assert(instance.get_input1_focused());
69assert(!instance.get_input2_focused());
70
71instance.invoke_focus_input2();
72assert(!instance.get_input1_focused());
73assert(instance.get_input2_focused());
74```
75
76```js
77var instance = new slint.TestCase();
78assert(!instance.input1_focused);
79assert(!instance.input2_focused);
80
81instance.focus_input1();
82assert(instance.input1_focused);
83assert(!instance.input2_focused);
84
85instance.focus_input2();
86assert(!instance.input1_focused);
87assert(instance.input2_focused);
88```
89*/
90}
91
92#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
93 use i_slint_backend_testing as slint_testing;
94 slint_testing::init();
95 let instance = TestCase::new().unwrap();
96 assert!(!instance.get_input1_focused());
97 assert!(!instance.get_input2_focused());
98
99 instance.invoke_focus_input1();
100 assert!(instance.get_input1_focused());
101 assert!(!instance.get_input2_focused());
102
103 instance.invoke_focus_input2();
104 assert!(!instance.get_input1_focused());
105 assert!(instance.get_input2_focused());
106 Ok(())
107}