1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3
4export component TestCase inherits Window {
5 width: 600px;
6 height: 600px;
7
8 out property has-hover1 <=> area.has-hover;
9 out property has-hover2 <=> secondArea.has-hover;
10 out property has-hover3 <=> area3.has-hover;
11
12 Rectangle {
13 width: 100px;
14 height: 100px;
15 background: area.has-hover ? red : orange;
16 y: 100px;
17 x: 220px;
18 opacity: 0.75;
19 area := TouchArea { mouse-cursor: copy;}
20 }
21
22 Rectangle {
23 width: 100px;
24 height: 100px;
25 background: secondArea.has-hover ? blue : cyan;
26 opacity: 0.75;
27 y: 100px;
28 x: 280px;
29 secondArea := TouchArea {
30 mouse-cursor: alias;
31 Rectangle {
32 width: 100px;
33 height: 100px;
34 background: area3.has-hover ? green : lime;
35 opacity: 0.75;
36 x: 80px;
37 area3 := TouchArea {}
38 }
39
40 }
41 }
42}
43
44/*
45```rust
46use slint::{LogicalPosition, platform::{WindowEvent, PointerEventButton}};
47use slint::private_unstable_api::re_exports::MouseCursor;
48let instance = TestCase::new().unwrap();
49assert!(!instance.get_has_hover1());
50assert!(!instance.get_has_hover2());
51assert!(!instance.get_has_hover3());
52assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default);
53instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(50.0, 50.0) });
54assert!(!instance.get_has_hover1());
55assert!(!instance.get_has_hover2());
56assert!(!instance.get_has_hover3());
57assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default);
58instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(240.0, 150.0) });
59assert!(instance.get_has_hover1());
60assert!(!instance.get_has_hover2());
61assert!(!instance.get_has_hover3());
62assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Copy);
63instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(290.0, 150.0) });
64// We Since the touch area are not children, only one is active
65assert!(!instance.get_has_hover1());
66assert!(instance.get_has_hover2());
67assert!(!instance.get_has_hover3());
68//FIXME: it currently takes two events for the mouse cursor to change when going from one MouseArea to another
69//assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Alias);
70instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(330.0, 150.0) });
71assert!(!instance.get_has_hover1());
72assert!(instance.get_has_hover2());
73assert!(!instance.get_has_hover3());
74assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Alias);
75instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(370.0, 150.0) });
76assert!(!instance.get_has_hover1());
77// here 2 and 3 are both active since one is a children of the other
78assert!(instance.get_has_hover2());
79assert!(instance.get_has_hover3());
80assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default);
81instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(390.0, 150.0) });
82assert!(!instance.get_has_hover1());
83assert!(!instance.get_has_hover2());
84assert!(instance.get_has_hover3());
85assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default);
86instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(510.0, 150.0) });
87assert!(!instance.get_has_hover1());
88assert!(!instance.get_has_hover2());
89assert!(!instance.get_has_hover3());
90assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default);
91
92// Now grab
93let button = PointerEventButton::Left;
94instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(240.0, 150.0), button });
95assert!(instance.get_has_hover1());
96assert!(!instance.get_has_hover2());
97assert!(!instance.get_has_hover3());
98assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Copy);
99instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(290.0, 150.0) });
100assert!(instance.get_has_hover1());
101assert!(!instance.get_has_hover2());
102assert!(!instance.get_has_hover3());
103assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Copy);
104instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(330.0, 150.0) });
105assert!(instance.get_has_hover1());
106assert!(!instance.get_has_hover2());
107assert!(!instance.get_has_hover3());
108assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Copy);
109instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(370.0, 150.0) });
110assert!(instance.get_has_hover1());
111assert!(!instance.get_has_hover2());
112assert!(!instance.get_has_hover3());
113assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Copy);
114instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(390.0, 150.0) });
115assert!(instance.get_has_hover1());
116assert!(!instance.get_has_hover2());
117assert!(!instance.get_has_hover3());
118assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Copy);
119instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(510.0, 150.0) });
120assert!(instance.get_has_hover1());
121assert!(!instance.get_has_hover2());
122assert!(!instance.get_has_hover3());
123assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Copy);
124instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(370.0, 150.0), button });
125assert!(!instance.get_has_hover1());
126assert!(instance.get_has_hover2());
127assert!(instance.get_has_hover3());
128assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default);
129
130```
131*/
132