Skip to content

Commit 5f27425

Browse files
committed
Use destructuring and descriptive names.
1 parent 43be4c9 commit 5f27425

File tree

11 files changed

+95
-76
lines changed

11 files changed

+95
-76
lines changed

Cargo.lock

Lines changed: 2 additions & 2 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
@@ -55,8 +55,8 @@ parley = { git = "https://github.com/linebender/parley", rev = "587b7634ae8601c1
5555
peniko = "0.4.0"
5656
winit = "0.30.10"
5757
tracing = { version = "0.1.41", default-features = false }
58-
ui-events = { git = "https://github.com/endoli/ui-events", rev = "6382e63" }
59-
ui-events-winit = { git = "https://github.com/endoli/ui-events", rev = "6382e63" }
58+
ui-events = { git = "https://github.com/endoli/ui-events", rev = "08c942c" }
59+
ui-events-winit = { git = "https://github.com/endoli/ui-events", rev = "08c942c" }
6060
smallvec = "1.15.0"
6161
hashbrown = "0.15.3"
6262
dpi = "0.1.2"

masonry/src/widgets/button.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use vello::peniko::Color;
1717
use crate::core::keyboard::{Key, NamedKey};
1818
use crate::core::{
1919
AccessCtx, AccessEvent, BoxConstraints, ChildrenIds, EventCtx, LayoutCtx, NewWidget, PaintCtx,
20-
PointerEvent, PropertiesMut, PropertiesRef, RegisterCtx, TextEvent, Update, UpdateCtx, Widget,
21-
WidgetId, WidgetMut, WidgetPod,
20+
PointerButtonEvent, PointerEvent, PropertiesMut, PropertiesRef, RegisterCtx, TextEvent, Update,
21+
UpdateCtx, Widget, WidgetId, WidgetMut, WidgetPod,
2222
};
2323
use crate::properties::{
2424
ActiveBackground, Background, BorderColor, BorderWidth, BoxShadow, CornerRadius,
@@ -118,9 +118,9 @@ impl Widget for Button {
118118
ctx.request_paint_only();
119119
trace!("Button {:?} pressed", ctx.widget_id());
120120
}
121-
PointerEvent::Up(b) => {
121+
PointerEvent::Up(PointerButtonEvent { button, .. }) => {
122122
if ctx.is_active() && ctx.is_hovered() {
123-
ctx.submit_action::<Self::Action>(ButtonPress { button: b.button });
123+
ctx.submit_action::<Self::Action>(ButtonPress { button: *button });
124124
trace!("Button {:?} released", ctx.widget_id());
125125
}
126126
// Changes in pointer capture impact appearance, but not accessibility node

masonry/src/widgets/portal.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ use vello::kurbo::{Point, Rect, Size, Vec2};
1111

1212
use crate::core::{
1313
AccessCtx, AccessEvent, Axis, BoxConstraints, ChildrenIds, ComposeCtx, EventCtx, FromDynWidget,
14-
LayoutCtx, NewWidget, NoAction, PaintCtx, PointerEvent, PropertiesMut, PropertiesRef,
15-
RegisterCtx, ScrollDelta, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut, WidgetPod,
14+
LayoutCtx, NewWidget, NoAction, PaintCtx, PointerEvent, PointerScrollEvent, PropertiesMut,
15+
PropertiesRef, RegisterCtx, ScrollDelta, TextEvent, Update, UpdateCtx, Widget, WidgetId,
16+
WidgetMut, WidgetPod,
1617
};
1718
use crate::widgets::ScrollBar;
1819

@@ -270,10 +271,10 @@ impl<W: Widget + FromDynWidget + ?Sized> Widget for Portal<W> {
270271
let content_size = self.content_size;
271272

272273
match *event {
273-
PointerEvent::Scroll(ref s) => {
274+
PointerEvent::Scroll(PointerScrollEvent { delta, .. }) => {
274275
// TODO - Remove reference to scale factor.
275276
// See https://github.com/linebender/xilem/issues/1264
276-
let delta = match s.delta {
277+
let delta = match delta {
277278
ScrollDelta::PixelDelta(PhysicalPosition::<f64> { x, y }) => -Vec2 { x, y },
278279
ScrollDelta::LineDelta(x, y) => {
279280
-Vec2 {

masonry/src/widgets/scroll_bar.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use vello::kurbo::{Point, Rect, Size};
88

99
use crate::core::{
1010
AccessCtx, AccessEvent, AllowRawMut, Axis, BoxConstraints, ChildrenIds, EventCtx, LayoutCtx,
11-
NoAction, PaintCtx, PointerEvent, PropertiesMut, PropertiesRef, RegisterCtx, TextEvent, Update,
12-
UpdateCtx, Widget, WidgetId, WidgetMut,
11+
NoAction, PaintCtx, PointerButtonEvent, PointerEvent, PointerUpdate, PropertiesMut,
12+
PropertiesRef, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut,
1313
};
1414
use crate::theme;
1515
use crate::util::{fill_color, include_screenshot, stroke};
@@ -129,12 +129,12 @@ impl Widget for ScrollBar {
129129
event: &PointerEvent,
130130
) {
131131
match event {
132-
PointerEvent::Down(b) => {
132+
PointerEvent::Down(PointerButtonEvent { state, .. }) => {
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(b.state.position);
137+
let mouse_pos = ctx.local_position(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);
@@ -147,14 +147,14 @@ impl Widget for ScrollBar {
147147
};
148148
ctx.request_render();
149149
}
150-
PointerEvent::Move(u) => {
150+
PointerEvent::Move(PointerUpdate { current, .. }) => {
151151
if let Some(grab_anchor) = self.grab_anchor {
152152
let cursor_min_length = theme::SCROLLBAR_MIN_SIZE;
153153
self.cursor_progress = self.progress_from_mouse_pos(
154154
ctx.size(),
155155
cursor_min_length,
156156
grab_anchor,
157-
ctx.local_position(u.current.position),
157+
ctx.local_position(current.position),
158158
);
159159
self.moved = true;
160160
}

masonry/src/widgets/split.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ use vello::kurbo::{Line, Point, Rect, Size};
1010

1111
use crate::core::{
1212
AccessCtx, AccessEvent, Axis, BoxConstraints, ChildrenIds, CursorIcon, EventCtx, FromDynWidget,
13-
LayoutCtx, NewWidget, NoAction, PaintCtx, PointerEvent, PropertiesMut, PropertiesRef, QueryCtx,
14-
RegisterCtx, TextEvent, Widget, WidgetId, WidgetMut, WidgetPod,
13+
LayoutCtx, NewWidget, NoAction, PaintCtx, PointerButtonEvent, PointerEvent, PointerUpdate,
14+
PropertiesMut, PropertiesRef, QueryCtx, RegisterCtx, TextEvent, Widget, WidgetId, WidgetMut,
15+
WidgetPod,
1516
};
1617
use crate::peniko::Color;
1718
use crate::properties::types::{AsUnit, Length};
@@ -395,8 +396,8 @@ where
395396
) {
396397
if self.draggable {
397398
match event {
398-
PointerEvent::Down(b) => {
399-
let pos = ctx.local_position(b.state.position);
399+
PointerEvent::Down(PointerButtonEvent { state, .. }) => {
400+
let pos = ctx.local_position(state.position);
400401
if self.bar_hit_test(ctx.size(), pos) {
401402
ctx.set_handled();
402403
ctx.capture_pointer();
@@ -407,9 +408,9 @@ where
407408
} - self.bar_position(ctx.size());
408409
}
409410
}
410-
PointerEvent::Move(u) => {
411+
PointerEvent::Move(PointerUpdate { current, .. }) => {
411412
if ctx.is_active() {
412-
let pos = ctx.local_position(u.current.position);
413+
let pos = ctx.local_position(current.position);
413414
// If widget has pointer capture, assume always it's hovered
414415
let effective_pos = match self.split_axis {
415416
Axis::Horizontal => Point {

masonry/src/widgets/text_area.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use vello::peniko::Fill;
1515
use crate::core::keyboard::{Key, KeyState, NamedKey};
1616
use crate::core::{
1717
AccessCtx, AccessEvent, BoxConstraints, BrushIndex, ChildrenIds, CursorIcon, EventCtx, Ime,
18-
LayoutCtx, PaintCtx, PointerButton, PointerEvent, PropertiesMut, PropertiesRef, QueryCtx,
19-
RegisterCtx, StyleProperty, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut,
20-
render_text,
18+
LayoutCtx, PaintCtx, PointerButton, PointerButtonEvent, PointerEvent, PointerUpdate,
19+
PropertiesMut, PropertiesRef, QueryCtx, RegisterCtx, StyleProperty, TextEvent, Update,
20+
UpdateCtx, Widget, WidgetId, WidgetMut, render_text,
2121
};
2222
use crate::properties::{ContentColor, DisabledContentColor};
2323
use crate::theme::default_text_styles;
@@ -424,34 +424,36 @@ impl<const EDITABLE: bool> Widget for TextArea<EDITABLE> {
424424
_props: &mut PropertiesMut<'_>,
425425
event: &PointerEvent,
426426
) {
427-
if self.editor.is_composing() {
427+
if ctx.is_disabled() || self.editor.is_composing() {
428428
return;
429429
}
430430

431431
match event {
432-
PointerEvent::Down(b) => {
433-
if matches!(b.button, None | Some(PointerButton::Primary)) {
434-
let cursor_pos = ctx.local_position(b.state.position);
435-
let (fctx, lctx) = ctx.text_contexts();
436-
let mut drv = self.editor.driver(fctx, lctx);
437-
match b.state.count {
438-
2 => drv.select_word_at_point(cursor_pos.x as f32, cursor_pos.y as f32),
439-
3 => drv.select_line_at_point(cursor_pos.x as f32, cursor_pos.y as f32),
440-
_ => drv.move_to_point(cursor_pos.x as f32, cursor_pos.y as f32),
441-
}
442-
let new_generation = self.editor.generation();
443-
if new_generation != self.rendered_generation {
444-
ctx.request_render();
445-
ctx.set_ime_area(self.ime_area());
446-
self.rendered_generation = new_generation;
447-
}
448-
ctx.request_focus();
449-
ctx.capture_pointer();
432+
PointerEvent::Down(PointerButtonEvent {
433+
button: None | Some(PointerButton::Primary),
434+
state,
435+
..
436+
}) => {
437+
let cursor_pos = ctx.local_position(state.position);
438+
let (fctx, lctx) = ctx.text_contexts();
439+
let mut drv = self.editor.driver(fctx, lctx);
440+
match state.count {
441+
2 => drv.select_word_at_point(cursor_pos.x as f32, cursor_pos.y as f32),
442+
3 => drv.select_line_at_point(cursor_pos.x as f32, cursor_pos.y as f32),
443+
_ => drv.move_to_point(cursor_pos.x as f32, cursor_pos.y as f32),
444+
}
445+
let new_generation = self.editor.generation();
446+
if new_generation != self.rendered_generation {
447+
ctx.request_render();
448+
ctx.set_ime_area(self.ime_area());
449+
self.rendered_generation = new_generation;
450450
}
451+
ctx.request_focus();
452+
ctx.capture_pointer();
451453
}
452-
PointerEvent::Move(u) => {
454+
PointerEvent::Move(PointerUpdate { current, .. }) => {
453455
if ctx.is_active() {
454-
let cursor_pos = ctx.local_position(u.current.position);
456+
let cursor_pos = ctx.local_position(current.position);
455457
let (fctx, lctx) = ctx.text_contexts();
456458
self.editor
457459
.driver(fctx, lctx)

masonry/src/widgets/virtual_scroll.rs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use vello::kurbo::{Point, Size, Vec2};
1010

1111
use crate::core::keyboard::{Key, KeyState, NamedKey};
1212
use crate::core::{
13-
AccessCtx, AccessEvent, BoxConstraints, ChildrenIds, ComposeCtx, EventCtx, LayoutCtx,
14-
NewWidget, PaintCtx, PointerEvent, PropertiesMut, PropertiesRef, RegisterCtx, ScrollDelta,
15-
TextEvent, Update, UpdateCtx, Widget, WidgetMut, WidgetPod,
13+
AccessCtx, AccessEvent, BoxConstraints, ChildrenIds, ComposeCtx, EventCtx, KeyboardEvent,
14+
LayoutCtx, NewWidget, PaintCtx, PointerEvent, PointerScrollEvent, PropertiesMut, PropertiesRef,
15+
RegisterCtx, ScrollDelta, TextEvent, Update, UpdateCtx, Widget, WidgetMut, WidgetPod,
1616
};
1717
use crate::util::debug_panic;
1818

@@ -524,10 +524,10 @@ impl Widget for VirtualScroll {
524524
event: &PointerEvent,
525525
) {
526526
match event {
527-
PointerEvent::Scroll(s) => {
527+
PointerEvent::Scroll(PointerScrollEvent { delta, .. }) => {
528528
// TODO - Remove reference to scale factor.
529529
// See https://github.com/linebender/xilem/issues/1264
530-
let delta = match s.delta {
530+
let delta = match delta {
531531
ScrollDelta::PixelDelta(p) => -p.to_logical::<f64>(ctx.get_scale_factor()).y,
532532
ScrollDelta::LineDelta(_, y) => -y as f64 * ctx.get_scale_factor() * 120.,
533533
_ => 0.0,
@@ -545,23 +545,33 @@ impl Widget for VirtualScroll {
545545
_props: &mut PropertiesMut<'_>,
546546
event: &TextEvent,
547547
) {
548-
match event {
549-
TextEvent::Keyboard(key_event) => {
550-
// To get to this state, you currently need to press "tab" to focus this widget in the example.
551-
if matches!(key_event.state, KeyState::Down) {
552-
// We use an unreasonably large delta (logical pixels) here to allow testing that the case where the
553-
// scrolling "jumps" the area is handled correctly.
554-
// In future, this manual testing would be achieved through use of a scrollbar.
555-
let delta = 20000.;
556-
if matches!(key_event.key, Key::Named(NamedKey::PageDown)) {
557-
self.scroll_offset_from_anchor += delta;
558-
self.event_post_scroll(ctx);
559-
}
560-
if matches!(key_event.key, Key::Named(NamedKey::PageUp)) {
561-
self.scroll_offset_from_anchor -= delta;
562-
self.event_post_scroll(ctx);
563-
}
564-
}
548+
// We use an unreasonably large delta (logical pixels) here to allow testing that the case
549+
// where the scrolling "jumps" the area is handled correctly.
550+
// In future, this manual testing would be achieved through use of a scrollbar.
551+
const DELTA: f64 = 20000.;
552+
553+
// To get to this state, you currently need to press "tab" to focus this widget in the
554+
// example.
555+
let TextEvent::Keyboard(keyboard_event) = event else {
556+
return;
557+
};
558+
559+
match keyboard_event {
560+
KeyboardEvent {
561+
state: KeyState::Down,
562+
key: Key::Named(NamedKey::PageDown),
563+
..
564+
} => {
565+
self.scroll_offset_from_anchor += DELTA;
566+
self.event_post_scroll(ctx);
567+
}
568+
KeyboardEvent {
569+
state: KeyState::Down,
570+
key: Key::Named(NamedKey::PageUp),
571+
..
572+
} => {
573+
self.scroll_offset_from_anchor -= DELTA;
574+
self.event_post_scroll(ctx);
565575
}
566576
_ => {}
567577
}

masonry_core/src/core/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ pub use widget_tag::WidgetTag;
4242

4343
pub use ui_events::keyboard::{KeyboardEvent, Modifiers};
4444
pub use ui_events::pointer::{
45-
PointerButton, PointerButtonEvent, PointerEvent, PointerId, PointerInfo, PointerScrollEvent,
46-
PointerState, PointerType, PointerUpdate,
45+
PointerButton, PointerButtonEvent, PointerEvent, PointerGesture, PointerGestureEvent,
46+
PointerId, PointerInfo, PointerScrollEvent, PointerState, PointerType, PointerUpdate,
4747
};
4848
pub use ui_events::{ScrollDelta, keyboard, pointer};
4949

masonry_core/src/passes/event.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ use tracing::{debug, info_span, trace};
66
use crate::app::{RenderRoot, RenderRootSignal};
77
use crate::core::keyboard::{Key, KeyState, NamedKey};
88
use crate::core::{
9-
AccessEvent, EventCtx, Handled, Ime, PointerButtonEvent, PointerEvent, PointerInfo,
10-
PointerScrollEvent, PointerType, PointerUpdate, PropertiesMut, TextEvent, Widget, WidgetId,
9+
AccessEvent, EventCtx, Handled, Ime, PointerButtonEvent, PointerEvent, PointerGestureEvent,
10+
PointerInfo, PointerScrollEvent, PointerType, PointerUpdate, PropertiesMut, TextEvent, Widget,
11+
WidgetId,
1112
};
1213
use crate::debug_panic;
1314
use crate::dpi::{LogicalPosition, PhysicalPosition};
@@ -53,6 +54,7 @@ fn pointer_event_short_name(e: &PointerEvent) -> &'static str {
5354
PointerEvent::Leave(..) => "Leave",
5455
PointerEvent::Cancel(..) => "Cancel",
5556
PointerEvent::Scroll(..) => "Scroll",
57+
PointerEvent::Gesture(..) => "Gesture",
5658
}
5759
}
5860

@@ -62,7 +64,8 @@ fn try_event_position(event: &PointerEvent) -> Option<PhysicalPosition<f64>> {
6264
PointerEvent::Down(PointerButtonEvent { state, .. })
6365
| PointerEvent::Up(PointerButtonEvent { state, .. })
6466
| PointerEvent::Move(PointerUpdate { current: state, .. })
65-
| PointerEvent::Scroll(PointerScrollEvent { state, .. }) => Some(state.position),
67+
| PointerEvent::Scroll(PointerScrollEvent { state, .. })
68+
| PointerEvent::Gesture(PointerGestureEvent { state, .. }) => Some(state.position),
6669
_ => None,
6770
}
6871
}

0 commit comments

Comments
 (0)