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
5import { LineEdit } from "std-widgets.slint";
6
7export component TestCase inherits Window {
8
9 callback focus_the_line_edit;
10 focus_the_line_edit => {
11 le.focus();
12 }
13 callback focus_the_focus_scope;
14 focus_the_focus_scope => {
15 fs.focus();
16 }
17
18 callback set_manual(bool);
19 set_manual(v) => {
20 TextInputInterface.text-input-focused = v;
21 }
22
23 le := LineEdit { }
24 fs := FocusScope { }
25
26 out property<bool> focused: TextInputInterface.text-input-focused;
27
28}
29
30/*
31```rust
32let instance = TestCase::new().unwrap();
33assert!(!instance.get_focused());
34instance.invoke_focus_the_line_edit();
35assert!(instance.get_focused());
36instance.invoke_focus_the_focus_scope();
37assert!(!instance.get_focused());
38instance.invoke_focus_the_line_edit();
39assert!(instance.get_focused());
40instance.invoke_set_manual(false);
41assert!(!instance.get_focused());
42instance.invoke_focus_the_focus_scope();
43assert!(!instance.get_focused());
44instance.invoke_focus_the_line_edit();
45assert!(instance.get_focused());
46```
47
48```cpp
49auto handle = TestCase::create();
50const TestCase &instance = *handle;
51assert(!instance.get_focused());
52instance.invoke_focus_the_line_edit();
53assert(instance.get_focused());
54instance.invoke_focus_the_focus_scope();
55assert(!instance.get_focused());
56instance.invoke_focus_the_line_edit();
57assert(instance.get_focused());
58instance.invoke_set_manual(false);
59assert(!instance.get_focused());
60instance.invoke_focus_the_focus_scope();
61assert(!instance.get_focused());
62instance.invoke_focus_the_line_edit();
63assert(instance.get_focused());
64```
65
66```js
67var instance = new slint.TestCase();
68assert(!instance.focused);
69instance.focus_the_line_edit();
70assert(instance.focused);
71instance.focus_the_focus_scope();
72assert(!instance.focused);
73instance.focus_the_line_edit();
74assert(instance.focused);
75instance.set_manual(false);
76assert(!instance.focused);
77instance.focus_the_focus_scope();
78assert(!instance.focused);
79instance.focus_the_line_edit();
80assert(instance.focused);
81```
82*/
83}
84
85#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
86 use i_slint_backend_testing as slint_testing;
87 slint_testing::init();
88 let instance = TestCase::new().unwrap();
89 assert!(!instance.get_focused());
90 instance.invoke_focus_the_line_edit();
91 assert!(instance.get_focused());
92 instance.invoke_focus_the_focus_scope();
93 assert!(!instance.get_focused());
94 instance.invoke_focus_the_line_edit();
95 assert!(instance.get_focused());
96 instance.invoke_set_manual(false);
97 assert!(!instance.get_focused());
98 instance.invoke_focus_the_focus_scope();
99 assert!(!instance.get_focused());
100 instance.invoke_focus_the_line_edit();
101 assert!(instance.get_focused());
102 Ok(())
103}