1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/models"# ] |
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 | ExtraComponent := Rectangle { |
6 | for x in [{a: "0" }, {a: "1" }] : Text { text: x.a; } |
7 | } |
8 | |
9 | |
10 | Extra2 := Rectangle { |
11 | property<int> top_level; |
12 | property<int> value; |
13 | callback update_value; |
14 | for aaa[r] in [[10, top_level], [2, 3]] : blah := Rectangle { |
15 | width: parent.width; |
16 | height: root.height; |
17 | property <int> some_value: 1000; |
18 | for bb[l] in aaa : TouchArea { |
19 | property <int> some_value: 1515; |
20 | width: 10phx; |
21 | height: 10phx; |
22 | x: r*10phx; |
23 | y: l*10phx; |
24 | clicked => { |
25 | root.value += bb + blah.some_value; |
26 | update_value(); |
27 | } |
28 | } |
29 | } |
30 | } |
31 | |
32 | export TestCase := Rectangle { |
33 | width: 100phx; |
34 | height: 100phx; |
35 | background: white; |
36 | property<float> top_level: 42; |
37 | property<int> value: 0; |
38 | |
39 | for pp[idx] in 5: Rectangle { |
40 | s := Rectangle { |
41 | property<length> within: 88phx; |
42 | x: 2phx * idx; |
43 | y: 200phx * pp; |
44 | width: s.within; |
45 | height: root.top_level * 1phx; |
46 | for nested in [1phx] : Rectangle { |
47 | x : s.width + root.top_level * 1phx + nested; |
48 | } |
49 | } |
50 | } |
51 | |
52 | for pp[idx] in [1,3,2]: Rectangle { |
53 | x: idx * 1phx; |
54 | y: 25phx * pp; |
55 | } |
56 | |
57 | for pp[idx] in ["1" ,"3" ,"2" ]: Rectangle { |
58 | x: idx * 1phx; |
59 | Text { text: pp; } |
60 | } |
61 | |
62 | for pp in [{a: 12, b: "aa" , c: {a: #00f}}, {a: 13, b: "cc" , c: { a: #f00}}]: Text { |
63 | x: pp.a * 1phx; |
64 | text: pp.b; |
65 | color: pp.c.a; |
66 | ExtraComponent { |
67 | } |
68 | } |
69 | Extra2 { |
70 | width: parent.width; |
71 | height: root.height; |
72 | top_level: root.top_level; |
73 | update_value => { |
74 | root.value = self.value; |
75 | } |
76 | } |
77 | |
78 | property<[{a: int}]> m; |
79 | for x in m : TouchArea { |
80 | width: parent.width; |
81 | height: root.height; |
82 | clicked => { |
83 | root.value = x.a; |
84 | } |
85 | } |
86 | |
87 | // issue #2977 |
88 | for v in value + value : Text { text: v; } |
89 | } |
90 | |
91 | |
92 | |
93 | /* |
94 | ```cpp |
95 | auto handle = TestCase::create(); |
96 | const TestCase &instance = *handle; |
97 | |
98 | slint_testing::send_mouse_click(&instance, 5., 5.); |
99 | assert_eq(instance.get_value(), 1010); |
100 | |
101 | slint_testing::send_mouse_click(&instance, 15., 15.); |
102 | assert_eq(instance.get_value(), 2013); |
103 | |
104 | slint_testing::send_mouse_click(&instance, 5., 15.); |
105 | assert_eq(instance.get_value(), 3000+13+42); |
106 | ``` |
107 | |
108 | |
109 | ```rust |
110 | let instance = TestCase::new().unwrap(); |
111 | |
112 | slint_testing::send_mouse_click(&instance, 5., 5.); |
113 | assert_eq!(instance.get_value(), 1010); |
114 | |
115 | slint_testing::send_mouse_click(&instance, 15., 15.); |
116 | assert_eq!(instance.get_value(), 2013); |
117 | |
118 | slint_testing::send_mouse_click(&instance, 5., 15.); |
119 | assert_eq!(instance.get_value(), 3000+13+42); |
120 | |
121 | ``` |
122 | |
123 | ```js |
124 | var instance = new slint.TestCase(); |
125 | slintlib.private_api.send_mouse_click(instance, 5., 5.); |
126 | assert.equal(instance.value, 1010); |
127 | |
128 | instance.cond1 = true; |
129 | slintlib.private_api.send_mouse_click(instance, 15., 15.); |
130 | assert.equal(instance.value, 2013); |
131 | |
132 | instance.cond1 = false; |
133 | slintlib.private_api.send_mouse_click(instance, 5., 15.); |
134 | assert.equal(instance.value, 3000+13+42); |
135 | ``` |
136 | */ |
137 | } |
138 | |
139 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
140 | use i_slint_backend_testing as slint_testing; |
141 | slint_testing::init(); |
142 | let instance = TestCase::new().unwrap(); |
143 | |
144 | slint_testing::send_mouse_click(&instance, x:5., y:5.); |
145 | assert_eq!(instance.get_value(), 1010); |
146 | |
147 | slint_testing::send_mouse_click(&instance, x:15., y:15.); |
148 | assert_eq!(instance.get_value(), 2013); |
149 | |
150 | slint_testing::send_mouse_click(&instance, x:5., y:15.); |
151 | assert_eq!(instance.get_value(), 3000+13+42); |
152 | |
153 | Ok(()) |
154 | } |