1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial |
3 | |
4 | component Clip { |
5 | // the presence of a Clip element should not impact the rest |
6 | } |
7 | |
8 | |
9 | MaybeVisible := Rectangle { |
10 | width: 10phx; |
11 | height: 10phx; |
12 | property <int> touch; |
13 | out property has-hover <=> ta.has-hover; |
14 | Rectangle { |
15 | background: red; |
16 | x: 5phx; |
17 | y: -10phx; |
18 | width: 15phx; |
19 | height: 15phx; |
20 | ta := TouchArea { |
21 | clicked => { touch+=1; } |
22 | } |
23 | } |
24 | } |
25 | |
26 | Invisible := TouchArea { |
27 | visible: false; |
28 | } |
29 | |
30 | component VisibleAlias { |
31 | in property v <=> r.visible; |
32 | r := Rectangle { |
33 | TouchArea { |
34 | clicked => { |
35 | debug("Error" ); |
36 | } |
37 | } |
38 | } |
39 | } |
40 | |
41 | TestCase := Rectangle { |
42 | height: 100phx; |
43 | width: 100phx; |
44 | property <int> touch1 <=> el1.touch; |
45 | property <int> touch2 <=> el2.touch; |
46 | property <bool> el1visible : true; |
47 | out property el1-has-hover <=> el1.has-hover; |
48 | |
49 | el1 := MaybeVisible { |
50 | visible <=> el1visible; |
51 | x: 10phx; |
52 | y: 10phx; |
53 | } |
54 | |
55 | el2 := MaybeVisible { |
56 | visible: false; |
57 | x: 30phx; |
58 | y: 30phx; |
59 | } |
60 | |
61 | Invisible { } |
62 | |
63 | VisibleAlias { v:false; width: 100%; height: 100%; } |
64 | |
65 | test_rect := Rectangle { } |
66 | property <bool> test: test_rect.visible && !el2.visible && el1.visible; |
67 | } |
68 | |
69 | /* |
70 | ```cpp |
71 | auto handle = TestCase::create(); |
72 | const TestCase &instance = *handle; |
73 | |
74 | assert_eq(instance.get_test(), true); |
75 | assert_eq(instance.get_el1visible(), true); |
76 | |
77 | // el2 !visible, outside |
78 | slint_testing::send_mouse_click(&instance, 37., 27.); |
79 | assert_eq(instance.get_touch1(), 0); |
80 | assert_eq(instance.get_touch2(), 0); |
81 | assert(!instance.get_el1_has_hover()); |
82 | |
83 | // el2 !visible, inside |
84 | slint_testing::send_mouse_click(&instance, 37., 33.); |
85 | assert_eq(instance.get_touch1(), 0); |
86 | assert_eq(instance.get_touch2(), 0); |
87 | assert(!instance.get_el1_has_hover()); |
88 | |
89 | |
90 | // el1 visible, outside |
91 | slint_testing::send_mouse_click(&instance, 17., 7.); |
92 | assert_eq(instance.get_touch1(), 1); |
93 | assert_eq(instance.get_touch2(), 0); |
94 | assert(instance.get_el1_has_hover()); |
95 | |
96 | // el1 visible, inside |
97 | slint_testing::send_mouse_click(&instance, 17., 13.); |
98 | assert_eq(instance.get_touch1(), 2); |
99 | assert_eq(instance.get_touch2(), 0); |
100 | assert(instance.get_el1_has_hover()); |
101 | |
102 | // now makes el invisible |
103 | instance.set_el1visible(false); |
104 | slint_testing::send_mouse_click(&instance, 17., 7.); |
105 | assert_eq(instance.get_touch1(), 2); |
106 | assert_eq(instance.get_touch2(), 0); |
107 | assert(!instance.get_el1_has_hover()); |
108 | |
109 | ``` |
110 | |
111 | |
112 | ```rust |
113 | let instance = TestCase::new().unwrap(); |
114 | |
115 | |
116 | assert_eq!(instance.get_test(), true); |
117 | assert_eq!(instance.get_el1visible(), true); |
118 | |
119 | // el2 !visible, outside |
120 | slint_testing::send_mouse_click(&instance, 37., 27.); |
121 | assert_eq!(instance.get_touch1(), 0); |
122 | assert_eq!(instance.get_touch2(), 0); |
123 | |
124 | // el2 !visible, inside |
125 | slint_testing::send_mouse_click(&instance, 37., 33.); |
126 | assert_eq!(instance.get_touch1(), 0); |
127 | assert_eq!(instance.get_touch2(), 0); |
128 | assert!(!instance.get_el1_has_hover()); |
129 | |
130 | |
131 | // el1 visible, outside |
132 | slint_testing::send_mouse_click(&instance, 17., 7.); |
133 | assert_eq!(instance.get_touch1(), 1); |
134 | assert_eq!(instance.get_touch2(), 0); |
135 | assert!(instance.get_el1_has_hover()); |
136 | |
137 | // el1 visible, inside |
138 | slint_testing::send_mouse_click(&instance, 17., 13.); |
139 | assert_eq!(instance.get_touch1(), 2); |
140 | assert_eq!(instance.get_touch2(), 0); |
141 | assert!(instance.get_el1_has_hover()); |
142 | |
143 | // now makes el invisible |
144 | instance.set_el1visible(false); |
145 | slint_testing::send_mouse_click(&instance, 17., 7.); |
146 | assert_eq!(instance.get_touch1(), 2); |
147 | assert_eq!(instance.get_touch2(), 0); |
148 | assert!(!instance.get_el1_has_hover()); |
149 | ``` |
150 | |
151 | */ |
152 | |