Core: Pass the MouseEvent by reference

(Prepare to add non-copy data in it)
This commit is contained in:
Olivier Goffart 2025-06-17 15:45:09 +02:00
parent 14be95b6a7
commit 47a556d0e7
23 changed files with 142 additions and 150 deletions

View file

@ -224,7 +224,7 @@ public:
void dispatch_pointer_event(const cbindgen_private::MouseEvent &event)
{
private_api::assert_main_thread();
cbindgen_private::slint_windowrc_dispatch_pointer_event(&inner, event);
cbindgen_private::slint_windowrc_dispatch_pointer_event(&inner, &event);
}
/// Registers a font by the specified path. The path must refer to an existing

View file

@ -237,7 +237,7 @@ impl Item for NativeButton {
fn input_event_filter_before_children(
self: Pin<&Self>,
event: MouseEvent,
event: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -247,7 +247,7 @@ impl Item for NativeButton {
fn input_event(
self: Pin<&Self>,
event: MouseEvent,
event: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
self_rc: &i_slint_core::items::ItemRc,
) -> InputEventResult {
@ -262,7 +262,7 @@ impl Item for NativeButton {
let was_pressed = self.pressed();
Self::FIELD_OFFSETS.pressed.apply_pin(self).set(match event {
MouseEvent::Pressed { button, .. } => button == PointerEventButton::Left,
MouseEvent::Pressed { button, .. } => *button == PointerEventButton::Left,
MouseEvent::Exit | MouseEvent::Released { .. } => false,
MouseEvent::Moved { .. } => {
return if was_pressed {
@ -275,7 +275,8 @@ impl Item for NativeButton {
});
if let MouseEvent::Released { position, .. } = event {
let geo = self_rc.geometry();
if LogicalRect::new(LogicalPoint::default(), geo.size).contains(position) && was_pressed
if LogicalRect::new(LogicalPoint::default(), geo.size).contains(*position)
&& was_pressed
{
self.activate();
}

View file

@ -67,7 +67,7 @@ impl Item for NativeCheckBox {
fn input_event_filter_before_children(
self: Pin<&Self>,
event: MouseEvent,
event: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -77,7 +77,7 @@ impl Item for NativeCheckBox {
fn input_event(
self: Pin<&Self>,
event: MouseEvent,
event: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
self_rc: &i_slint_core::items::ItemRc,
) -> InputEventResult {
@ -89,8 +89,8 @@ impl Item for NativeCheckBox {
}
if let MouseEvent::Released { position, button, .. } = event {
let geo = self_rc.geometry();
if button == PointerEventButton::Left
&& LogicalRect::new(LogicalPoint::default(), geo.size).contains(position)
if *button == PointerEventButton::Left
&& LogicalRect::new(LogicalPoint::default(), geo.size).contains(*position)
{
Self::FIELD_OFFSETS.checked.apply_pin(self).set(!self.checked());
Self::FIELD_OFFSETS.toggled.apply_pin(self).call(&())

View file

@ -52,7 +52,7 @@ impl Item for NativeComboBox {
fn input_event_filter_before_children(
self: Pin<&Self>,
event: MouseEvent,
event: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -62,7 +62,7 @@ impl Item for NativeComboBox {
fn input_event(
self: Pin<&Self>,
event: MouseEvent,
event: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &i_slint_core::items::ItemRc,
) -> InputEventResult {
@ -193,7 +193,7 @@ impl Item for NativeComboBoxPopup {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -202,7 +202,7 @@ impl Item for NativeComboBoxPopup {
fn input_event(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &i_slint_core::items::ItemRc,
) -> InputEventResult {

View file

@ -161,7 +161,7 @@ impl Item for NativeGroupBox {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -170,7 +170,7 @@ impl Item for NativeGroupBox {
fn input_event(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &i_slint_core::items::ItemRc,
) -> InputEventResult {

View file

@ -93,7 +93,7 @@ impl Item for NativeLineEdit {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -102,7 +102,7 @@ impl Item for NativeLineEdit {
fn input_event(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &i_slint_core::items::ItemRc,
) -> InputEventResult {

View file

@ -80,7 +80,7 @@ impl Item for NativeStandardListViewItem {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -89,7 +89,7 @@ impl Item for NativeStandardListViewItem {
fn input_event(
self: Pin<&Self>,
_event: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &i_slint_core::items::ItemRc,
) -> InputEventResult {

View file

@ -72,7 +72,7 @@ impl Item for NativeProgressIndicator {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -81,7 +81,7 @@ impl Item for NativeProgressIndicator {
fn input_event(
self: Pin<&Self>,
_event: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &i_slint_core::items::ItemRc,
) -> InputEventResult {

View file

@ -105,7 +105,7 @@ impl Item for NativeScrollView {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -114,7 +114,7 @@ impl Item for NativeScrollView {
fn input_event(
self: Pin<&Self>,
event: MouseEvent,
event: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
self_rc: &i_slint_core::items::ItemRc,
) -> InputEventResult {

View file

@ -149,7 +149,7 @@ impl Item for NativeSlider {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -159,7 +159,7 @@ impl Item for NativeSlider {
#[allow(clippy::unnecessary_cast)] // MouseEvent uses Coord
fn input_event(
self: Pin<&Self>,
event: MouseEvent,
event: &MouseEvent,
window_adapter: &Rc<dyn WindowAdapter>,
self_rc: &i_slint_core::items::ItemRc,
) -> InputEventResult {
@ -248,7 +248,7 @@ impl Item for NativeSlider {
InputEventResult::EventAccepted
}
MouseEvent::Pressed { button, .. } | MouseEvent::Released { button, .. } => {
debug_assert_ne!(button, PointerEventButton::Left);
debug_assert_ne!(*button, PointerEventButton::Left);
InputEventResult::EventIgnored
}
};

View file

@ -123,7 +123,7 @@ impl Item for NativeSpinBox {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -132,7 +132,7 @@ impl Item for NativeSpinBox {
fn input_event(
self: Pin<&Self>,
event: MouseEvent,
event: &MouseEvent,
window_adapter: &Rc<dyn WindowAdapter>,
self_rc: &i_slint_core::items::ItemRc,
) -> InputEventResult {
@ -178,7 +178,7 @@ impl Item for NativeSpinBox {
}
MouseEvent::Released { button, .. } => {
data.pressed = false;
let left_button = button == PointerEventButton::Left;
let left_button = *button == PointerEventButton::Left;
if new_control == cpp!(unsafe []->u32 as "int" { return QStyle::SC_SpinBoxUp;})
&& enabled
&& left_button
@ -206,14 +206,14 @@ impl Item for NativeSpinBox {
}
MouseEvent::Moved { .. } => false,
MouseEvent::Wheel { delta_y, .. } => {
if delta_y > 0. {
if *delta_y > 0. {
let v = self.value();
if v < self.maximum() {
let new_val = v + step_size;
self.value.set(new_val);
Self::FIELD_OFFSETS.edited.apply_pin(self).call(&(new_val,));
}
} else if delta_y < 0. {
} else if *delta_y < 0. {
let v = self.value();
if v > self.minimum() {
let new_val = v - step_size;

View file

@ -61,7 +61,7 @@ impl Item for NativeTableHeaderSection {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -70,7 +70,7 @@ impl Item for NativeTableHeaderSection {
fn input_event(
self: Pin<&Self>,
_event: MouseEvent,
_event: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &i_slint_core::items::ItemRc,
) -> InputEventResult {

View file

@ -237,7 +237,7 @@ impl Item for NativeTabWidget {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -246,7 +246,7 @@ impl Item for NativeTabWidget {
fn input_event(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &i_slint_core::items::ItemRc,
) -> InputEventResult {
@ -422,7 +422,7 @@ impl Item for NativeTab {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -431,7 +431,7 @@ impl Item for NativeTab {
fn input_event(
self: Pin<&Self>,
event: MouseEvent,
event: &MouseEvent,
window_adapter: &Rc<dyn WindowAdapter>,
self_rc: &i_slint_core::items::ItemRc,
) -> InputEventResult {
@ -441,7 +441,7 @@ impl Item for NativeTab {
}
Self::FIELD_OFFSETS.pressed.apply_pin(self).set(match event {
MouseEvent::Pressed { button, .. } => button == PointerEventButton::Left,
MouseEvent::Pressed { button, .. } => *button == PointerEventButton::Left,
MouseEvent::Exit | MouseEvent::Released { .. } => false,
MouseEvent::Moved { .. } => {
return if self.pressed() {
@ -455,8 +455,8 @@ impl Item for NativeTab {
let click_on_press = cpp!(unsafe [] -> bool as "bool" {
return qApp->style()->styleHint(QStyle::SH_TabBar_SelectMouseType, nullptr, nullptr) == QEvent::MouseButtonPress;
});
if matches!(event, MouseEvent::Released { button, .. } if !click_on_press && button == PointerEventButton::Left)
|| matches!(event, MouseEvent::Pressed { button, .. } if click_on_press && button == PointerEventButton::Left)
if matches!(event, MouseEvent::Released { button: PointerEventButton::Left, .. } if !click_on_press)
|| matches!(event, MouseEvent::Pressed { button: PointerEventButton::Left, .. } if click_on_press)
{
WindowInner::from_pub(window_adapter.window()).set_focus_item(
self_rc,

View file

@ -559,15 +559,15 @@ impl MouseInputState {
/// Try to handle the mouse grabber. Return None if the event has been handled, otherwise
/// return the event that must be handled
pub(crate) fn handle_mouse_grab(
mouse_event: MouseEvent,
mouse_event: &MouseEvent,
window_adapter: &Rc<dyn WindowAdapter>,
mouse_input_state: &mut MouseInputState,
) -> Option<MouseEvent> {
if !mouse_input_state.grabbed || mouse_input_state.item_stack.is_empty() {
return Some(mouse_event);
return Some(mouse_event.clone());
};
let mut event = mouse_event;
let mut event = mouse_event.clone();
let mut intercept = false;
let mut invalid = false;
@ -584,7 +584,7 @@ pub(crate) fn handle_mouse_grab(
return false;
};
if intercept {
item.borrow().as_ref().input_event(MouseEvent::Exit, window_adapter, &item);
item.borrow().as_ref().input_event(&MouseEvent::Exit, window_adapter, &item);
return false;
}
let g = item.geometry();
@ -598,7 +598,7 @@ pub(crate) fn handle_mouse_grab(
if interested
&& item.borrow().as_ref().input_event_filter_before_children(
event,
&event,
window_adapter,
&item,
) == InputEventFilterResult::Intercept
@ -608,11 +608,11 @@ pub(crate) fn handle_mouse_grab(
true
});
if invalid {
return Some(mouse_event);
return Some(mouse_event.clone());
}
let grabber = mouse_input_state.top_item().unwrap();
let input_result = grabber.borrow().as_ref().input_event(event, window_adapter, &grabber);
let input_result = grabber.borrow().as_ref().input_event(&event, window_adapter, &grabber);
if input_result != InputEventResult::GrabMouse {
mouse_input_state.grabbed = false;
// Return a move event so that the new position can be registered properly
@ -634,7 +634,7 @@ pub(crate) fn send_exit_events(
) {
for it in core::mem::take(&mut new_input_state.delayed_exit_items) {
let Some(item) = it.upgrade() else { continue };
item.borrow().as_ref().input_event(MouseEvent::Exit, window_adapter, &item);
item.borrow().as_ref().input_event(&MouseEvent::Exit, window_adapter, &item);
}
let mut clipped = false;
@ -649,13 +649,13 @@ pub(crate) fn send_exit_events(
if item.borrow().as_ref().clips_children() {
clipped = true;
}
item.borrow().as_ref().input_event(MouseEvent::Exit, window_adapter, &item);
item.borrow().as_ref().input_event(&MouseEvent::Exit, window_adapter, &item);
} else if new_input_state.item_stack.get(idx).map_or(true, |(x, _)| *x != it.0) {
// The item is still under the mouse, but no longer in the item stack. We should also sent the exit event, unless we delay it
if new_input_state.delayed.is_some() {
new_input_state.delayed_exit_items.push(it.0.clone());
} else {
item.borrow().as_ref().input_event(MouseEvent::Exit, window_adapter, &item);
item.borrow().as_ref().input_event(&MouseEvent::Exit, window_adapter, &item);
}
}
}
@ -666,7 +666,7 @@ pub(crate) fn send_exit_events(
/// Returns a new mouse grabber stack.
pub fn process_mouse_input(
root: ItemRc,
mouse_event: MouseEvent,
mouse_event: &MouseEvent,
window_adapter: &Rc<dyn WindowAdapter>,
mouse_input_state: MouseInputState,
) -> MouseInputState {
@ -694,7 +694,7 @@ pub fn process_mouse_input(
// An accepted wheel event might have moved things. Send a move event at the position to reset the has-hover
return process_mouse_input(
root,
MouseEvent::Moved { position },
&MouseEvent::Moved { position: *position },
window_adapter,
result,
);
@ -722,7 +722,7 @@ pub(crate) fn process_delayed_event(
let mut actual_visitor =
|component: &ItemTreeRc, index: u32, _: Pin<ItemRef>| -> VisitChildrenResult {
send_mouse_event_to_item(
event,
&event,
ItemRc::new(component.clone(), index),
window_adapter,
&mut mouse_input_state,
@ -740,7 +740,7 @@ pub(crate) fn process_delayed_event(
}
fn send_mouse_event_to_item(
mouse_event: MouseEvent,
mouse_event: &MouseEvent,
item_rc: ItemRc,
window_adapter: &Rc<dyn WindowAdapter>,
result: &mut MouseInputState,
@ -750,14 +750,14 @@ fn send_mouse_event_to_item(
let item = item_rc.borrow();
let geom = item_rc.geometry();
// translated in our coordinate
let mut event_for_children = mouse_event;
let mut event_for_children = mouse_event.clone();
event_for_children.translate(-geom.origin.to_vector());
let filter_result = if mouse_event.position().is_some_and(|p| geom.contains(p))
|| item.as_ref().clips_children()
{
item.as_ref().input_event_filter_before_children(
event_for_children,
&event_for_children,
window_adapter,
&item_rc,
)
@ -796,7 +796,7 @@ fn send_mouse_event_to_item(
let mut actual_visitor =
|component: &ItemTreeRc, index: u32, _: Pin<ItemRef>| -> VisitChildrenResult {
send_mouse_event_to_item(
event_for_children,
&event_for_children,
ItemRc::new(component.clone(), index),
window_adapter,
result,
@ -818,12 +818,12 @@ fn send_mouse_event_to_item(
let r = if ignore {
InputEventResult::EventIgnored
} else {
let mut event = mouse_event;
let mut event = mouse_event.clone();
event.translate(-geom.origin.to_vector());
if last_top_item.map_or(true, |x| *x != item_rc) {
event.set_click_count(0);
}
item.as_ref().input_event(event, window_adapter, &item_rc)
item.as_ref().input_event(&event, window_adapter, &item_rc)
};
match r {
InputEventResult::EventAccepted => VisitChildrenResult::abort(item_rc.index(), 0),

View file

@ -141,7 +141,7 @@ pub struct ItemVTable {
/// on this item again.
pub input_event_filter_before_children: extern "C" fn(
core::pin::Pin<VRef<ItemVTable>>,
MouseEvent,
&MouseEvent,
window_adapter: &WindowAdapterRc,
self_rc: &ItemRc,
) -> InputEventFilterResult,
@ -149,7 +149,7 @@ pub struct ItemVTable {
/// Handle input event for mouse and touch event
pub input_event: extern "C" fn(
core::pin::Pin<VRef<ItemVTable>>,
MouseEvent,
&MouseEvent,
window_adapter: &WindowAdapterRc,
self_rc: &ItemRc,
) -> InputEventResult,
@ -211,7 +211,7 @@ impl Item for Empty {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -220,7 +220,7 @@ impl Item for Empty {
fn input_event(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventResult {
@ -303,7 +303,7 @@ impl Item for Rectangle {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -312,7 +312,7 @@ impl Item for Rectangle {
fn input_event(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventResult {
@ -404,7 +404,7 @@ impl Item for BasicBorderRectangle {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -413,7 +413,7 @@ impl Item for BasicBorderRectangle {
fn input_event(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventResult {
@ -518,7 +518,7 @@ impl Item for BorderRectangle {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -527,7 +527,7 @@ impl Item for BorderRectangle {
fn input_event(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventResult {
@ -647,7 +647,7 @@ impl Item for Clip {
fn input_event_filter_before_children(
self: Pin<&Self>,
event: MouseEvent,
event: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -667,7 +667,7 @@ impl Item for Clip {
fn input_event(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventResult {
@ -759,7 +759,7 @@ impl Item for Opacity {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -768,7 +768,7 @@ impl Item for Opacity {
fn input_event(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventResult {
@ -877,7 +877,7 @@ impl Item for Layer {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -886,7 +886,7 @@ impl Item for Layer {
fn input_event(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventResult {
@ -970,7 +970,7 @@ impl Item for Rotate {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -979,7 +979,7 @@ impl Item for Rotate {
fn input_event(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventResult {
@ -1115,7 +1115,7 @@ impl Item for WindowItem {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -1124,7 +1124,7 @@ impl Item for WindowItem {
fn input_event(
self: Pin<&Self>,
_event: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventResult {
@ -1331,7 +1331,7 @@ impl Item for ContextMenu {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -1340,7 +1340,7 @@ impl Item for ContextMenu {
fn input_event(
self: Pin<&Self>,
event: MouseEvent,
event: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventResult {
@ -1356,6 +1356,7 @@ impl Item for ContextMenu {
MouseEvent::Pressed { position, button: PointerEventButton::Left, .. } => {
let timer = crate::timers::Timer::default();
let self_weak = _self_rc.downgrade();
let position = *position;
timer.start(
crate::timers::TimerMode::SingleShot,
WindowInner::from_pub(_window_adapter.window())
@ -1365,7 +1366,7 @@ impl Item for ContextMenu {
move || {
let Some(self_rc) = self_weak.upgrade() else { return };
let Some(self_) = self_rc.downcast::<ContextMenu>() else { return };
self_.show.call(&(crate::api::LogicalPosition::from_euclid(position),));
self_.show.call(&(LogicalPosition::from_euclid(position),));
},
);
self.long_press_timer.set(Some(timer));
@ -1515,7 +1516,7 @@ impl Item for BoxShadow {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -1524,7 +1525,7 @@ impl Item for BoxShadow {
fn input_event(
self: Pin<&Self>,
_event: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventResult {

View file

@ -182,7 +182,7 @@ impl Item for ComponentContainer {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -191,7 +191,7 @@ impl Item for ComponentContainer {
fn input_event(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventResult {

View file

@ -106,7 +106,7 @@ impl Item for Flickable {
fn input_event_filter_before_children(
self: Pin<&Self>,
event: MouseEvent,
event: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -128,7 +128,7 @@ impl Item for Flickable {
fn input_event(
self: Pin<&Self>,
event: MouseEvent,
event: &MouseEvent,
window_adapter: &Rc<dyn WindowAdapter>,
self_rc: &ItemRc,
) -> InputEventResult {
@ -253,13 +253,13 @@ impl FlickableData {
fn handle_mouse_filter(
&self,
flick: Pin<&Flickable>,
event: MouseEvent,
event: &MouseEvent,
flick_rc: &ItemRc,
) -> InputEventFilterResult {
let mut inner = self.inner.borrow_mut();
match event {
MouseEvent::Pressed { position, button: PointerEventButton::Left, .. } => {
inner.pressed_pos = position;
inner.pressed_pos = *position;
inner.pressed_time = Some(crate::animations::current_tick());
inner.pressed_viewport_pos = LogicalPoint::from_lengths(
(Flickable::FIELD_OFFSETS.viewport_x).apply_pin(flick).get(),
@ -288,7 +288,7 @@ impl FlickableData {
}
// Check if the mouse was moved more than the DISTANCE_THRESHOLD in a
// direction in which the flickable can flick
let diff = position - inner.pressed_pos;
let diff = *position - inner.pressed_pos;
let geo = flick_rc.geometry();
let w = geo.width_length();
let h = geo.height_length();
@ -319,7 +319,7 @@ impl FlickableData {
fn handle_mouse(
&self,
flick: Pin<&Flickable>,
event: MouseEvent,
event: &MouseEvent,
window_adapter: &Rc<dyn WindowAdapter>,
flick_rc: &ItemRc,
) -> InputEventResult {
@ -340,7 +340,7 @@ impl FlickableData {
}
MouseEvent::Moved { position } => {
if inner.pressed_time.is_some() {
let new_pos = inner.pressed_viewport_pos + (position - inner.pressed_pos);
let new_pos = inner.pressed_viewport_pos + (*position - inner.pressed_pos);
let x = (Flickable::FIELD_OFFSETS.viewport_x).apply_pin(flick);
let y = (Flickable::FIELD_OFFSETS.viewport_y).apply_pin(flick);
let should_capture = || {
@ -390,9 +390,9 @@ impl FlickableData {
&& !cfg!(target_os = "macos")
{
// Shift invert coordinate for the purpose of scrolling. But not on macOs because there the OS already take care of the change
LogicalVector::new(delta_y, delta_x)
LogicalVector::new(*delta_y, *delta_x)
} else {
LogicalVector::new(delta_x, delta_y)
LogicalVector::new(*delta_x, *delta_y)
};
let new_pos = ensure_in_bound(flick, old_pos + delta, flick_rc);
@ -412,7 +412,7 @@ impl FlickableData {
fn mouse_released(
inner: &mut FlickableDataInner,
flick: Pin<&Flickable>,
event: MouseEvent,
event: &MouseEvent,
flick_rc: &ItemRc,
) {
if let (Some(pressed_time), Some(pos)) = (inner.pressed_time, event.position()) {

View file

@ -66,7 +66,7 @@ impl Item for ImageItem {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -75,7 +75,7 @@ impl Item for ImageItem {
fn input_event(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventResult {
@ -217,7 +217,7 @@ impl Item for ClippedImage {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -226,7 +226,7 @@ impl Item for ClippedImage {
fn input_event(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventResult {

View file

@ -67,7 +67,7 @@ impl Item for TouchArea {
fn input_event_filter_before_children(
self: Pin<&Self>,
event: MouseEvent,
event: &MouseEvent,
window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -99,7 +99,7 @@ impl Item for TouchArea {
fn input_event(
self: Pin<&Self>,
event: MouseEvent,
event: &MouseEvent,
window_adapter: &Rc<dyn WindowAdapter>,
self_rc: &ItemRc,
) -> InputEventResult {
@ -116,13 +116,13 @@ impl Item for TouchArea {
match event {
MouseEvent::Pressed { position, button, .. } => {
self.grabbed.set(true);
if button == PointerEventButton::Left {
if *button == PointerEventButton::Left {
Self::FIELD_OFFSETS.pressed_x.apply_pin(self).set(position.x_length());
Self::FIELD_OFFSETS.pressed_y.apply_pin(self).set(position.y_length());
Self::FIELD_OFFSETS.pressed.apply_pin(self).set(true);
}
Self::FIELD_OFFSETS.pointer_event.apply_pin(self).call(&(PointerEvent {
button,
button: *button,
kind: PointerEventKind::Down,
modifiers: window_adapter.window().0.modifiers.get().into(),
},));
@ -144,8 +144,8 @@ impl Item for TouchArea {
MouseEvent::Released { button, position, click_count } => {
let geometry = self_rc.geometry();
if button == PointerEventButton::Left
&& LogicalRect::new(LogicalPoint::default(), geometry.size).contains(position)
if *button == PointerEventButton::Left
&& LogicalRect::new(LogicalPoint::default(), geometry.size).contains(*position)
&& self.pressed()
{
Self::FIELD_OFFSETS.clicked.apply_pin(self).call(&());
@ -155,11 +155,11 @@ impl Item for TouchArea {
}
self.grabbed.set(false);
if button == PointerEventButton::Left {
if *button == PointerEventButton::Left {
Self::FIELD_OFFSETS.pressed.apply_pin(self).set(false);
}
Self::FIELD_OFFSETS.pointer_event.apply_pin(self).call(&(PointerEvent {
button,
button: *button,
kind: PointerEventKind::Up,
modifiers: window_adapter.window().0.modifiers.get().into(),
},));
@ -181,10 +181,12 @@ impl Item for TouchArea {
}
MouseEvent::Wheel { delta_x, delta_y, .. } => {
let modifiers = window_adapter.window().0.modifiers.get().into();
let r = Self::FIELD_OFFSETS
.scroll_event
.apply_pin(self)
.call(&(PointerScrollEvent { delta_x, delta_y, modifiers },));
let r =
Self::FIELD_OFFSETS.scroll_event.apply_pin(self).call(&(PointerScrollEvent {
delta_x: *delta_x,
delta_y: *delta_y,
modifiers,
},));
if self.grabbed.get() {
InputEventResult::GrabMouse
} else {
@ -282,7 +284,7 @@ impl Item for FocusScope {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -291,7 +293,7 @@ impl Item for FocusScope {
fn input_event(
self: Pin<&Self>,
event: MouseEvent,
event: &MouseEvent,
window_adapter: &Rc<dyn WindowAdapter>,
self_rc: &ItemRc,
) -> InputEventResult {
@ -425,7 +427,7 @@ impl Item for SwipeGestureHandler {
fn input_event_filter_before_children(
self: Pin<&Self>,
event: MouseEvent,
event: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -441,7 +443,7 @@ impl Item for SwipeGestureHandler {
Self::FIELD_OFFSETS
.pressed_position
.apply_pin(self)
.set(crate::lengths::logical_position_to_api(position));
.set(crate::lengths::logical_position_to_api(*position));
self.pressed.set(true);
InputEventFilterResult::DelayForwarding(
super::flickable::FORWARD_DELAY.as_millis() as _
@ -490,7 +492,7 @@ impl Item for SwipeGestureHandler {
fn input_event(
self: Pin<&Self>,
event: MouseEvent,
event: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventResult {
@ -504,7 +506,7 @@ impl Item for SwipeGestureHandler {
if !self.pressed.get() && !self.swiping() {
return InputEventResult::EventIgnored;
}
self.current_position.set(crate::lengths::logical_position_to_api(position));
self.current_position.set(crate::lengths::logical_position_to_api(*position));
self.pressed.set(false);
if self.swiping() {
Self::FIELD_OFFSETS.swiping.apply_pin(self).set(false);
@ -518,7 +520,7 @@ impl Item for SwipeGestureHandler {
if !self.pressed.get() {
return InputEventResult::EventIgnored;
}
self.current_position.set(crate::lengths::logical_position_to_api(position));
self.current_position.set(crate::lengths::logical_position_to_api(*position));
if !self.swiping() {
let pressed_pos = self.pressed_position();
let dx = position.x - pressed_pos.x as Coord;

View file

@ -18,8 +18,7 @@ use crate::item_rendering::CachedRenderingData;
use crate::layout::{LayoutInfo, Orientation};
use crate::lengths::{
LogicalBorderRadius, LogicalLength, LogicalRect, LogicalSize, LogicalVector, PointLengths,
RectLengths,
LogicalBorderRadius, LogicalLength, LogicalRect, LogicalSize, LogicalVector, RectLengths,
};
#[cfg(feature = "rtti")]
use crate::rtti::*;
@ -65,27 +64,16 @@ impl Item for Path {
fn input_event_filter_before_children(
self: Pin<&Self>,
event: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
self_rc: &ItemRc,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
if let Some(pos) = event.position() {
let geometry = self_rc.geometry();
if self.clip()
&& (pos.x < 0 as _
|| pos.y < 0 as _
|| pos.x_length() > geometry.width_length()
|| pos.y_length() > geometry.height_length())
{
return InputEventFilterResult::Intercept;
}
}
InputEventFilterResult::ForwardAndIgnore
}
fn input_event(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventResult {

View file

@ -83,7 +83,7 @@ impl Item for ComplexText {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -92,7 +92,7 @@ impl Item for ComplexText {
fn input_event(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventResult {
@ -245,7 +245,7 @@ impl Item for SimpleText {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -254,7 +254,7 @@ impl Item for SimpleText {
fn input_event(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventResult {
@ -574,7 +574,7 @@ impl Item for TextInput {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: MouseEvent,
_: &MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> InputEventFilterResult {
@ -583,7 +583,7 @@ impl Item for TextInput {
fn input_event(
self: Pin<&Self>,
event: MouseEvent,
event: &MouseEvent,
window_adapter: &Rc<dyn WindowAdapter>,
self_rc: &ItemRc,
) -> InputEventResult {
@ -593,7 +593,7 @@ impl Item for TextInput {
match event {
MouseEvent::Pressed { position, button: PointerEventButton::Left, click_count } => {
let clicked_offset =
self.byte_offset_for_position(position, window_adapter, self_rc) as i32;
self.byte_offset_for_position(*position, window_adapter, self_rc) as i32;
self.as_ref().pressed.set((click_count % 3) + 1);
if !window_adapter.window().0.modifiers.get().shift() {
@ -630,7 +630,7 @@ impl Item for TextInput {
}
MouseEvent::Released { position, button: PointerEventButton::Middle, .. } => {
let clicked_offset =
self.byte_offset_for_position(position, window_adapter, self_rc) as i32;
self.byte_offset_for_position(*position, window_adapter, self_rc) as i32;
self.as_ref().anchor_position_byte_offset.set(clicked_offset);
self.set_cursor_position(
clicked_offset,
@ -655,7 +655,7 @@ impl Item for TextInput {
let pressed = self.as_ref().pressed.get();
if pressed > 0 {
let clicked_offset =
self.byte_offset_for_position(position, window_adapter, self_rc) as i32;
self.byte_offset_for_position(*position, window_adapter, self_rc) as i32;
self.set_cursor_position(
clicked_offset,
true,

View file

@ -162,7 +162,7 @@ impl crate::items::Item for MenuItem {
fn input_event_filter_before_children(
self: Pin<&Self>,
_: crate::input::MouseEvent,
_: &crate::input::MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> crate::input::InputEventFilterResult {
@ -171,7 +171,7 @@ impl crate::items::Item for MenuItem {
fn input_event(
self: Pin<&Self>,
_: crate::input::MouseEvent,
_: &crate::input::MouseEvent,
_window_adapter: &Rc<dyn WindowAdapter>,
_self_rc: &ItemRc,
) -> crate::input::InputEventResult {

View file

@ -647,7 +647,7 @@ impl WindowInner {
});
mouse_input_state = if let Some(mut event) =
crate::input::handle_mouse_grab(event, &window_adapter, &mut mouse_input_state)
crate::input::handle_mouse_grab(&event, &window_adapter, &mut mouse_input_state)
{
let mut item_tree = self.component.borrow().upgrade();
let mut offset = LogicalPoint::default();
@ -697,7 +697,7 @@ impl WindowInner {
event.translate(-offset.to_vector());
let mut new_input_state = crate::input::process_mouse_input(
root,
event,
&event,
&window_adapter,
mouse_input_state,
);
@ -1862,10 +1862,10 @@ pub mod ffi {
#[unsafe(no_mangle)]
pub unsafe extern "C" fn slint_windowrc_dispatch_pointer_event(
handle: *const WindowAdapterRcOpaque,
event: crate::input::MouseEvent,
event: &crate::input::MouseEvent,
) {
let window_adapter = &*(handle as *const Rc<dyn WindowAdapter>);
window_adapter.window().0.process_mouse_input(event);
window_adapter.window().0.process_mouse_input(event.clone());
}
/// Dispatch a window event