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

SwipeGestureHandler: currectly grab the mouse #6723

Merged
merged 1 commit into from
Nov 5, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions internal/core/items/input_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,10 @@ impl Item for SwipeGestureHandler {

if start_swipe {
Self::FIELD_OFFSETS.swiping.apply_pin(self).set(true);
} else {
return InputEventResult::EventIgnored;
}
}
Self::FIELD_OFFSETS.moved.apply_pin(self).call(&());
InputEventResult::EventAccepted
InputEventResult::GrabMouse
}
MouseEvent::Wheel { .. } => InputEventResult::EventIgnored,
}
Expand Down
21 changes: 9 additions & 12 deletions tests/cases/elements/swipegesturehandler.slint
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,9 @@ assert_eq!(instance.get_ta_hover(), false);
assert_eq!(instance.get_down_swiping(), false);
assert_eq!(instance.get_right_swiping(), false);
assert_eq!(instance.get_left_swiping(), true);
// the root gesture cause the mouse event to be repeated twice
assert_eq!(instance.get_r(), "M2(20)M2(20)");
assert_eq!(instance.get_r(), "M2(20)");
instance.window().dispatch_event(WindowEvent::PointerExited);
assert_eq!(instance.get_r(), "M2(20)M2(20)C2(20)");
assert_eq!(instance.get_r(), "M2(20)C2(20)");
assert_eq!(instance.get_down_swiping(), false);
assert_eq!(instance.get_left_swiping(), false);
assert_eq!(instance.get_right_swiping(), false);
Expand All @@ -191,10 +190,9 @@ assert_eq!(instance.get_ta_hover(), false);
assert_eq!(instance.get_down_swiping(), false);
assert_eq!(instance.get_right_swiping(), false);
assert_eq!(instance.get_left_swiping(), true);
// the root gesture cause the mouse event to be repeated twice
assert_eq!(instance.get_r(), "M2(20)M2(20)");
assert_eq!(instance.get_r(), "M2(20)");
instance.invoke_invoke_cancel();
assert_eq!(instance.get_r(), "M2(20)M2(20)C2(20)");
assert_eq!(instance.get_r(), "M2(20)C2(20)");
assert_eq!(instance.get_down_swiping(), false);
assert_eq!(instance.get_left_swiping(), false);
assert_eq!(instance.get_right_swiping(), false);
Expand All @@ -204,7 +202,7 @@ instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPo
slint_testing::mock_elapsed_time(120);
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left });
slint_testing::mock_elapsed_time(120);
assert_eq!(instance.get_r(), "M2(20)M2(20)C2(20)");
assert_eq!(instance.get_r(), "M2(20)C2(20)");
assert_eq!(instance.get_down_swiping(), false);
assert_eq!(instance.get_left_swiping(), false);
assert_eq!(instance.get_right_swiping(), false);
Expand Down Expand Up @@ -253,7 +251,7 @@ assert_eq!(instance.get_right_swiping(), false, "got cancelled");

instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(220.0, 519.0), button: PointerEventButton::Left });
assert_eq!(instance.get_r(), "S1(169)");
assert_eq!(instance.get_ta_hover(), false, "FIXME: or should it be true as the mouse is still over it?");
assert_eq!(instance.get_ta_hover(), true);
assert_eq!(instance.get_ta_pressed(), false);
assert_eq!(instance.get_down_swiping(), false);
assert_eq!(instance.get_left_swiping(), false);
Expand All @@ -278,10 +276,9 @@ assert_eq(instance.get_ta_hover(), false);
assert_eq(instance.get_down_swiping(), false);
assert_eq(instance.get_right_swiping(), false);
assert_eq(instance.get_left_swiping(), true);
// the root gesture cause the mouse event to be repeated twice
assert_eq(instance.get_r(), "M2(20)M2(20)");
assert_eq(instance.get_r(), "M2(20)");
instance.invoke_invoke_cancel();
assert_eq(instance.get_r(), "M2(20)M2(20)C2(20)");
assert_eq(instance.get_r(), "M2(20)C2(20)");
assert_eq(instance.get_down_swiping(), false);
assert_eq(instance.get_left_swiping(), false);
assert_eq(instance.get_right_swiping(), false);
Expand All @@ -291,7 +288,7 @@ instance.window().dispatch_pointer_move_event(slint::LogicalPosition({ 60.0, 100
slint_testing::mock_elapsed_time(120);
instance.window().dispatch_pointer_release_event(slint::LogicalPosition({40.0, 100.0}), PointerEventButton::Left);
slint_testing::mock_elapsed_time(120);
assert_eq(instance.get_r(), "M2(20)M2(20)C2(20)");
assert_eq(instance.get_r(), "M2(20)C2(20)");
assert_eq(instance.get_down_swiping(), false);
assert_eq(instance.get_left_swiping(), false);
assert_eq(instance.get_right_swiping(), false);
Expand Down
230 changes: 230 additions & 0 deletions tests/cases/elements/swipegesturehandler2.slint
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

export component TestCase inherits Window {
width: 400px;
height: 400px;

in-out property <string> result;
out property swiping-sgh-with-ta <=> sgh-with-ta.swiping;
out property swiping-sgh-wo-ta <=> sgh-wo-ta.swiping;
out property swiping-sgh-disabled-ta <=> sgh-disabled-ta.swiping;


// With a TouchArea
sgh-with-ta := SwipeGestureHandler {
width: 200px;
height: 200px;
x: 0px;
y: 0px;
Rectangle {
background: yellow;
}
handle-swipe-down: true;
handle-swipe-up: true;
handle-swipe-left: true;
handle-swipe-right: true;
TouchArea {
clicked => { result += "ta1"; }
}
}

// Without a TouchArea
sgh-wo-ta := SwipeGestureHandler {
width: 200px;
height: 200px;
x: 200px;
y: 0px;
Rectangle {
background: green;
}
handle-swipe-down: true;
handle-swipe-up: true;
handle-swipe-left: true;
handle-swipe-right: true;
}

// With a disabled one
sgh-disabled-ta := SwipeGestureHandler {
width: 200px;
height: 200px;
x: 0px;
y: 200px;
Rectangle {
background: red;
}
handle-swipe-down: true;
handle-swipe-up: true;
handle-swipe-left: true;
handle-swipe-right: true;
ta := TouchArea {
enabled: false;
clicked => { result += "ta2"; }
}
}
}


/*
```rust
use slint::{platform::WindowEvent, LogicalPosition, platform::PointerEventButton};
let instance = TestCase::new().unwrap();

assert_eq!(instance.get_result(), "");
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);


// With TouchArea
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 100.0) });
instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left });
slint_testing::mock_elapsed_time(200);
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 100.0) });
slint_testing::mock_elapsed_time(50);
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(50.0, 50.0) });
assert_eq!(instance.get_swiping_sgh_with_ta(), true, "we should be swiping 'with-ta'");
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
slint_testing::mock_elapsed_time(50);


instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(250.0, 250.0) }); //outside
assert_eq!(instance.get_swiping_sgh_with_ta(), true, "we should be swiping 'with-ta'");
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
slint_testing::mock_elapsed_time(50);

instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 100.0) });
assert_eq!(instance.get_swiping_sgh_with_ta(), true);
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left });
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
assert_eq!(instance.get_result(), "");


// Without TouhArea
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(200.0 + 100.0, 100.0) });
instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(200.0 + 100.0, 100.0), button: PointerEventButton::Left });
slint_testing::mock_elapsed_time(200);
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(200.0 + 100.0, 100.0) });
slint_testing::mock_elapsed_time(50);
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(200.0 + 50.0, 50.0) });
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), true, "we should be swiping 'without-ta'");
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
slint_testing::mock_elapsed_time(50);

instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(250.0, 250.0) }); //outside
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), true);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
slint_testing::mock_elapsed_time(50);


instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(200.0 + 100.0, 100.0) });
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), true);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(200.0 + 100.0, 100.0), button: PointerEventButton::Left });
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
assert_eq!(instance.get_result(), "");

// With disabled TouchArea
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 200.0 + 100.0) });
instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 200.0 + 100.0), button: PointerEventButton::Left });
slint_testing::mock_elapsed_time(200);
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 200.0 + 100.0) });
slint_testing::mock_elapsed_time(50);
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(50.0, 200.0 + 50.0) });
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), true, "we should be swiping 'with-disabled-ta'");
slint_testing::mock_elapsed_time(50);


instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(250.0, 250.0) }); //outside
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), true);
slint_testing::mock_elapsed_time(50);

instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 200.0 + 100.0) });
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), true);
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(100.0, 200.0 + 100.0), button: PointerEventButton::Left });
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
assert_eq!(instance.get_result(), "");

// Do ther click, now.
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 100.0) });
instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left });
slint_testing::mock_elapsed_time(200);
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(101.0, 101.0) });
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(101.0, 101.0), button: PointerEventButton::Left });
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
assert_eq!(instance.get_result(), "ta1");
instance.set_result("".into());

instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0 + 100.0, 100.0) });
instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0 + 100.0, 100.0), button: PointerEventButton::Left });
slint_testing::mock_elapsed_time(200);
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0 + 101.0, 101.0) });
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(100.0 + 101.0, 101.0), button: PointerEventButton::Left });
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
assert_eq!(instance.get_result(), "");

instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 100.0 + 100.0) });
instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 100.0 + 100.0), button: PointerEventButton::Left });
slint_testing::mock_elapsed_time(200);
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(101.0, 100.0 + 101.0) });
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(101.0, 100.0 + 101.0), button: PointerEventButton::Left });
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
assert_eq!(instance.get_result(), "");


```


*/
Loading