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
9 callback focus_rectangle();
10 focus_rectangle => { rectangle.focus(); }
11
12 rectangle := Rectangle {
13 width: parent.width;
14 height: 200phx;
15 forward-focus: input;
16 }
17
18 input := TextInput {
19 y: 200phx;
20 width: parent.width;
21 height: 200phx;
22 }
23
24 property<bool> input_focused: input.has_focus;
25}
26
27/*
28```rust
29let instance = TestCase::new().unwrap();
30assert!(!instance.get_input_focused());
31
32instance.invoke_focus_rectangle();
33assert!(instance.get_input_focused());
34```
35
36```cpp
37auto handle = TestCase::create();
38const TestCase &instance = *handle;
39assert(!instance.get_input_focused());
40
41instance.invoke_focus_rectangle();
42assert(instance.get_input_focused());
43```
44
45```js
46var instance = new slint.TestCase();
47assert(!instance.input_focused);
48
49instance.focus_rectangle();
50assert(instance.input_focused);
51```
52*/
53}
54
55#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
56 use i_slint_backend_testing as slint_testing;
57 slint_testing::init();
58 let instance = TestCase::new().unwrap();
59 assert!(!instance.get_input_focused());
60
61 instance.invoke_focus_rectangle();
62 assert!(instance.get_input_focused());
63 Ok(())
64}