1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/text"# ] |
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 | |
5 | TestCase := Window { |
6 | width: 100phx; |
7 | height: 100phx; |
8 | ti := FocusScope { |
9 | key-pressed(event) => { |
10 | pressed = true; |
11 | repeat = event.repeat; |
12 | accept; |
13 | } |
14 | key-released(event) => { |
15 | pressed = false; |
16 | repeat = event.repeat; |
17 | accept; |
18 | } |
19 | } |
20 | |
21 | property <bool> input_focused: ti.has_focus; |
22 | property <bool> pressed; |
23 | property <bool> repeat; |
24 | } |
25 | |
26 | /* |
27 | ```rust |
28 | use slint::platform::WindowEvent; |
29 | |
30 | let instance = TestCase::new().unwrap(); |
31 | |
32 | slint_testing::send_mouse_click(&instance, 5., 5.); |
33 | assert!(instance.get_input_focused()); |
34 | |
35 | instance.window().dispatch_event(WindowEvent::KeyPressed { text: 'a'.into() }); |
36 | assert_eq!(instance.get_pressed(), true); |
37 | assert_eq!(instance.get_repeat(), false); |
38 | |
39 | instance.set_pressed(false); |
40 | instance.window().dispatch_event(WindowEvent::KeyPressRepeated { text: 'a'.into() }); |
41 | assert_eq!(instance.get_pressed(), true); |
42 | assert_eq!(instance.get_repeat(), true); |
43 | |
44 | instance.set_pressed(false); |
45 | instance.window().dispatch_event(WindowEvent::KeyPressRepeated { text: 'a'.into() }); |
46 | assert_eq!(instance.get_pressed(), true); |
47 | assert_eq!(instance.get_repeat(), true); |
48 | |
49 | instance.window().dispatch_event(WindowEvent::KeyReleased { text: 'a'.into() }); |
50 | assert_eq!(instance.get_pressed(), false); |
51 | assert_eq!(instance.get_repeat(), false); |
52 | |
53 | ``` |
54 | */ |
55 | } |
56 | |
57 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
58 | use i_slint_backend_testing as slint_testing; |
59 | slint_testing::init(); |
60 | use slint::platform::WindowEvent; |
61 | |
62 | let instance = TestCase::new().unwrap(); |
63 | |
64 | slint_testing::send_mouse_click(&instance, 5., 5.); |
65 | assert!(instance.get_input_focused()); |
66 | |
67 | instance.window().dispatch_event(WindowEvent::KeyPressed { text: 'a' .into() }); |
68 | assert_eq!(instance.get_pressed(), true); |
69 | assert_eq!(instance.get_repeat(), false); |
70 | |
71 | instance.set_pressed(false); |
72 | instance.window().dispatch_event(WindowEvent::KeyPressRepeated { text: 'a' .into() }); |
73 | assert_eq!(instance.get_pressed(), true); |
74 | assert_eq!(instance.get_repeat(), true); |
75 | |
76 | instance.set_pressed(false); |
77 | instance.window().dispatch_event(WindowEvent::KeyPressRepeated { text: 'a' .into() }); |
78 | assert_eq!(instance.get_pressed(), true); |
79 | assert_eq!(instance.get_repeat(), true); |
80 | |
81 | instance.window().dispatch_event(WindowEvent::KeyReleased { text: 'a' .into() }); |
82 | assert_eq!(instance.get_pressed(), false); |
83 | assert_eq!(instance.get_repeat(), false); |
84 | |
85 | Ok(()) |
86 | } |