Skip to content

Commit 2488f6e

Browse files
committed
Update ui-events to 0.2.0.
1 parent fb3e7d8 commit 2488f6e

File tree

9 files changed

+85
-44
lines changed

9 files changed

+85
-44
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ndk = "0.9.0"
1818
num_enum = "0.7.3"
1919
send_wrapper = "0.6.0"
2020
smallvec = "1.15.0"
21-
ui-events = "0.1.0"
21+
ui-events = { version = "0.2.0", default-features = false }
2222

2323
[profile.dev]
2424
panic = "abort"

demo/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ log = "0.4.26"
1717
parley = { version = "0.6.0", features = ["accesskit"] }
1818
peniko = { version = "0.5.0", default-features = false }
1919
pollster = "0.4.0"
20-
ui-events = "0.1.0"
20+
ui-events = { version = "0.2.0", default-features = false }
2121
vello = "0.6.0"
2222

2323
# Send tracing events to Android GPU inspector, for profiling

demo/src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ impl ViewPeer for DemoViewPeer {
372372
return false;
373373
};
374374

375-
if matches!(ev, PointerEvent::Up { .. }) {
375+
if matches!(ev, PointerEvent::Up(..)) {
376376
ctx.push_static_deferred_callback(show_soft_input);
377377
}
378378

@@ -438,9 +438,16 @@ impl ViewPeer for DemoViewPeer {
438438
width: jint,
439439
height: jint,
440440
) {
441-
self.tap_counter = TapCounter::new(ctx.view.view_configuration(&mut ctx.env));
441+
let android_ctx = ctx.view.context(&mut ctx.env);
442+
let scale_factor = {
443+
let res = android_ctx.resources(&mut ctx.env);
444+
let metrics = res.display_metrics(&mut ctx.env);
445+
metrics.density(&mut ctx.env) as f64
446+
};
447+
self.tap_counter = TapCounter::new(ctx.view.view_configuration(&mut ctx.env), scale_factor);
442448
let editor = self.editor.editor_mut();
443-
editor.set_scale(1.0);
449+
#[allow(clippy::cast_possible_truncation, reason = "Unavoidable")]
450+
editor.set_scale(scale_factor as f32);
444451
editor.set_width(Some(width as f32 - 2_f32 * text::INSET));
445452
self.last_drawn_generation = Default::default();
446453
let focused = ctx.view.is_focused(&mut ctx.env);

demo/src/text.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use parley::{
1212
use std::time::{Duration, Instant};
1313
use ui_events::{
1414
keyboard::{Code, Key, KeyState, KeyboardEvent, NamedKey},
15-
pointer::{PointerButton, PointerEvent, PointerState, PointerUpdate},
15+
pointer::{PointerButton, PointerButtonEvent, PointerEvent, PointerState, PointerUpdate},
1616
};
1717
use vello::{
1818
Scene,
@@ -310,7 +310,7 @@ impl Editor {
310310
pub fn handle_pointer_event(&mut self, ev: PointerEvent) -> bool {
311311
let mut drv = self.editor.driver(&mut self.font_cx, &mut self.layout_cx);
312312
match ev {
313-
PointerEvent::Down {
313+
PointerEvent::Down(PointerButtonEvent {
314314
button: None | Some(PointerButton::Primary),
315315
state:
316316
PointerState {
@@ -320,7 +320,7 @@ impl Editor {
320320
..
321321
},
322322
..
323-
} => match count {
323+
}) => match count {
324324
2 => drv.select_word_at_point(position.x as f32 - INSET, position.y as f32 - INSET),
325325
3 => drv.select_line_at_point(position.x as f32 - INSET, position.y as f32 - INSET),
326326
1 if modifiers.shift() => drv.extend_selection_to_point(

masonry-demo/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ crate-type = ["cdylib"]
99

1010
[dependencies]
1111
android-view = { path = ".." }
12-
masonry = { git = "https://github.com/linebender/xilem", rev = "2750659" }
12+
masonry = { git = "https://github.com/linebender/xilem", rev = "de88321" }
1313
masonry_android = { path = "../masonry" }
1414

1515
# Send tracing events to Android GPU inspector, for profiling

masonry/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ edition = "2024"
66
[dependencies]
77
accesskit_android = "0.4.0"
88
android-view = { path = ".." }
9-
masonry_core = { git = "https://github.com/linebender/xilem", rev = "2750659" }
9+
masonry_core = { git = "https://github.com/linebender/xilem", rev = "de88321" }
1010
pollster = "0.4.0"
1111
tracing = "0.1.40"

masonry/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,8 @@ impl<Driver: AppDriver> ViewPeer for MasonryViewPeer<Driver> {
453453
) {
454454
let android_ctx = ctx.view.context(&mut ctx.env);
455455
let scale_factor = scale_factor(&mut ctx.env, &android_ctx);
456-
self.state.tap_counter = TapCounter::new(ctx.view.view_configuration(&mut ctx.env));
456+
self.state.tap_counter =
457+
TapCounter::new(ctx.view.view_configuration(&mut ctx.env), scale_factor);
457458
self.state
458459
.render_root
459460
.handle_window_event(WindowEvent::Rescale(scale_factor));

src/events.rs

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use num_enum::FromPrimitive;
1212
use ui_events::{
1313
ScrollDelta,
1414
keyboard::{KeyboardEvent, Modifiers},
15-
pointer::{ContactGeometry, PointerEvent, PointerId, PointerState, PointerUpdate},
15+
pointer::{
16+
ContactGeometry, PointerButtonEvent, PointerEvent, PointerId, PointerScrollEvent,
17+
PointerState, PointerUpdate,
18+
},
1619
};
1720

1821
use crate::ViewConfiguration;
@@ -439,6 +442,8 @@ impl<'local> MotionEvent<'local> {
439442
x: self.axis(env, Axis::X, action_index) as f64,
440443
y: self.axis(env, Axis::Y, action_index) as f64,
441444
},
445+
// `TapCounter` will attach the scale.
446+
scale_factor: 1.0,
442447
buttons,
443448
// `TapCounter` will attach an appropriate count.
444449
count: 0,
@@ -469,16 +474,18 @@ impl<'local> MotionEvent<'local> {
469474
};
470475

471476
Some(match action {
472-
MotionAction::Down | MotionAction::PointerDown => PointerEvent::Down {
473-
pointer,
474-
state,
475-
button,
476-
},
477-
MotionAction::Up | MotionAction::PointerUp => PointerEvent::Up {
477+
MotionAction::Down | MotionAction::PointerDown => {
478+
PointerEvent::Down(PointerButtonEvent {
479+
pointer,
480+
state,
481+
button,
482+
})
483+
}
484+
MotionAction::Up | MotionAction::PointerUp => PointerEvent::Up(PointerButtonEvent {
478485
pointer,
479486
state,
480487
button,
481-
},
488+
}),
482489
MotionAction::Move | MotionAction::HoverMove => {
483490
let hsz = self.history_size(env);
484491
let mut coalesced: Vec<PointerState> = vec![state.clone(); hsz as usize];
@@ -531,7 +538,7 @@ impl<'local> MotionEvent<'local> {
531538
MotionAction::Cancel => PointerEvent::Cancel(pointer),
532539
MotionAction::HoverEnter => PointerEvent::Enter(pointer),
533540
MotionAction::HoverExit => PointerEvent::Leave(pointer),
534-
MotionAction::Scroll => PointerEvent::Scroll {
541+
MotionAction::Scroll => PointerEvent::Scroll(PointerScrollEvent {
535542
pointer,
536543
delta: ScrollDelta::PixelDelta(PhysicalPosition::<f64> {
537544
x: (self.axis(env, Axis::Hscroll, action_index)
@@ -540,7 +547,7 @@ impl<'local> MotionEvent<'local> {
540547
* vc.scaled_vertical_scroll_factor) as f64,
541548
}),
542549
state,
543-
},
550+
}),
544551
_ => {
545552
// Other current `MotionAction` values relate to gamepad/joystick buttons;
546553
// ui-events doesn't currently have types for these, so consider them unhandled.
@@ -610,25 +617,31 @@ struct TapState {
610617
pub struct TapCounter {
611618
/// The `ViewConfiguration` which configures tap counting.
612619
pub vc: ViewConfiguration,
620+
/// The scale factor.
621+
pub scale_factor: f64,
613622
/// Recent taps which can be used for tap counting.
614623
taps: Vec<TapState>,
615624
}
616625

617626
impl TapCounter {
618627
/// Make a new `TapCounter` with `ViewConfiguration` from your view.
619-
pub fn new(vc: ViewConfiguration) -> Self {
620-
Self { vc, taps: vec![] }
628+
pub fn new(vc: ViewConfiguration, scale_factor: f64) -> Self {
629+
Self {
630+
vc,
631+
scale_factor,
632+
taps: vec![],
633+
}
621634
}
622635

623636
/// Enhance a `PointerEvent` with `count`.
624637
///
625638
pub fn attach_count(&mut self, e: PointerEvent) -> PointerEvent {
626639
match e {
627-
PointerEvent::Down {
640+
PointerEvent::Down(PointerButtonEvent {
628641
button,
629642
pointer,
630643
state,
631-
} => {
644+
}) => {
632645
let e = if let Some(i) =
633646
self.taps.iter().position(|TapState { x, y, up_time, .. }| {
634647
let dx = (x - state.position.x).abs();
@@ -645,11 +658,15 @@ impl TapCounter {
645658
self.taps[i].x = state.position.x;
646659
self.taps[i].y = state.position.y;
647660

648-
PointerEvent::Down {
661+
PointerEvent::Down(PointerButtonEvent {
649662
button,
650663
pointer,
651-
state: PointerState { count, ..state },
652-
}
664+
state: PointerState {
665+
count,
666+
scale_factor: self.scale_factor,
667+
..state
668+
},
669+
})
653670
} else {
654671
let s = TapState {
655672
pointer_id: pointer.pointer_id,
@@ -660,34 +677,39 @@ impl TapCounter {
660677
y: state.position.y,
661678
};
662679
self.taps.push(s);
663-
PointerEvent::Down {
680+
PointerEvent::Down(PointerButtonEvent {
664681
button,
665682
pointer,
666-
state: PointerState { count: 1, ..state },
667-
}
683+
state: PointerState {
684+
count: 1,
685+
scale_factor: self.scale_factor,
686+
..state
687+
},
688+
})
668689
};
669690
self.clear_expired(state.time);
670691
e
671692
}
672-
PointerEvent::Up {
693+
PointerEvent::Up(PointerButtonEvent {
673694
button,
674695
pointer,
675696
ref state,
676-
} => {
697+
}) => {
677698
if let Some(i) = self
678699
.taps
679700
.iter()
680701
.position(|TapState { pointer_id, .. }| *pointer_id == pointer.pointer_id)
681702
{
682703
self.taps[i].up_time = state.time;
683-
PointerEvent::Up {
704+
PointerEvent::Up(PointerButtonEvent {
684705
button,
685706
pointer,
686707
state: PointerState {
687708
count: self.taps[i].count,
709+
scale_factor: self.scale_factor,
688710
..state.clone()
689711
},
690-
}
712+
})
691713
} else {
692714
e.clone()
693715
}
@@ -717,17 +739,26 @@ impl TapCounter {
717739
pointer,
718740
current: PointerState {
719741
count,
742+
scale_factor: self.scale_factor,
720743
..current.clone()
721744
},
722745
coalesced: coalesced
723746
.iter()
724747
.cloned()
725-
.map(|u| PointerState { count, ..u })
748+
.map(|u| PointerState {
749+
count,
750+
scale_factor: self.scale_factor,
751+
..u
752+
})
726753
.collect(),
727754
predicted: predicted
728755
.iter()
729756
.cloned()
730-
.map(|u| PointerState { count, ..u })
757+
.map(|u| PointerState {
758+
count,
759+
scale_factor: self.scale_factor,
760+
..u
761+
})
731762
.collect(),
732763
})
733764
} else {
@@ -739,7 +770,9 @@ impl TapCounter {
739770
.retain(|TapState { pointer_id, .. }| *pointer_id != p.pointer_id);
740771
e.clone()
741772
}
742-
PointerEvent::Enter(..) | PointerEvent::Scroll { .. } => e.clone(),
773+
PointerEvent::Enter(..) | PointerEvent::Scroll(..) | PointerEvent::Gesture(..) => {
774+
e.clone()
775+
}
743776
}
744777
}
745778

0 commit comments

Comments
 (0)