Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
352 changes: 303 additions & 49 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ndk = "0.9.0"
num_enum = "0.7.3"
send_wrapper = "0.6.0"
smallvec = "1.15.0"
ui-events = "0.1.0"
ui-events = { git = "https://github.com/endoli/ui-events", rev = "08c942c" }

[profile.dev]
panic = "abort"
Expand Down
2 changes: 1 addition & 1 deletion demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ log = "0.4.26"
parley = { git = "https://github.com/linebender/parley", rev = "587b7634ae8601c10de7f0361bfd56085a5b7b4e", features = ["accesskit"] }
peniko = { version = "0.4.0", default-features = false }
pollster = "0.4.0"
ui-events = "0.1.0"
ui-events = { git = "https://github.com/endoli/ui-events", rev = "08c942c" }
vello = "0.5.0"

# Send tracing events to Android GPU inspector, for profiling
Expand Down
2 changes: 1 addition & 1 deletion demo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ impl ViewPeer for DemoViewPeer {
return false;
};

if matches!(ev, PointerEvent::Up { .. }) {
if matches!(ev, PointerEvent::Up(..)) {
ctx.push_static_deferred_callback(show_soft_input);
}

Expand Down
6 changes: 3 additions & 3 deletions demo/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use parley::{
use std::time::{Duration, Instant};
use ui_events::{
keyboard::{Code, Key, KeyState, KeyboardEvent, NamedKey},
pointer::{PointerButton, PointerEvent, PointerState, PointerUpdate},
pointer::{PointerButton, PointerButtonEvent, PointerEvent, PointerState, PointerUpdate},
};
use vello::{
Scene,
Expand Down Expand Up @@ -310,7 +310,7 @@ impl Editor {
pub fn handle_pointer_event(&mut self, ev: PointerEvent) -> bool {
let mut drv = self.editor.driver(&mut self.font_cx, &mut self.layout_cx);
match ev {
PointerEvent::Down {
PointerEvent::Down(PointerButtonEvent {
button: None | Some(PointerButton::Primary),
state:
PointerState {
Expand All @@ -320,7 +320,7 @@ impl Editor {
..
},
..
} => match count {
}) => match count {
2 => drv.select_word_at_point(position.x as f32 - INSET, position.y as f32 - INSET),
3 => drv.select_line_at_point(position.x as f32 - INSET, position.y as f32 - INSET),
1 if modifiers.shift() => drv.extend_selection_to_point(
Expand Down
2 changes: 1 addition & 1 deletion masonry-demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
android-view = { path = ".." }
masonry = { git = "https://github.com/linebender/xilem" }
masonry = { git = "https://github.com/xorgy/xilem", branch = "ui-events-0.2.0" }
masonry_android = { path = "../masonry" }

# Send tracing events to Android GPU inspector, for profiling
Expand Down
8 changes: 4 additions & 4 deletions masonry-demo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ use android_view::{
};
use masonry::{
core::{ErasedAction, NewWidget, Properties, Widget, WidgetId},
properties::Padding,
properties::{Padding, types::Length},
theme::default_property_set,
widgets::{Button, ButtonPress, Flex, Label, Portal, TextAction, TextArea, TextInput},
};
use masonry_android::{AppDriver, DriverCtx};
use std::{ffi::c_void, sync::Arc};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};

const WIDGET_SPACING: f64 = 5.0;
const WIDGET_SPACING: Length = Length::const_px(5.0);

struct Driver {
next_task: String,
Expand Down Expand Up @@ -59,8 +59,8 @@ fn make_widget_tree() -> impl Widget {
.with_child(NewWidget::new_with_props(
Flex::row()
.with_flex_child(TextInput::new("").with_auto_id(), 1.0)
.with_child(Button::new("Add task").with_auto_id()),
Properties::new().with(Padding::all(WIDGET_SPACING)),
.with_child(Button::new(NewWidget::new(Label::new("Add task"))).with_auto_id()),
Properties::new().with(Padding::all(WIDGET_SPACING.get())),
))
.with_spacer(WIDGET_SPACING)
.with_auto_id(),
Expand Down
2 changes: 1 addition & 1 deletion masonry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ edition = "2024"
[dependencies]
accesskit_android = "0.4.0"
android-view = { path = ".." }
masonry_core = { git = "https://github.com/linebender/xilem" }
masonry_core = { git = "https://github.com/xorgy/xilem", branch = "ui-events-0.2.0" }
pollster = "0.4.0"
tracing = "0.1.40"
17 changes: 11 additions & 6 deletions masonry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ impl<Driver: AppDriver> MasonryViewPeer<Driver> {
self.app_driver
.on_action(&mut driver_ctx, widget_id, action);
}
RenderRootSignal::ClipboardStore(..) => {
// TODO
}
RenderRootSignal::StartIme => {
ctx.push_static_deferred_callback(show_soft_input);
}
Expand Down Expand Up @@ -243,10 +246,11 @@ impl<Driver: AppDriver> MasonryViewPeer<Driver> {

let (scene, tree_update) = self.state.render_root.redraw();

if let Some(events) = self
.state
.accesskit_adapter
.update_if_active(|| tree_update)
if let Some(tree_update) = tree_update
&& let Some(events) = self
.state
.accesskit_adapter
.update_if_active(|| tree_update)
{
ctx.push_dynamic_deferred_callback(move |env, view| {
events.raise(env, &view.0);
Expand Down Expand Up @@ -317,7 +321,8 @@ impl<Driver: AppDriver> MasonryViewPeer<Driver> {
// Queue the texture to be presented on the surface.
surface_texture.present();

device_handle.device.poll(wgpu::Maintain::Poll);
// `poll` has a return type for a reason, but not sure what to do with it here.
let _ = device_handle.device.poll(wgpu::PollType::Poll);
}

fn on_key_event<'local>(
Expand Down Expand Up @@ -347,7 +352,7 @@ impl<Driver: AppDriver> MasonryViewPeer<Driver> {
if handler.requested_initial_tree {
self.state
.render_root
.handle_window_event(WindowEvent::RebuildAccessTree);
.handle_window_event(WindowEvent::EnableAccessTree);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to need somebody to confirm that this is the correct way to do this now, I wasn't involved in any of the changes that caused this.

I may end up splitting the Masonry upstream churn changes from this PR when it comes time to merge, just want to flag this for somebody to look at.

self.handle_signals(ctx);
}
result
Expand Down
49 changes: 28 additions & 21 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use num_enum::FromPrimitive;
use ui_events::{
ScrollDelta,
keyboard::{KeyboardEvent, Modifiers},
pointer::{ContactGeometry, PointerEvent, PointerId, PointerState, PointerUpdate},
pointer::{
ContactGeometry, PointerButtonEvent, PointerEvent, PointerId, PointerScrollEvent,
PointerState, PointerUpdate,
},
};

use crate::ViewConfiguration;
Expand Down Expand Up @@ -467,16 +470,18 @@ impl<'local> MotionEvent<'local> {
};

Some(match action {
MotionAction::Down | MotionAction::PointerDown => PointerEvent::Down {
pointer,
state,
button,
},
MotionAction::Up | MotionAction::PointerUp => PointerEvent::Up {
MotionAction::Down | MotionAction::PointerDown => {
PointerEvent::Down(PointerButtonEvent {
pointer,
state,
button,
})
}
MotionAction::Up | MotionAction::PointerUp => PointerEvent::Up(PointerButtonEvent {
pointer,
state,
button,
},
}),
MotionAction::Move | MotionAction::HoverMove => {
let hsz = self.history_size(env);
let mut coalesced: Vec<PointerState> = vec![state.clone(); hsz as usize];
Expand Down Expand Up @@ -527,7 +532,7 @@ impl<'local> MotionEvent<'local> {
MotionAction::Cancel => PointerEvent::Cancel(pointer),
MotionAction::HoverEnter => PointerEvent::Enter(pointer),
MotionAction::HoverExit => PointerEvent::Leave(pointer),
MotionAction::Scroll => PointerEvent::Scroll {
MotionAction::Scroll => PointerEvent::Scroll(PointerScrollEvent {
pointer,
delta: ScrollDelta::PixelDelta(PhysicalPosition::<f64> {
x: (self.axis(env, Axis::Hscroll, action_index)
Expand All @@ -536,7 +541,7 @@ impl<'local> MotionEvent<'local> {
* vc.scaled_vertical_scroll_factor) as f64,
}),
state,
},
}),
_ => {
// Other current `MotionAction` values relate to gamepad/joystick buttons;
// ui-events doesn't currently have types for these, so consider them unhandled.
Expand Down Expand Up @@ -620,11 +625,11 @@ impl TapCounter {
///
pub fn attach_count(&mut self, e: PointerEvent) -> PointerEvent {
match e {
PointerEvent::Down {
PointerEvent::Down(PointerButtonEvent {
button,
pointer,
state,
} => {
}) => {
let e = if let Some(i) =
self.taps.iter().position(|TapState { x, y, up_time, .. }| {
let dx = (x - state.position.x).abs();
Expand All @@ -641,11 +646,11 @@ impl TapCounter {
self.taps[i].x = state.position.x;
self.taps[i].y = state.position.y;

PointerEvent::Down {
PointerEvent::Down(PointerButtonEvent {
button,
pointer,
state: PointerState { count, ..state },
}
})
} else {
let s = TapState {
pointer_id: pointer.pointer_id,
Expand All @@ -656,34 +661,34 @@ impl TapCounter {
y: state.position.y,
};
self.taps.push(s);
PointerEvent::Down {
PointerEvent::Down(PointerButtonEvent {
button,
pointer,
state: PointerState { count: 1, ..state },
}
})
};
self.clear_expired(state.time);
e
}
PointerEvent::Up {
PointerEvent::Up(PointerButtonEvent {
button,
pointer,
ref state,
} => {
}) => {
if let Some(i) = self
.taps
.iter()
.position(|TapState { pointer_id, .. }| *pointer_id == pointer.pointer_id)
{
self.taps[i].up_time = state.time;
PointerEvent::Up {
PointerEvent::Up(PointerButtonEvent {
button,
pointer,
state: PointerState {
count: self.taps[i].count,
..state.clone()
},
}
})
} else {
e.clone()
}
Expand Down Expand Up @@ -735,7 +740,9 @@ impl TapCounter {
.retain(|TapState { pointer_id, .. }| *pointer_id != p.pointer_id);
e.clone()
}
PointerEvent::Enter(..) | PointerEvent::Scroll { .. } => e.clone(),
PointerEvent::Enter(..) | PointerEvent::Scroll(..) | PointerEvent::Gesture(..) => {
e.clone()
}
}
}

Expand Down