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 := Rectangle {
6 width: 400phx;
7 height: 400phx;
8 forward-focus: focus-scope;
9
10 focus-scope := FocusScope {}
11
12 FocusScope {
13 focus-changed-event => {
14 scope-focused = self.has-focus;
15 }
16 }
17
18 property <bool> scope-focused;
19}
20
21/*
22```rust
23let instance = TestCase::new().unwrap();
24assert!(!instance.get_scope_focused());
25slint_testing::send_keyboard_string_sequence(&instance, "\t");
26assert!(instance.get_scope_focused());
27slint_testing::send_keyboard_string_sequence(&instance, "\t");
28assert!(!instance.get_scope_focused());
29```
30
31```cpp
32auto handle = TestCase::create();
33const TestCase &instance = *handle;
34assert(!instance.get_scope_focused());
35slint_testing::send_keyboard_string_sequence(&instance, "\t");
36assert(instance.get_scope_focused());
37slint_testing::send_keyboard_string_sequence(&instance, "\t");
38assert(!instance.get_scope_focused());
39```
40
41```js
42var instance = new slint.TestCase();
43assert(!instance.scope_focused);
44slintlib.private_api.send_keyboard_string_sequence(instance, "\t");
45assert(instance.scope_focused);
46slintlib.private_api.send_keyboard_string_sequence(instance, "\t");
47assert(!instance.scope_focused);
48```
49*/
50}
51
52#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
53 use i_slint_backend_testing as slint_testing;
54 slint_testing::init();
55 let instance = TestCase::new().unwrap();
56 assert!(!instance.get_scope_focused());
57 slint_testing::send_keyboard_string_sequence(&instance, sequence:"\t");
58 assert!(instance.get_scope_focused());
59 slint_testing::send_keyboard_string_sequence(&instance, sequence:"\t");
60 assert!(!instance.get_scope_focused());
61 Ok(())
62}