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
4component Clip {
5 // the presence of a Clip element should not impact the rest
6}
7
8
9MaybeVisible := 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
26Invisible := TouchArea {
27 visible: false;
28}
29
30component VisibleAlias {
31 in property v <=> r.visible;
32 r := Rectangle {
33 TouchArea {
34 clicked => {
35 debug("Error");
36 }
37 }
38 }
39}
40
41TestCase := 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
71auto handle = TestCase::create();
72const TestCase &instance = *handle;
73
74assert_eq(instance.get_test(), true);
75assert_eq(instance.get_el1visible(), true);
76
77// el2 !visible, outside
78slint_testing::send_mouse_click(&instance, 37., 27.);
79assert_eq(instance.get_touch1(), 0);
80assert_eq(instance.get_touch2(), 0);
81assert(!instance.get_el1_has_hover());
82
83// el2 !visible, inside
84slint_testing::send_mouse_click(&instance, 37., 33.);
85assert_eq(instance.get_touch1(), 0);
86assert_eq(instance.get_touch2(), 0);
87assert(!instance.get_el1_has_hover());
88
89
90// el1 visible, outside
91slint_testing::send_mouse_click(&instance, 17., 7.);
92assert_eq(instance.get_touch1(), 1);
93assert_eq(instance.get_touch2(), 0);
94assert(instance.get_el1_has_hover());
95
96// el1 visible, inside
97slint_testing::send_mouse_click(&instance, 17., 13.);
98assert_eq(instance.get_touch1(), 2);
99assert_eq(instance.get_touch2(), 0);
100assert(instance.get_el1_has_hover());
101
102// now makes el invisible
103instance.set_el1visible(false);
104slint_testing::send_mouse_click(&instance, 17., 7.);
105assert_eq(instance.get_touch1(), 2);
106assert_eq(instance.get_touch2(), 0);
107assert(!instance.get_el1_has_hover());
108
109```
110
111
112```rust
113let instance = TestCase::new().unwrap();
114
115
116assert_eq!(instance.get_test(), true);
117assert_eq!(instance.get_el1visible(), true);
118
119// el2 !visible, outside
120slint_testing::send_mouse_click(&instance, 37., 27.);
121assert_eq!(instance.get_touch1(), 0);
122assert_eq!(instance.get_touch2(), 0);
123
124// el2 !visible, inside
125slint_testing::send_mouse_click(&instance, 37., 33.);
126assert_eq!(instance.get_touch1(), 0);
127assert_eq!(instance.get_touch2(), 0);
128assert!(!instance.get_el1_has_hover());
129
130
131// el1 visible, outside
132slint_testing::send_mouse_click(&instance, 17., 7.);
133assert_eq!(instance.get_touch1(), 1);
134assert_eq!(instance.get_touch2(), 0);
135assert!(instance.get_el1_has_hover());
136
137// el1 visible, inside
138slint_testing::send_mouse_click(&instance, 17., 13.);
139assert_eq!(instance.get_touch1(), 2);
140assert_eq!(instance.get_touch2(), 0);
141assert!(instance.get_el1_has_hover());
142
143// now makes el invisible
144instance.set_el1visible(false);
145slint_testing::send_mouse_click(&instance, 17., 7.);
146assert_eq!(instance.get_touch1(), 2);
147assert_eq!(instance.get_touch2(), 0);
148assert!(!instance.get_el1_has_hover());
149```
150
151*/
152