Skip to content

Commit 8f7a566

Browse files
committed
Update to ui-events and ui-events-winit 0.2.0.
1 parent 906244d commit 8f7a566

File tree

11 files changed

+52
-88
lines changed

11 files changed

+52
-88
lines changed

Cargo.lock

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ parley = { version = "0.5.0", features = ["accesskit"] }
5252
peniko = "0.4.0"
5353
winit = "0.30.10"
5454
tracing = { version = "0.1.41", default-features = false }
55-
ui-events = "0.1.0"
56-
ui-events-winit = "0.1.0"
55+
ui-events = { git = "https://github.com/endoli/ui-events", rev = "6382e63" }
56+
ui-events-winit = { git = "https://github.com/endoli/ui-events", rev = "6382e63" }
5757
smallvec = "1.15.0"
5858
hashbrown = "0.15.3"
5959
dpi = "0.1.2"

masonry/src/widgets/button.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,17 @@ impl Widget for Button {
9797
event: &PointerEvent,
9898
) {
9999
match event {
100-
PointerEvent::Down { .. } => {
100+
PointerEvent::Down(..) => {
101101
if !ctx.is_disabled() {
102102
ctx.capture_pointer();
103103
// Changes in pointer capture impact appearance, but not accessibility node
104104
ctx.request_paint_only();
105105
trace!("Button {:?} pressed", ctx.widget_id());
106106
}
107107
}
108-
PointerEvent::Up { button, .. } => {
108+
PointerEvent::Up(b) => {
109109
if ctx.is_pointer_capture_target() && ctx.is_hovered() && !ctx.is_disabled() {
110-
ctx.submit_action(Action::ButtonPressed(*button));
110+
ctx.submit_action(Action::ButtonPressed(b.button));
111111
trace!("Button {:?} released", ctx.widget_id());
112112
}
113113
// Changes in pointer capture impact appearance, but not accessibility node

masonry/src/widgets/portal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ impl<W: Widget + FromDynWidget + ?Sized> Widget for Portal<W> {
274274
let content_size = ctx.get_raw_ref(&mut self.child).ctx().size();
275275

276276
match *event {
277-
PointerEvent::Scroll { delta, .. } => {
278-
let delta = match delta {
277+
PointerEvent::Scroll(ref s) => {
278+
let delta = match s.delta {
279279
ScrollDelta::PixelDelta(PhysicalPosition::<f64> { x, y }) => -Vec2 { x, y },
280280
ScrollDelta::LineDelta(x, y) => {
281281
-Vec2 {

masonry/src/widgets/scroll_bar.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ impl Widget for ScrollBar {
129129
event: &PointerEvent,
130130
) {
131131
match event {
132-
PointerEvent::Down { state, .. } => {
132+
PointerEvent::Down(b) => {
133133
ctx.capture_pointer();
134134

135135
let cursor_min_length = theme::SCROLLBAR_MIN_SIZE;
136136
let cursor_rect = self.get_cursor_rect(ctx.size(), cursor_min_length);
137-
let mouse_pos = ctx.local_position(state.position);
137+
let mouse_pos = ctx.local_position(b.state.position);
138138
if cursor_rect.contains(mouse_pos) {
139139
let (z0, z1) = self.axis.major_span(cursor_rect);
140140
let mouse_major = self.axis.major_pos(mouse_pos);
@@ -160,7 +160,7 @@ impl Widget for ScrollBar {
160160
}
161161
ctx.request_render();
162162
}
163-
PointerEvent::Up { .. } | PointerEvent::Cancel(..) => {
163+
PointerEvent::Up(..) | PointerEvent::Cancel(..) => {
164164
self.grab_anchor = None;
165165
ctx.request_render();
166166
}

masonry/src/widgets/split.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,8 @@ where
405405
) {
406406
if self.draggable {
407407
match event {
408-
PointerEvent::Down { state, .. } => {
409-
let pos = ctx.local_position(state.position);
408+
PointerEvent::Down(b) => {
409+
let pos = ctx.local_position(b.state.position);
410410
if self.bar_hit_test(ctx.size(), pos) {
411411
ctx.set_handled();
412412
ctx.capture_pointer();

masonry/src/widgets/text_area.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,12 +477,12 @@ impl<const EDITABLE: bool> Widget for TextArea<EDITABLE> {
477477
}
478478

479479
match event {
480-
PointerEvent::Down { button, state, .. } => {
481-
if !ctx.is_disabled() && matches!(button, None | Some(PointerButton::Primary)) {
482-
let cursor_pos = ctx.local_position(state.position);
480+
PointerEvent::Down(b) => {
481+
if !ctx.is_disabled() && matches!(b.button, None | Some(PointerButton::Primary)) {
482+
let cursor_pos = ctx.local_position(b.state.position);
483483
let (fctx, lctx) = ctx.text_contexts();
484484
let mut drv = self.editor.driver(fctx, lctx);
485-
match state.count {
485+
match b.state.count {
486486
2 => drv.select_word_at_point(cursor_pos.x as f32, cursor_pos.y as f32),
487487
3 => drv.select_line_at_point(cursor_pos.x as f32, cursor_pos.y as f32),
488488
_ => drv.move_to_point(cursor_pos.x as f32, cursor_pos.y as f32),

masonry/src/widgets/virtual_scroll.rs

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ impl<W: Widget + FromDynWidget + ?Sized> Widget for VirtualScroll<W> {
479479
event: &PointerEvent,
480480
) {
481481
match event {
482-
PointerEvent::Scroll { delta, .. } => {
483-
let delta = match delta {
482+
PointerEvent::Scroll(s) => {
483+
let delta = match s.delta {
484484
ScrollDelta::PixelDelta(p) => -p.to_logical::<f64>(ctx.get_scale_factor()).y,
485485
ScrollDelta::LineDelta(_, y) => -y as f64 * ctx.get_scale_factor() * 120.,
486486
_ => 0.0,
@@ -918,16 +918,13 @@ fn opt_iter_difference(
918918
mod tests {
919919
use std::collections::HashSet;
920920

921-
use dpi::PhysicalPosition;
921+
use kurbo::{Size, Vec2};
922922
use parley::StyleProperty;
923-
use vello::kurbo::Size;
924923

925-
use crate::core::{
926-
Action, FromDynWidget, PointerEvent, PointerState, ScrollDelta, Widget, WidgetId,
927-
WidgetMut, WidgetPod,
928-
};
929-
use crate::testing::{PRIMARY_MOUSE, TestHarness, assert_render_snapshot};
924+
use crate::core::{Action, FromDynWidget, Widget, WidgetId, WidgetMut, WidgetPod};
925+
use crate::testing::{TestHarness, assert_render_snapshot};
930926
use crate::theme::default_property_set;
927+
use crate::vello::kurbo;
931928
use crate::widgets::{Label, VirtualScroll, VirtualScrollAction};
932929

933930
use super::opt_iter_difference;
@@ -1005,11 +1002,7 @@ mod tests {
10051002
drive_to_fixpoint::<ScrollContents>(&mut harness, virtual_scroll_id, driver);
10061003
assert_render_snapshot!(harness, "virtual_scroll_moved");
10071004
harness.mouse_move_to(virtual_scroll_id);
1008-
harness.process_pointer_event(PointerEvent::Scroll {
1009-
pointer: PRIMARY_MOUSE,
1010-
delta: ScrollDelta::PixelDelta(PhysicalPosition::<f64> { x: 0., y: 25. }),
1011-
state: PointerState::default(),
1012-
});
1005+
harness.mouse_wheel(Vec2 { x: 0., y: 25. });
10131006
drive_to_fixpoint::<ScrollContents>(&mut harness, virtual_scroll_id, driver);
10141007
assert_render_snapshot!(harness, "virtual_scroll_scrolled");
10151008
}
@@ -1052,11 +1045,7 @@ mod tests {
10521045
});
10531046
drive_to_fixpoint::<ScrollContents>(&mut harness, virtual_scroll_id, driver);
10541047
harness.mouse_move_to(virtual_scroll_id);
1055-
harness.process_pointer_event(PointerEvent::Scroll {
1056-
pointer: PRIMARY_MOUSE,
1057-
delta: ScrollDelta::PixelDelta(PhysicalPosition::<f64> { x: 0., y: 200. }),
1058-
state: PointerState::default(),
1059-
});
1048+
harness.mouse_wheel(Vec2 { x: 0., y: 200. });
10601049
drive_to_fixpoint::<ScrollContents>(&mut harness, virtual_scroll_id, driver);
10611050
}
10621051

@@ -1098,11 +1087,7 @@ mod tests {
10981087
});
10991088
drive_to_fixpoint::<ScrollContents>(&mut harness, virtual_scroll_id, driver);
11001089
harness.mouse_move_to(virtual_scroll_id);
1101-
harness.process_pointer_event(PointerEvent::Scroll {
1102-
pointer: PRIMARY_MOUSE,
1103-
delta: ScrollDelta::PixelDelta(PhysicalPosition::<f64> { x: 0., y: 200. }),
1104-
state: PointerState::default(),
1105-
});
1090+
harness.mouse_wheel(Vec2 { x: 0., y: 200. });
11061091
drive_to_fixpoint::<ScrollContents>(&mut harness, virtual_scroll_id, driver);
11071092
}
11081093

@@ -1144,11 +1129,7 @@ mod tests {
11441129
});
11451130
drive_to_fixpoint::<ScrollContents>(&mut harness, virtual_scroll_id, driver);
11461131
harness.mouse_move_to(virtual_scroll_id);
1147-
harness.process_pointer_event(PointerEvent::Scroll {
1148-
pointer: PRIMARY_MOUSE,
1149-
delta: ScrollDelta::PixelDelta(PhysicalPosition::<f64> { x: 0., y: 200. }),
1150-
state: PointerState::default(),
1151-
});
1132+
harness.mouse_wheel(Vec2 { x: 0., y: 200. });
11521133
drive_to_fixpoint::<ScrollContents>(&mut harness, virtual_scroll_id, driver);
11531134
}
11541135

@@ -1205,11 +1186,7 @@ mod tests {
12051186
original_range = widget.active_range.clone();
12061187
}
12071188
harness.mouse_move_to(virtual_scroll_id);
1208-
harness.process_pointer_event(PointerEvent::Scroll {
1209-
pointer: PRIMARY_MOUSE,
1210-
delta: ScrollDelta::PixelDelta(PhysicalPosition::<f64> { x: 0., y: -50. }),
1211-
state: PointerState::default(),
1212-
});
1189+
harness.mouse_wheel(Vec2 { x: 0., y: -50. });
12131190
drive_to_fixpoint::<ScrollContents>(&mut harness, virtual_scroll_id, driver);
12141191
{
12151192
let widget = harness
@@ -1219,11 +1196,7 @@ mod tests {
12191196
assert_ne!(widget.anchor_index, MIN);
12201197
assert_ne!(widget.active_range, original_range);
12211198
}
1222-
harness.process_pointer_event(PointerEvent::Scroll {
1223-
pointer: PRIMARY_MOUSE,
1224-
delta: ScrollDelta::PixelDelta(PhysicalPosition::<f64> { x: 0., y: 60. }),
1225-
state: PointerState::default(),
1226-
});
1199+
harness.mouse_wheel(Vec2 { x: 0., y: 60. });
12271200
drive_to_fixpoint::<ScrollContents>(&mut harness, virtual_scroll_id, driver);
12281201
{
12291202
let widget = harness
@@ -1290,11 +1263,7 @@ mod tests {
12901263
assert_render_snapshot!(harness, "virtual_scroll_limited_up_bottom");
12911264
}
12921265
harness.mouse_move_to(virtual_scroll_id);
1293-
harness.process_pointer_event(PointerEvent::Scroll {
1294-
pointer: PRIMARY_MOUSE,
1295-
delta: ScrollDelta::PixelDelta(PhysicalPosition::<f64> { x: 0., y: 5. }),
1296-
state: PointerState::default(),
1297-
});
1266+
harness.mouse_wheel(Vec2 { x: 0., y: 5. });
12981267
drive_to_fixpoint::<ScrollContents>(&mut harness, virtual_scroll_id, driver);
12991268
{
13001269
let widget = harness
@@ -1304,11 +1273,7 @@ mod tests {
13041273
assert_ne!(widget.anchor_index, MAX);
13051274
assert_ne!(widget.active_range, original_range);
13061275
}
1307-
harness.process_pointer_event(PointerEvent::Scroll {
1308-
pointer: PRIMARY_MOUSE,
1309-
delta: ScrollDelta::PixelDelta(PhysicalPosition::<f64> { x: 0., y: -6. }),
1310-
state: PointerState::default(),
1311-
});
1276+
harness.mouse_wheel(Vec2 { x: 0., y: -6. });
13121277
drive_to_fixpoint::<ScrollContents>(&mut harness, virtual_scroll_id, driver);
13131278
{
13141279
let widget = harness

masonry_core/src/core/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ pub use widget_state::WidgetOptions;
3636

3737
pub use ui_events::keyboard::{KeyboardEvent, Modifiers};
3838
pub use ui_events::pointer::{
39-
PointerButton, PointerEvent, PointerId, PointerInfo, PointerState, PointerType, PointerUpdate,
39+
PointerButton, PointerButtonEvent, PointerEvent, PointerId, PointerInfo, PointerScrollEvent,
40+
PointerState, PointerType, PointerUpdate,
4041
};
4142
pub use ui_events::{ScrollDelta, keyboard, pointer};
4243

masonry_core/src/passes/event.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use tracing::{debug, info_span, trace};
5-
use ui_events::pointer::PointerType;
65

76
use crate::Handled;
87
use crate::app::{RenderRoot, RenderRootSignal};
98
use crate::core::keyboard::{Key, KeyState, NamedKey};
109
use crate::core::{
11-
AccessEvent, EventCtx, PointerEvent, PointerInfo, PointerUpdate, PropertiesMut, TextEvent,
12-
Widget, WidgetId,
10+
AccessEvent, EventCtx, PointerButtonEvent, PointerEvent, PointerInfo, PointerScrollEvent,
11+
PointerType, PointerUpdate, PropertiesMut, TextEvent, Widget, WidgetId,
1312
};
1413
use crate::debug_panic;
1514
use crate::dpi::{LogicalPosition, PhysicalPosition};
@@ -47,23 +46,23 @@ fn is_very_frequent(e: &PointerEvent) -> bool {
4746
/// Short name for a [`PointerEvent`].
4847
fn pointer_event_short_name(e: &PointerEvent) -> &'static str {
4948
match e {
50-
PointerEvent::Down { .. } => "Down",
51-
PointerEvent::Up { .. } => "Up",
49+
PointerEvent::Down(..) => "Down",
50+
PointerEvent::Up(..) => "Up",
5251
PointerEvent::Move(..) => "Move",
5352
PointerEvent::Enter(..) => "Enter",
5453
PointerEvent::Leave(..) => "Leave",
5554
PointerEvent::Cancel(..) => "Cancel",
56-
PointerEvent::Scroll { .. } => "Scroll",
55+
PointerEvent::Scroll(..) => "Scroll",
5756
}
5857
}
5958

6059
/// A position if the event has one.
6160
fn try_event_position(event: &PointerEvent) -> Option<PhysicalPosition<f64>> {
6261
match event {
63-
PointerEvent::Down { state, .. }
64-
| PointerEvent::Up { state, .. }
62+
PointerEvent::Down(PointerButtonEvent { state, .. })
63+
| PointerEvent::Up(PointerButtonEvent { state, .. })
6564
| PointerEvent::Move(PointerUpdate { current: state, .. })
66-
| PointerEvent::Scroll { state, .. } => Some(state.position),
65+
| PointerEvent::Scroll(PointerScrollEvent { state, .. }) => Some(state.position),
6766
_ => None,
6867
}
6968
}

0 commit comments

Comments
 (0)