Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flickable should not accept the mouse release event if it was not flicking #1905

Merged
merged 1 commit into from Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion internal/core/items/flickable.rs
Expand Up @@ -292,8 +292,13 @@ impl FlickableData {
InputEventResult::GrabMouse
}
MouseEvent::Exit | MouseEvent::Released { .. } => {
let was_capturing = inner.capture_events;
Self::mouse_released(&mut inner, flick, event);
InputEventResult::EventAccepted
if was_capturing {
InputEventResult::EventAccepted
} else {
InputEventResult::EventIgnored
}
}
MouseEvent::Moved { position } => {
if inner.pressed_time.is_some() {
Expand Down
22 changes: 20 additions & 2 deletions tests/cases/elements/flickable3.slint
Expand Up @@ -6,7 +6,7 @@ TestCase := Window {
width: 500phx;
height: 500phx;

Flickable {
f1 := Flickable {
x: 0phx;
width: 250phx;
viewport-height: 800phx;
Expand All @@ -28,24 +28,42 @@ TestCase := Window {

property<bool> t1-has-hover: t1.has-hover;
property<bool> t2-has-hover: t2.has-hover;

property f1_pos <=> f1.viewport_y;
}

/*
```rust
// Test that mouse exit events are dispatched while scrolling
use slint::{platform::WindowEvent, LogicalPosition};
use slint::{platform::WindowEvent, LogicalPosition, platform::PointerEventButton};
let instance = TestCase::new();
// Vertical
assert_eq!(instance.get_t1_has_hover(), false);
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(25.0, 25.0) });
assert_eq!(instance.get_t1_has_hover(), true);
instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(25.0, 25.0), delta_x: 0.0, delta_y: -30.0 });
assert_eq!(instance.get_t1_has_hover(), false);
assert_eq!(instance.get_f1_pos(), -30.0);
// Horizontal
assert_eq!(instance.get_t2_has_hover(), false);
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(275.0, 25.0) });
assert_eq!(instance.get_t2_has_hover(), true);
instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(275.0, 25.0), delta_x: -30.0, delta_y: 0.0 });
assert_eq!(instance.get_t2_has_hover(), false);




// Test that it's not flicking when the mouse is released
assert_eq!(instance.get_f1_pos(), -30.0);
instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(25.0, 125.0), button: PointerEventButton::Left });
slint_testing::mock_elapsed_time(100);
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(25.0, 125.0), button: PointerEventButton::Left });
slint_testing::mock_elapsed_time(100);
assert_eq!(instance.get_f1_pos(), -30.0);
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(30.0, 25.0) });
assert_eq!(instance.get_f1_pos(), -30.0);
```


*/