diff --git a/Cargo.lock b/Cargo.lock index 42b1d320ff..55552d81fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4545,21 +4545,23 @@ dependencies = [ [[package]] name = "ui-events" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4c2cc34489c685d4e7a1a1f97b7b4416c5aa789892114ae77df6cd2a60f0ec4" +checksum = "8a57da61c5700db75d28822c56068295055ec216996560af57a5d4a457914d34" dependencies = [ "dpi", "keyboard-types", + "kurbo", ] [[package]] name = "ui-events-winit" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61de84ebdb9c2e756d18fcd378802b5a0d359863fcee3ced54ac2d2fbb19cf74" +checksum = "e3ef6b086ceb9e4bbf0148e494959b18cf08de7604f8d8e958a94e73fc2d531e" dependencies = [ "ui-events", + "web-time", "winit", ] diff --git a/Cargo.toml b/Cargo.toml index ad8a17af7f..4f8f261e2f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,8 +54,8 @@ parley = { version = "0.6.0", features = ["accesskit"] } peniko = "0.5.0" winit = "0.30.12" tracing = { version = "0.1.41", default-features = false } -ui-events = "0.1.0" -ui-events-winit = "0.1.0" +ui-events = { version = "0.2.0", default-features = false, features = ["kurbo"] } +ui-events-winit = { version = "0.2.0", default-features = false } smallvec = "1.15.1" hashbrown = "0.16.0" dpi = "0.1.2" diff --git a/masonry/examples/layers.rs b/masonry/examples/layers.rs index 68474c073f..c3a73d2159 100644 --- a/masonry/examples/layers.rs +++ b/masonry/examples/layers.rs @@ -9,8 +9,8 @@ use masonry::accesskit::{Node, Role}; use masonry::core::{ AccessCtx, BoxConstraints, ChildrenIds, ErasedAction, EventCtx, LayoutCtx, NewWidget, NoAction, - PaintCtx, PointerEvent, PropertiesMut, PropertiesRef, RegisterCtx, StyleProperty, Update, - UpdateCtx, Widget, WidgetId, WidgetMut, WidgetPod, + PaintCtx, PointerEvent, PointerUpdate, PropertiesMut, PropertiesRef, RegisterCtx, + StyleProperty, Update, UpdateCtx, Widget, WidgetId, WidgetMut, WidgetPod, }; use masonry::kurbo::{Point, Size}; use masonry::parley::FontWeight; @@ -74,10 +74,10 @@ impl Widget for OverlayBox { _props: &mut PropertiesMut<'_>, event: &PointerEvent, ) { - if let PointerEvent::Move(e) = event + if let PointerEvent::Move(PointerUpdate { current, .. }) = event && ctx.is_hovered() { - let position = ctx.window_origin() + ctx.local_position(e.current.position).to_vec2(); + let position = current.logical_point(); if let Some(overlay_id) = self.layer_root_id { ctx.reposition_layer(overlay_id, position); } else { diff --git a/masonry/src/doc/color_rectangle.rs b/masonry/src/doc/color_rectangle.rs index d18f7020f7..2b3283c0e9 100644 --- a/masonry/src/doc/color_rectangle.rs +++ b/masonry/src/doc/color_rectangle.rs @@ -85,10 +85,7 @@ impl Widget for ColorRectangle { event: &PointerEvent, ) { match event { - PointerEvent::Down { - button: Some(PointerButton::Primary), - .. - } => { + PointerEvent::Down(b) if b.button == Some(PointerButton::Primary) => { ctx.submit_action::(ColorRectanglePress); } _ => {} diff --git a/masonry/src/widgets/button.rs b/masonry/src/widgets/button.rs index 2cdbff5ca4..6cfc271cce 100644 --- a/masonry/src/widgets/button.rs +++ b/masonry/src/widgets/button.rs @@ -17,8 +17,8 @@ use vello::peniko::Color; use crate::core::keyboard::{Key, NamedKey}; use crate::core::{ AccessCtx, AccessEvent, BoxConstraints, ChildrenIds, EventCtx, LayoutCtx, NewWidget, PaintCtx, - PointerEvent, PropertiesMut, PropertiesRef, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, - WidgetId, WidgetMut, WidgetPod, + PointerButtonEvent, PointerEvent, PropertiesMut, PropertiesRef, RegisterCtx, TextEvent, Update, + UpdateCtx, Widget, WidgetId, WidgetMut, WidgetPod, }; use crate::properties::{ ActiveBackground, Background, BorderColor, BorderWidth, BoxShadow, CornerRadius, @@ -112,13 +112,13 @@ impl Widget for Button { event: &PointerEvent, ) { match event { - PointerEvent::Down { .. } => { + PointerEvent::Down(..) => { ctx.capture_pointer(); // Changes in pointer capture impact appearance, but not accessibility node ctx.request_paint_only(); trace!("Button {:?} pressed", ctx.widget_id()); } - PointerEvent::Up { button, .. } => { + PointerEvent::Up(PointerButtonEvent { button, .. }) => { if ctx.is_active() && ctx.is_hovered() { ctx.submit_action::(ButtonPress { button: *button }); trace!("Button {:?} released", ctx.widget_id()); diff --git a/masonry/src/widgets/portal.rs b/masonry/src/widgets/portal.rs index 6ed8850a07..0b5d90814d 100644 --- a/masonry/src/widgets/portal.rs +++ b/masonry/src/widgets/portal.rs @@ -11,8 +11,9 @@ use vello::kurbo::{Point, Rect, Size, Vec2}; use crate::core::{ AccessCtx, AccessEvent, Axis, BoxConstraints, ChildrenIds, ComposeCtx, EventCtx, FromDynWidget, - LayoutCtx, NewWidget, NoAction, PaintCtx, PointerEvent, PropertiesMut, PropertiesRef, - RegisterCtx, ScrollDelta, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut, WidgetPod, + LayoutCtx, NewWidget, NoAction, PaintCtx, PointerEvent, PointerScrollEvent, PropertiesMut, + PropertiesRef, RegisterCtx, ScrollDelta, TextEvent, Update, UpdateCtx, Widget, WidgetId, + WidgetMut, WidgetPod, }; use crate::widgets::ScrollBar; @@ -270,7 +271,7 @@ impl Widget for Portal { let content_size = self.content_size; match *event { - PointerEvent::Scroll { delta, .. } => { + PointerEvent::Scroll(PointerScrollEvent { delta, .. }) => { // TODO - Remove reference to scale factor. // See https://github.com/linebender/xilem/issues/1264 let delta = match delta { diff --git a/masonry/src/widgets/scroll_bar.rs b/masonry/src/widgets/scroll_bar.rs index 539862df66..355d71f895 100644 --- a/masonry/src/widgets/scroll_bar.rs +++ b/masonry/src/widgets/scroll_bar.rs @@ -8,8 +8,8 @@ use vello::kurbo::{Point, Rect, Size}; use crate::core::{ AccessCtx, AccessEvent, AllowRawMut, Axis, BoxConstraints, ChildrenIds, EventCtx, LayoutCtx, - NoAction, PaintCtx, PointerEvent, PropertiesMut, PropertiesRef, RegisterCtx, TextEvent, Update, - UpdateCtx, Widget, WidgetId, WidgetMut, + NoAction, PaintCtx, PointerButtonEvent, PointerEvent, PointerUpdate, PropertiesMut, + PropertiesRef, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut, }; use crate::theme; use crate::util::{fill_color, include_screenshot, stroke}; @@ -129,7 +129,7 @@ impl Widget for ScrollBar { event: &PointerEvent, ) { match event { - PointerEvent::Down { state, .. } => { + PointerEvent::Down(PointerButtonEvent { state, .. }) => { ctx.capture_pointer(); let cursor_min_length = theme::SCROLLBAR_MIN_SIZE; @@ -147,20 +147,20 @@ impl Widget for ScrollBar { }; ctx.request_render(); } - PointerEvent::Move(u) => { + PointerEvent::Move(PointerUpdate { current, .. }) => { if let Some(grab_anchor) = self.grab_anchor { let cursor_min_length = theme::SCROLLBAR_MIN_SIZE; self.cursor_progress = self.progress_from_mouse_pos( ctx.size(), cursor_min_length, grab_anchor, - ctx.local_position(u.current.position), + ctx.local_position(current.position), ); self.moved = true; } ctx.request_render(); } - PointerEvent::Up { .. } | PointerEvent::Cancel(..) => { + PointerEvent::Up(..) | PointerEvent::Cancel(..) => { self.grab_anchor = None; ctx.request_render(); } diff --git a/masonry/src/widgets/slider.rs b/masonry/src/widgets/slider.rs index 16c8c2a1b1..a0393f93fc 100644 --- a/masonry/src/widgets/slider.rs +++ b/masonry/src/widgets/slider.rs @@ -14,8 +14,8 @@ use vello::kurbo::{Circle, Point, Rect, Size}; use crate::core::keyboard::{Key, NamedKey}; use crate::core::{ AccessCtx, AccessEvent, BoxConstraints, ChildrenIds, EventCtx, HasProperty, LayoutCtx, - PaintCtx, PointerEvent, PropertiesMut, PropertiesRef, RegisterCtx, TextEvent, Update, - UpdateCtx, Widget, WidgetId, WidgetMut, + PaintCtx, PointerButtonEvent, PointerEvent, PointerUpdate, PropertiesMut, PropertiesRef, + RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut, }; use crate::properties::{Background, BarColor, ThumbColor, ThumbRadius, TrackThickness}; use crate::theme; @@ -154,11 +154,11 @@ impl Widget for Slider { return; } match event { - PointerEvent::Down { + PointerEvent::Down(PointerButtonEvent { button: Some(PointerButton::Primary), state, .. - } => { + }) => { ctx.request_focus(); ctx.capture_pointer(); let local_pos = ctx.local_position(state.position); @@ -171,9 +171,9 @@ impl Widget for Slider { ctx.submit_action::(self.value); } } - PointerEvent::Move(e) => { + PointerEvent::Move(PointerUpdate { current, .. }) => { if ctx.is_active() { - let local_pos = ctx.local_position(e.current.position); + let local_pos = ctx.local_position(current.position); if self.update_value_from_position( local_pos.x, ctx.size().width, @@ -185,10 +185,10 @@ impl Widget for Slider { ctx.request_render(); } } - PointerEvent::Up { + PointerEvent::Up(PointerButtonEvent { button: Some(PointerButton::Primary), .. - } => { + }) => { if ctx.is_active() { ctx.release_pointer(); } diff --git a/masonry/src/widgets/split.rs b/masonry/src/widgets/split.rs index 62ea279bac..5c2b46b8d7 100644 --- a/masonry/src/widgets/split.rs +++ b/masonry/src/widgets/split.rs @@ -10,8 +10,9 @@ use vello::kurbo::{Line, Point, Rect, Size}; use crate::core::{ AccessCtx, AccessEvent, Axis, BoxConstraints, ChildrenIds, CursorIcon, EventCtx, FromDynWidget, - LayoutCtx, NewWidget, NoAction, PaintCtx, PointerEvent, PropertiesMut, PropertiesRef, QueryCtx, - RegisterCtx, TextEvent, Widget, WidgetId, WidgetMut, WidgetPod, + LayoutCtx, NewWidget, NoAction, PaintCtx, PointerButtonEvent, PointerEvent, PointerUpdate, + PropertiesMut, PropertiesRef, QueryCtx, RegisterCtx, TextEvent, Widget, WidgetId, WidgetMut, + WidgetPod, }; use crate::peniko::Color; use crate::properties::types::{AsUnit, Length}; @@ -395,7 +396,7 @@ where ) { if self.draggable { match event { - PointerEvent::Down { state, .. } => { + PointerEvent::Down(PointerButtonEvent { state, .. }) => { let pos = ctx.local_position(state.position); if self.bar_hit_test(ctx.size(), pos) { ctx.set_handled(); @@ -407,9 +408,9 @@ where } - self.bar_position(ctx.size()); } } - PointerEvent::Move(u) => { + PointerEvent::Move(PointerUpdate { current, .. }) => { if ctx.is_active() { - let pos = ctx.local_position(u.current.position); + let pos = ctx.local_position(current.position); // If widget has pointer capture, assume always it's hovered let effective_pos = match self.split_axis { Axis::Horizontal => Point { diff --git a/masonry/src/widgets/text_area.rs b/masonry/src/widgets/text_area.rs index f1f4fbe639..7e022bf741 100644 --- a/masonry/src/widgets/text_area.rs +++ b/masonry/src/widgets/text_area.rs @@ -16,9 +16,9 @@ use vello::peniko::Fill; use crate::core::keyboard::{Key, KeyState, NamedKey}; use crate::core::{ AccessCtx, AccessEvent, BoxConstraints, BrushIndex, ChildrenIds, CursorIcon, EventCtx, Ime, - LayoutCtx, PaintCtx, PointerButton, PointerEvent, PropertiesMut, PropertiesRef, QueryCtx, - RegisterCtx, StyleProperty, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut, - render_text, + LayoutCtx, PaintCtx, PointerButton, PointerButtonEvent, PointerEvent, PointerUpdate, + PropertiesMut, PropertiesRef, QueryCtx, RegisterCtx, StyleProperty, TextEvent, Update, + UpdateCtx, Widget, WidgetId, WidgetMut, render_text, }; use crate::properties::{ CaretColor, ContentColor, DisabledContentColor, SelectionColor, UnfocusedSelectionColor, @@ -493,37 +493,39 @@ impl Widget for TextArea { } match event { - PointerEvent::Down { button, state, .. } => { - if matches!(button, None | Some(PointerButton::Primary)) { - let cursor_pos = ctx.local_position(state.position); - let (fctx, lctx) = ctx.text_contexts(); - let mut drv = self.editor.driver(fctx, lctx); - match state.count { - 2 => drv.select_word_at_point(cursor_pos.x as f32, cursor_pos.y as f32), - 3 => { - drv.select_hard_line_at_point(cursor_pos.x as f32, cursor_pos.y as f32); - } - _ => { - if state.modifiers.shift() { - drv.shift_click_extension(cursor_pos.x as f32, cursor_pos.y as f32); - } else { - drv.move_to_point(cursor_pos.x as f32, cursor_pos.y as f32); - } - } + PointerEvent::Down(PointerButtonEvent { + button: None | Some(PointerButton::Primary), + state, + .. + }) => { + let cursor_pos = ctx.local_position(state.position); + let (fctx, lctx) = ctx.text_contexts(); + let mut drv = self.editor.driver(fctx, lctx); + match state.count { + 2 => drv.select_word_at_point(cursor_pos.x as f32, cursor_pos.y as f32), + 3 => { + drv.select_hard_line_at_point(cursor_pos.x as f32, cursor_pos.y as f32); } - let new_generation = self.editor.generation(); - if new_generation != self.rendered_generation { - ctx.request_render(); - ctx.set_ime_area(self.ime_area()); - self.rendered_generation = new_generation; + _ => { + if state.modifiers.shift() { + drv.shift_click_extension(cursor_pos.x as f32, cursor_pos.y as f32); + } else { + drv.move_to_point(cursor_pos.x as f32, cursor_pos.y as f32); + } } - ctx.request_focus(); - ctx.capture_pointer(); } + let new_generation = self.editor.generation(); + if new_generation != self.rendered_generation { + ctx.request_render(); + ctx.set_ime_area(self.ime_area()); + self.rendered_generation = new_generation; + } + ctx.request_focus(); + ctx.capture_pointer(); } - PointerEvent::Move(u) => { + PointerEvent::Move(PointerUpdate { current, .. }) => { if ctx.is_active() { - let cursor_pos = ctx.local_position(u.current.position); + let cursor_pos = ctx.local_position(current.position); let (fctx, lctx) = ctx.text_contexts(); self.editor .driver(fctx, lctx) diff --git a/masonry/src/widgets/virtual_scroll.rs b/masonry/src/widgets/virtual_scroll.rs index 55da8e2ab5..5203d688f0 100644 --- a/masonry/src/widgets/virtual_scroll.rs +++ b/masonry/src/widgets/virtual_scroll.rs @@ -10,9 +10,9 @@ use vello::kurbo::{Point, Size, Vec2}; use crate::core::keyboard::{Key, KeyState, NamedKey}; use crate::core::{ - AccessCtx, AccessEvent, BoxConstraints, ChildrenIds, ComposeCtx, EventCtx, LayoutCtx, - NewWidget, PaintCtx, PointerEvent, PropertiesMut, PropertiesRef, RegisterCtx, ScrollDelta, - TextEvent, Update, UpdateCtx, Widget, WidgetMut, WidgetPod, + AccessCtx, AccessEvent, BoxConstraints, ChildrenIds, ComposeCtx, EventCtx, KeyboardEvent, + LayoutCtx, NewWidget, PaintCtx, PointerEvent, PointerScrollEvent, PropertiesMut, PropertiesRef, + RegisterCtx, ScrollDelta, TextEvent, Update, UpdateCtx, Widget, WidgetMut, WidgetPod, }; use crate::util::debug_panic; @@ -524,7 +524,7 @@ impl Widget for VirtualScroll { event: &PointerEvent, ) { match event { - PointerEvent::Scroll { delta, .. } => { + PointerEvent::Scroll(PointerScrollEvent { delta, .. }) => { // TODO - Remove reference to scale factor. // See https://github.com/linebender/xilem/issues/1264 let delta = match delta { @@ -545,23 +545,33 @@ impl Widget for VirtualScroll { _props: &mut PropertiesMut<'_>, event: &TextEvent, ) { - match event { - TextEvent::Keyboard(key_event) => { - // To get to this state, you currently need to press "tab" to focus this widget in the example. - if matches!(key_event.state, KeyState::Down) { - // We use an unreasonably large delta (logical pixels) here to allow testing that the case where the - // scrolling "jumps" the area is handled correctly. - // In future, this manual testing would be achieved through use of a scrollbar. - let delta = 20000.; - if matches!(key_event.key, Key::Named(NamedKey::PageDown)) { - self.scroll_offset_from_anchor += delta; - self.event_post_scroll(ctx); - } - if matches!(key_event.key, Key::Named(NamedKey::PageUp)) { - self.scroll_offset_from_anchor -= delta; - self.event_post_scroll(ctx); - } - } + // We use an unreasonably large delta (logical pixels) here to allow testing that the case + // where the scrolling "jumps" the area is handled correctly. + // In future, this manual testing would be achieved through use of a scrollbar. + const DELTA: f64 = 20000.; + + // To get to this state, you currently need to press "tab" to focus this widget in the + // example. + let TextEvent::Keyboard(keyboard_event) = event else { + return; + }; + + match keyboard_event { + KeyboardEvent { + state: KeyState::Down, + key: Key::Named(NamedKey::PageDown), + .. + } => { + self.scroll_offset_from_anchor += DELTA; + self.event_post_scroll(ctx); + } + KeyboardEvent { + state: KeyState::Down, + key: Key::Named(NamedKey::PageUp), + .. + } => { + self.scroll_offset_from_anchor -= DELTA; + self.event_post_scroll(ctx); } _ => {} } @@ -1030,15 +1040,13 @@ fn opt_iter_difference( mod tests { use std::collections::HashSet; - use dpi::PhysicalPosition; + use kurbo::{Size, Vec2}; use parley::StyleProperty; - use vello::kurbo::Size; - use crate::core::{ - NewWidget, PointerEvent, PointerState, ScrollDelta, Widget, WidgetId, WidgetMut, - }; - use crate::testing::{PRIMARY_MOUSE, TestHarness, assert_render_snapshot}; + use crate::core::{NewWidget, Widget, WidgetId, WidgetMut}; + use crate::testing::{TestHarness, assert_render_snapshot}; use crate::theme::default_property_set; + use crate::vello::kurbo; use crate::widgets::{Label, VirtualScroll, VirtualScrollAction}; use super::opt_iter_difference; @@ -1114,11 +1122,7 @@ mod tests { drive_to_fixpoint(&mut harness, virtual_scroll_id, driver); assert_render_snapshot!(harness, "virtual_scroll_moved"); harness.mouse_move_to(virtual_scroll_id); - harness.process_pointer_event(PointerEvent::Scroll { - pointer: PRIMARY_MOUSE, - delta: ScrollDelta::PixelDelta(PhysicalPosition:: { x: 0., y: 25. }), - state: PointerState::default(), - }); + harness.mouse_wheel(Vec2 { x: 0., y: 25. }); drive_to_fixpoint(&mut harness, virtual_scroll_id, driver); assert_render_snapshot!(harness, "virtual_scroll_scrolled"); } @@ -1159,11 +1163,7 @@ mod tests { }); drive_to_fixpoint(&mut harness, virtual_scroll_id, driver); harness.mouse_move_to(virtual_scroll_id); - harness.process_pointer_event(PointerEvent::Scroll { - pointer: PRIMARY_MOUSE, - delta: ScrollDelta::PixelDelta(PhysicalPosition:: { x: 0., y: 200. }), - state: PointerState::default(), - }); + harness.mouse_wheel(Vec2 { x: 0., y: 200. }); drive_to_fixpoint(&mut harness, virtual_scroll_id, driver); } @@ -1203,11 +1203,7 @@ mod tests { }); drive_to_fixpoint(&mut harness, virtual_scroll_id, driver); harness.mouse_move_to(virtual_scroll_id); - harness.process_pointer_event(PointerEvent::Scroll { - pointer: PRIMARY_MOUSE, - delta: ScrollDelta::PixelDelta(PhysicalPosition:: { x: 0., y: 200. }), - state: PointerState::default(), - }); + harness.mouse_wheel(Vec2 { x: 0., y: 200. }); drive_to_fixpoint(&mut harness, virtual_scroll_id, driver); } @@ -1247,11 +1243,7 @@ mod tests { }); drive_to_fixpoint(&mut harness, virtual_scroll_id, driver); harness.mouse_move_to(virtual_scroll_id); - harness.process_pointer_event(PointerEvent::Scroll { - pointer: PRIMARY_MOUSE, - delta: ScrollDelta::PixelDelta(PhysicalPosition:: { x: 0., y: 200. }), - state: PointerState::default(), - }); + harness.mouse_wheel(Vec2 { x: 0., y: 200. }); drive_to_fixpoint(&mut harness, virtual_scroll_id, driver); } @@ -1306,22 +1298,14 @@ mod tests { original_range = widget.active_range.clone(); } harness.mouse_move_to(virtual_scroll_id); - harness.process_pointer_event(PointerEvent::Scroll { - pointer: PRIMARY_MOUSE, - delta: ScrollDelta::PixelDelta(PhysicalPosition:: { x: 0., y: -50. }), - state: PointerState::default(), - }); + harness.mouse_wheel(Vec2 { x: 0., y: -50. }); drive_to_fixpoint(&mut harness, virtual_scroll_id, driver); { let widget = harness.root_widget(); assert_ne!(widget.anchor_index, MIN); assert_ne!(widget.active_range, original_range); } - harness.process_pointer_event(PointerEvent::Scroll { - pointer: PRIMARY_MOUSE, - delta: ScrollDelta::PixelDelta(PhysicalPosition:: { x: 0., y: 60. }), - state: PointerState::default(), - }); + harness.mouse_wheel(Vec2 { x: 0., y: 60. }); drive_to_fixpoint(&mut harness, virtual_scroll_id, driver); { let widget = harness.root_widget(); @@ -1383,22 +1367,14 @@ mod tests { assert_render_snapshot!(harness, "virtual_scroll_limited_up_bottom"); } harness.mouse_move_to(virtual_scroll_id); - harness.process_pointer_event(PointerEvent::Scroll { - pointer: PRIMARY_MOUSE, - delta: ScrollDelta::PixelDelta(PhysicalPosition:: { x: 0., y: 5. }), - state: PointerState::default(), - }); + harness.mouse_wheel(Vec2 { x: 0., y: 5. }); drive_to_fixpoint(&mut harness, virtual_scroll_id, driver); { let widget = harness.root_widget(); assert_ne!(widget.anchor_index, MAX); assert_ne!(widget.active_range, original_range); } - harness.process_pointer_event(PointerEvent::Scroll { - pointer: PRIMARY_MOUSE, - delta: ScrollDelta::PixelDelta(PhysicalPosition:: { x: 0., y: -6. }), - state: PointerState::default(), - }); + harness.mouse_wheel(Vec2 { x: 0., y: -6. }); drive_to_fixpoint(&mut harness, virtual_scroll_id, driver); { let widget = harness.root_widget(); diff --git a/masonry_core/src/core/mod.rs b/masonry_core/src/core/mod.rs index 754bdf4e15..2d03601438 100644 --- a/masonry_core/src/core/mod.rs +++ b/masonry_core/src/core/mod.rs @@ -42,7 +42,8 @@ pub use widget_tag::WidgetTag; pub use ui_events::keyboard::{KeyboardEvent, Modifiers}; pub use ui_events::pointer::{ - PointerButton, PointerEvent, PointerId, PointerInfo, PointerState, PointerType, PointerUpdate, + PointerButton, PointerButtonEvent, PointerEvent, PointerGesture, PointerGestureEvent, + PointerId, PointerInfo, PointerScrollEvent, PointerState, PointerType, PointerUpdate, }; pub use ui_events::{ScrollDelta, keyboard, pointer}; diff --git a/masonry_core/src/passes/event.rs b/masonry_core/src/passes/event.rs index ae87fc6da9..360cfc5510 100644 --- a/masonry_core/src/passes/event.rs +++ b/masonry_core/src/passes/event.rs @@ -2,13 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 use tracing::{debug, info_span, trace}; -use ui_events::pointer::PointerType; use crate::app::{RenderRoot, RenderRootSignal}; use crate::core::keyboard::{Key, KeyState, NamedKey}; use crate::core::{ - AccessEvent, EventCtx, Handled, Ime, PointerEvent, PointerInfo, PointerUpdate, PropertiesMut, - TextEvent, Widget, WidgetId, + AccessEvent, EventCtx, Handled, Ime, PointerButtonEvent, PointerEvent, PointerGestureEvent, + PointerInfo, PointerScrollEvent, PointerType, PointerUpdate, PropertiesMut, TextEvent, Widget, + WidgetId, }; use crate::debug_panic; use crate::dpi::{LogicalPosition, PhysicalPosition}; @@ -48,23 +48,25 @@ fn is_very_frequent(e: &PointerEvent) -> bool { /// Short name for a [`PointerEvent`]. fn pointer_event_short_name(e: &PointerEvent) -> &'static str { match e { - PointerEvent::Down { .. } => "Down", - PointerEvent::Up { .. } => "Up", + PointerEvent::Down(..) => "Down", + PointerEvent::Up(..) => "Up", PointerEvent::Move(..) => "Move", PointerEvent::Enter(..) => "Enter", PointerEvent::Leave(..) => "Leave", PointerEvent::Cancel(..) => "Cancel", - PointerEvent::Scroll { .. } => "Scroll", + PointerEvent::Scroll(..) => "Scroll", + PointerEvent::Gesture(..) => "Gesture", } } /// A position if the event has one. fn try_event_position(event: &PointerEvent) -> Option> { match event { - PointerEvent::Down { state, .. } - | PointerEvent::Up { state, .. } + PointerEvent::Down(PointerButtonEvent { state, .. }) + | PointerEvent::Up(PointerButtonEvent { state, .. }) | PointerEvent::Move(PointerUpdate { current: state, .. }) - | PointerEvent::Scroll { state, .. } => Some(state.position), + | PointerEvent::Scroll(PointerScrollEvent { state, .. }) + | PointerEvent::Gesture(PointerGestureEvent { state, .. }) => Some(state.position), _ => None, } } diff --git a/masonry_testing/src/harness.rs b/masonry_testing/src/harness.rs index 5560b00342..2ae3fe5936 100644 --- a/masonry_testing/src/harness.rs +++ b/masonry_testing/src/harness.rs @@ -23,9 +23,9 @@ use masonry_core::app::{ }; use masonry_core::core::{ CursorIcon, DefaultProperties, ErasedAction, FromDynWidget, Handled, Ime, KeyboardEvent, - Modifiers, NewWidget, PointerButton, PointerEvent, PointerId, PointerInfo, PointerState, - PointerType, PointerUpdate, ScrollDelta, TextEvent, Widget, WidgetId, WidgetMut, WidgetRef, - WidgetTag, WindowEvent, + Modifiers, NewWidget, PointerButton, PointerButtonEvent, PointerEvent, PointerId, PointerInfo, + PointerScrollEvent, PointerState, PointerType, PointerUpdate, ScrollDelta, TextEvent, Widget, + WidgetId, WidgetMut, WidgetRef, WidgetTag, WindowEvent, }; use masonry_core::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize}; use masonry_core::kurbo::{Point, Size, Vec2}; @@ -601,30 +601,30 @@ impl TestHarness { /// Send a [`Down`](PointerEvent::Down) event to the window. pub fn mouse_button_press(&mut self, button: PointerButton) { self.mouse_state.buttons.insert(button); - self.process_pointer_event(PointerEvent::Down { + self.process_pointer_event(PointerEvent::Down(PointerButtonEvent { pointer: PRIMARY_MOUSE, button: button.into(), state: self.mouse_state.clone(), - }); + })); } /// Send an [`Up`](PointerEvent::Up) event to the window. pub fn mouse_button_release(&mut self, button: PointerButton) { self.mouse_state.buttons.remove(button); - self.process_pointer_event(PointerEvent::Up { + self.process_pointer_event(PointerEvent::Up(PointerButtonEvent { pointer: PRIMARY_MOUSE, button: button.into(), state: self.mouse_state.clone(), - }); + })); } /// Send a [`Scroll`](PointerEvent::Scroll) event to the window. pub fn mouse_wheel(&mut self, Vec2 { x, y }: Vec2) { - self.process_pointer_event(PointerEvent::Scroll { + self.process_pointer_event(PointerEvent::Scroll(PointerScrollEvent { pointer: PRIMARY_MOUSE, delta: ScrollDelta::PixelDelta(PhysicalPosition { x, y }), state: self.mouse_state.clone(), - }); + })); } /// Send events that lead to a given widget being clicked. diff --git a/masonry_winit/src/event_loop_runner.rs b/masonry_winit/src/event_loop_runner.rs index 4a6d00d23b..b0c44f1dac 100644 --- a/masonry_winit/src/event_loop_runner.rs +++ b/masonry_winit/src/event_loop_runner.rs @@ -658,7 +658,9 @@ impl MasonryState<'_> { is_synthetic: true, .. } - ) && let Some(wet) = window.event_reducer.reduce(&event) + ) && let Some(wet) = window + .event_reducer + .reduce(window.handle.scale_factor(), &event) { match wet { WindowEventTranslation::Keyboard(k) => {