1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/layout"# ] |
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: 500px; |
7 | height: 550px; |
8 | background: #ecedeb; |
9 | |
10 | property<[int]> xs: [1, 2, 3]; |
11 | |
12 | VerticalLayout { |
13 | padding: 0px; |
14 | spacing: 0px; |
15 | alignment: start; |
16 | |
17 | for x_[i] in xs: Rectangle { |
18 | background: i == 0 ? red : i == 1 ? green : blue; |
19 | height: 100px; |
20 | TouchArea { |
21 | clicked => { last_clicked = x_; } |
22 | } |
23 | } |
24 | |
25 | for x_[i] in xs: Rectangle { |
26 | background: i == 0 ? red : i == 1 ? green : blue; |
27 | min-height: 50px; |
28 | TouchArea { |
29 | clicked => { last_clicked = 10 + x_; } |
30 | } |
31 | } |
32 | } |
33 | |
34 | property<int> last_clicked; |
35 | } |
36 | /* |
37 | ```cpp |
38 | auto handle = TestCase::create(); |
39 | const TestCase &instance = *handle; |
40 | |
41 | slint_testing::send_mouse_click(&instance, 5., 455.); |
42 | assert_eq(instance.get_last_clicked(), 0); |
43 | slint_testing::send_mouse_click(&instance, 5., 305.); |
44 | assert_eq(instance.get_last_clicked(), 11); |
45 | slint_testing::send_mouse_click(&instance, 5., 295.); |
46 | assert_eq(instance.get_last_clicked(), 3); |
47 | slint_testing::send_mouse_click(&instance, 5., 95.); |
48 | assert_eq(instance.get_last_clicked(), 1); |
49 | ``` |
50 | |
51 | |
52 | ```rust |
53 | let instance = TestCase::new().unwrap(); |
54 | |
55 | slint_testing::send_mouse_click(&instance, 5., 455.); |
56 | assert_eq!(instance.get_last_clicked(), 0); |
57 | slint_testing::send_mouse_click(&instance, 5., 305.); |
58 | assert_eq!(instance.get_last_clicked(), 11); |
59 | slint_testing::send_mouse_click(&instance, 5., 295.); |
60 | assert_eq!(instance.get_last_clicked(), 3); |
61 | slint_testing::send_mouse_click(&instance, 5., 95.); |
62 | assert_eq!(instance.get_last_clicked(), 1); |
63 | ``` |
64 | |
65 | ```js |
66 | var instance = new slint.TestCase(); |
67 | slintlib.private_api.send_mouse_click(instance, 5., 455.); |
68 | assert.equal(instance.last_clicked, 0); |
69 | slintlib.private_api.send_mouse_click(instance, 5., 305.); |
70 | assert.equal(instance.last_clicked, 11); |
71 | slintlib.private_api.send_mouse_click(instance, 5., 295.); |
72 | assert.equal(instance.last_clicked, 3); |
73 | slintlib.private_api.send_mouse_click(instance, 5., 95.); |
74 | assert.equal(instance.last_clicked, 1); |
75 | ``` |
76 | */ |
77 | } |
78 | |
79 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
80 | use i_slint_backend_testing as slint_testing; |
81 | slint_testing::init(); |
82 | let instance = TestCase::new().unwrap(); |
83 | |
84 | slint_testing::send_mouse_click(&instance, x:5., y:455.); |
85 | assert_eq!(instance.get_last_clicked(), 0); |
86 | slint_testing::send_mouse_click(&instance, x:5., y:305.); |
87 | assert_eq!(instance.get_last_clicked(), 11); |
88 | slint_testing::send_mouse_click(&instance, x:5., y:295.); |
89 | assert_eq!(instance.get_last_clicked(), 3); |
90 | slint_testing::send_mouse_click(&instance, x:5., y:95.); |
91 | assert_eq!(instance.get_last_clicked(), 1); |
92 | Ok(()) |
93 | } |