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
5TestCase := Window {
6 width: 500phx;
7 height: 500phx;
8
9 f1 := Flickable {
10 x: 0phx;
11 width: 250phx;
12 viewport-height: 800phx;
13
14 t1 := TouchArea {
15 height: 50phx;
16 y: 0px;
17 Rectangle { background: parent.has-hover ? red: blue; }
18 }
19 t1sec := TouchArea {
20 height: 10phx;
21 y: 50px;
22 Rectangle { background: parent.has-hover ? red: blue; }
23 }
24 }
25
26 Flickable {
27 x: 250phx;
28 width: 250phx;
29 viewport-width: 800phx;
30
31 t2 := TouchArea {
32 width: 50phx;
33 Rectangle { background: parent.has-hover ? green: yellow; }
34 }
35 }
36
37 out property<bool> t1-has-hover: t1.has-hover;
38 out property<bool> t1sec-has-hover: t1sec.has-hover;
39 out property<bool> t2-has-hover: t2.has-hover;
40
41 in-out property f1_pos <=> f1.viewport_y;
42}
43
44/*
45```rust
46// Test that mouse exit events are dispatched while scrolling
47use slint::{platform::WindowEvent, LogicalPosition, platform::PointerEventButton};
48let instance = TestCase::new().unwrap();
49// Vertical
50assert_eq!(instance.get_t1_has_hover(), false);
51assert_eq!(instance.get_t1sec_has_hover(), false);
52assert_eq!(instance.get_t2_has_hover(), false);
53instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(25.0, 25.0) });
54assert_eq!(instance.get_t1_has_hover(), true);
55assert_eq!(instance.get_t1sec_has_hover(), false);
56assert_eq!(instance.get_t2_has_hover(), false);
57instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(25.0, 25.0), delta_x: 0.0, delta_y: -30.0 });
58assert_eq!(instance.get_t1_has_hover(), false);
59assert_eq!(instance.get_t1sec_has_hover(), true);
60assert_eq!(instance.get_t2_has_hover(), false);
61assert_eq!(instance.get_f1_pos(), -30.0);
62
63instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(25.0, 25.0), delta_x: 0.0, delta_y: -30.0 });
64assert_eq!(instance.get_t1_has_hover(), false);
65assert_eq!(instance.get_t1sec_has_hover(), false);
66assert_eq!(instance.get_t2_has_hover(), false);
67assert_eq!(instance.get_f1_pos(), -60.0);
68
69
70// Horizontal
71assert_eq!(instance.get_t2_has_hover(), false);
72assert_eq!(instance.get_t1_has_hover(), false);
73instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(275.0, 25.0) });
74assert_eq!(instance.get_t2_has_hover(), true);
75assert_eq!(instance.get_t1_has_hover(), false);
76instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(275.0, 25.0), delta_x: -30.0, delta_y: 0.0 });
77assert_eq!(instance.get_t2_has_hover(), false);
78assert_eq!(instance.get_t1_has_hover(), false);
79
80
81
82
83// Test that it's not flicking when the mouse is released
84assert_eq!(instance.get_f1_pos(), -60.0);
85instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(25.0, 125.0), button: PointerEventButton::Left });
86slint_testing::mock_elapsed_time(100);
87instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(25.0, 125.0), button: PointerEventButton::Left });
88slint_testing::mock_elapsed_time(100);
89assert_eq!(instance.get_f1_pos(), -60.0);
90instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(30.0, 25.0) });
91assert_eq!(instance.get_f1_pos(), -60.0);
92```
93
94
95*/
96