1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/examples"# ] |
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 | TwoRectangle := Rectangle { |
6 | |
7 | callback clicked; |
8 | |
9 | Rectangle { |
10 | x: 50phx; |
11 | y: 50.0phx; |
12 | width: 25phx; |
13 | height: 25phx; |
14 | background: red; |
15 | |
16 | my_area := TouchArea { |
17 | width: 25phx; |
18 | height: 25phx; |
19 | clicked => { root.clicked() } |
20 | } |
21 | } |
22 | } |
23 | |
24 | ButtonRectangle := Rectangle { |
25 | property<string> button_text; |
26 | callback clicked; |
27 | width: 100phx; |
28 | height: 75phx; |
29 | |
30 | inner := Rectangle { |
31 | background: { area.pressed ? green : root.background }; |
32 | animate background { duration: 500ms; } |
33 | area := TouchArea { |
34 | width: inner.width; |
35 | height: inner.height; |
36 | clicked => { root.clicked() } |
37 | } |
38 | Text { |
39 | animate x { duration: 500ms; } |
40 | animate y { duration: 500ms; } |
41 | x: { area.pressed ? 60phx : 50phx; } |
42 | y: { area.pressed ? 20phx : 10phx; } |
43 | text: button_text; |
44 | width: root.width; |
45 | height: root.height; |
46 | horizontal-alignment: left; |
47 | vertical-alignment: center; |
48 | } |
49 | animate x { duration: 500ms; } |
50 | animate y { duration: 500ms; } |
51 | animate width { duration: 500ms; } |
52 | animate height { duration: 500ms; } |
53 | x: { area.pressed ? 0phx-10phx : 0phx } |
54 | y: { area.pressed ? 0phx-10phx : 0phx; } |
55 | width: { area.pressed ? (root.width + 20phx) : root.width; } |
56 | height: { area.pressed ? (root.height + 20phx) : root.height; } |
57 | } |
58 | } |
59 | |
60 | Hello := Rectangle { |
61 | |
62 | callback foobar; |
63 | callback plus_clicked; |
64 | callback minus_clicked; |
65 | |
66 | background: white; |
67 | |
68 | TwoRectangle { |
69 | width: 100phx; |
70 | height: 100phx; |
71 | background: blue; |
72 | clicked => { foobar() } |
73 | } |
74 | Rectangle { |
75 | x: 100phx; |
76 | y: 100phx; |
77 | width: (100phx); |
78 | height: {100phx} |
79 | background: green; |
80 | Rectangle { |
81 | x: 50phx; |
82 | y: 50.0phx; |
83 | width: 25phx; |
84 | height: 25phx; |
85 | background: yellow; |
86 | } |
87 | } |
88 | Image { |
89 | x: 200phx; |
90 | y: 200phx; |
91 | source: @image-url("../../../examples/memory/icons/tile_logo.png" ); |
92 | } |
93 | |
94 | ButtonRectangle { |
95 | background: #888; |
96 | x: 50phx; |
97 | y: 225phx; |
98 | clicked => { counter += 1 } |
99 | button_text: "+" ; |
100 | } |
101 | property<int> counter; |
102 | counter_label := Text { x: 100phx; y: 300phx; text: counter; color: black; } |
103 | ButtonRectangle { |
104 | background: #888; |
105 | x: 50phx; |
106 | y: 350phx; |
107 | clicked => { minus_clicked() } |
108 | button_text: "-" ; |
109 | } |
110 | |
111 | Path { |
112 | x: 100phx; |
113 | y: 300phx; |
114 | fill: green; |
115 | stroke: black; |
116 | stroke_width: 2px; |
117 | |
118 | MoveTo { |
119 | x: 0; |
120 | y: 0; |
121 | } |
122 | |
123 | LineTo { |
124 | x: 100; |
125 | y: 50; |
126 | } |
127 | LineTo { |
128 | x: 0; |
129 | y: 100; |
130 | } |
131 | |
132 | ArcTo { |
133 | x: 0; |
134 | y: 0; |
135 | radius_x: 10; |
136 | radius_y: 10; |
137 | } |
138 | |
139 | // M 0 0 C 15.3333 3.6667 92 1 48 46 Q -25 54 0 0 |
140 | CubicTo { |
141 | x: 48; |
142 | y: 46; |
143 | control-1-x: 15; |
144 | control-1-y: 3; |
145 | control-2-x: 92; |
146 | control-2-y: 1; |
147 | } |
148 | |
149 | QuadraticTo { |
150 | x: 0; |
151 | y: 0; |
152 | control-x: -25; |
153 | control-y: 54; |
154 | } |
155 | |
156 | Close {} |
157 | } |
158 | |
159 | Path { |
160 | commands: ta.pressed ? root.arrow_down_commands : root.funky-shape-commands; |
161 | x: 100phx; |
162 | y: 500phx; |
163 | stroke: black; |
164 | stroke_width: 2px; |
165 | } |
166 | |
167 | ta := TouchArea { |
168 | |
169 | } |
170 | |
171 | property <string> arrow_down_commands: "M21.8,311.1l84.2-82.1c15.7-15.2,41-15.2,56.7,0l341.1,304.1l333.7-297.5c15.5-15.2,41-15.2,56.6,0l84.3,82.1c15.6,15.2,15.6,40,0,55.2L531.7,771c-15.7,15.3-41,15.3-56.7,0l-6.9-6.7L21.8,366.3C6.1,351,6.1,326.3,21.8,311.1z" ; |
172 | property <string> funky_shape_commands: "M 100 300 Q 150 50 250 150 C 250 300 300 300 300 450 A 50 50 0 1 0 450 450 L 550 300" ; |
173 | property <length> width2 <=> root.width; |
174 | } |
175 | |
176 | /* |
177 | |
178 | ```cpp |
179 | auto handle = Hello::create(); |
180 | const Hello &instance = *handle; |
181 | assert(!instance.window().is_visible()); |
182 | instance.window().show(); |
183 | assert(instance.window().is_visible()); |
184 | assert(instance.get_width2() > 0); // default size from the backend |
185 | instance.window().set_size(slint::LogicalSize({123., 456.})); |
186 | assert_eq(instance.get_width2(), 123.); |
187 | instance.window().hide(); |
188 | assert(!instance.window().is_visible()); |
189 | ``` |
190 | |
191 | |
192 | ```rust |
193 | let instance = Hello::new().unwrap(); |
194 | assert!(!instance.window().is_visible()); |
195 | instance.window().show().unwrap(); |
196 | assert!(instance.window().is_visible()); |
197 | assert!(instance.get_width2() > 0.); // default size from the backend |
198 | instance.window().set_size(slint::LogicalSize::new(123., 456.)); |
199 | assert_eq!(instance.get_width2(), 123.); |
200 | instance.window().hide().unwrap(); |
201 | assert!(!instance.window().is_visible()); |
202 | ``` |
203 | |
204 | ```js |
205 | var instance = new slint.Hello(); |
206 | assert(!instance.window.visible); |
207 | instance.window.show(); |
208 | assert(instance.window.visible); |
209 | instance.window.hide(); |
210 | assert(!instance.window.visible); |
211 | ``` |
212 | |
213 | */ |
214 | } |
215 | |
216 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
217 | use i_slint_backend_testing as slint_testing; |
218 | slint_testing::init(); |
219 | let instance = Hello::new().unwrap(); |
220 | assert!(!instance.window().is_visible()); |
221 | instance.window().show().unwrap(); |
222 | assert!(instance.window().is_visible()); |
223 | assert!(instance.get_width2() > 0.); // default size from the backend |
224 | instance.window().set_size(slint::LogicalSize::new(width:123., height:456.)); |
225 | assert_eq!(instance.get_width2(), 123.); |
226 | instance.window().hide().unwrap(); |
227 | assert!(!instance.window().is_visible()); |
228 | Ok(()) |
229 | } |