| 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 | |
| 4 | export 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 |
| 46 | use slint::{LogicalPosition, platform::{WindowEvent, PointerEventButton}}; |
| 47 | use slint::private_unstable_api::re_exports::MouseCursor; |
| 48 | let instance = TestCase::new().unwrap(); |
| 49 | assert!(!instance.get_has_hover1()); |
| 50 | assert!(!instance.get_has_hover2()); |
| 51 | assert!(!instance.get_has_hover3()); |
| 52 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default); |
| 53 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(50.0, 50.0) }); |
| 54 | assert!(!instance.get_has_hover1()); |
| 55 | assert!(!instance.get_has_hover2()); |
| 56 | assert!(!instance.get_has_hover3()); |
| 57 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default); |
| 58 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(240.0, 150.0) }); |
| 59 | assert!(instance.get_has_hover1()); |
| 60 | assert!(!instance.get_has_hover2()); |
| 61 | assert!(!instance.get_has_hover3()); |
| 62 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Copy); |
| 63 | instance.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 |
| 65 | assert!(!instance.get_has_hover1()); |
| 66 | assert!(instance.get_has_hover2()); |
| 67 | assert!(!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); |
| 70 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(330.0, 150.0) }); |
| 71 | assert!(!instance.get_has_hover1()); |
| 72 | assert!(instance.get_has_hover2()); |
| 73 | assert!(!instance.get_has_hover3()); |
| 74 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Alias); |
| 75 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(370.0, 150.0) }); |
| 76 | assert!(!instance.get_has_hover1()); |
| 77 | // here 2 and 3 are both active since one is a children of the other |
| 78 | assert!(instance.get_has_hover2()); |
| 79 | assert!(instance.get_has_hover3()); |
| 80 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default); |
| 81 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(390.0, 150.0) }); |
| 82 | assert!(!instance.get_has_hover1()); |
| 83 | assert!(!instance.get_has_hover2()); |
| 84 | assert!(instance.get_has_hover3()); |
| 85 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default); |
| 86 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(510.0, 150.0) }); |
| 87 | assert!(!instance.get_has_hover1()); |
| 88 | assert!(!instance.get_has_hover2()); |
| 89 | assert!(!instance.get_has_hover3()); |
| 90 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default); |
| 91 | |
| 92 | // Now grab |
| 93 | let button = PointerEventButton::Left; |
| 94 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(240.0, 150.0), button }); |
| 95 | assert!(instance.get_has_hover1()); |
| 96 | assert!(!instance.get_has_hover2()); |
| 97 | assert!(!instance.get_has_hover3()); |
| 98 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Copy); |
| 99 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(290.0, 150.0) }); |
| 100 | assert!(instance.get_has_hover1()); |
| 101 | assert!(!instance.get_has_hover2()); |
| 102 | assert!(!instance.get_has_hover3()); |
| 103 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Copy); |
| 104 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(330.0, 150.0) }); |
| 105 | assert!(instance.get_has_hover1()); |
| 106 | assert!(!instance.get_has_hover2()); |
| 107 | assert!(!instance.get_has_hover3()); |
| 108 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Copy); |
| 109 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(370.0, 150.0) }); |
| 110 | assert!(instance.get_has_hover1()); |
| 111 | assert!(!instance.get_has_hover2()); |
| 112 | assert!(!instance.get_has_hover3()); |
| 113 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Copy); |
| 114 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(390.0, 150.0) }); |
| 115 | assert!(instance.get_has_hover1()); |
| 116 | assert!(!instance.get_has_hover2()); |
| 117 | assert!(!instance.get_has_hover3()); |
| 118 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Copy); |
| 119 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(510.0, 150.0) }); |
| 120 | assert!(instance.get_has_hover1()); |
| 121 | assert!(!instance.get_has_hover2()); |
| 122 | assert!(!instance.get_has_hover3()); |
| 123 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Copy); |
| 124 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(370.0, 150.0), button }); |
| 125 | assert!(!instance.get_has_hover1()); |
| 126 | assert!(instance.get_has_hover2()); |
| 127 | assert!(instance.get_has_hover3()); |
| 128 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default); |
| 129 | |
| 130 | ``` |
| 131 | */ |
| 132 | |