Skip to content

Update ui-events to 0.2.0. #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
9 changes: 4 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 = "6382e63" }

[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 = { version = "0.5.0", 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 = "6382e63" }
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
11 changes: 4 additions & 7 deletions masonry-demo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use masonry::{
core::{Action, DefaultProperties, Widget, WidgetId},
properties::Padding,
theme::default_property_set,
widgets::{Button, Flex, Label, Portal, RootWidget, TextArea, Textbox},
widgets::{Button, Flex, Label, Portal, TextArea, Textbox},
};
use masonry_android::{AppDriver, DriverCtx};
use std::{ffi::c_void, sync::Arc};
Expand All @@ -31,10 +31,7 @@ impl AppDriver for Driver {
match action {
Action::ButtonPressed(_) => {
ctx.render_root().edit_root_widget(|mut root| {
let mut root = root.downcast::<RootWidget>();

let mut portal = RootWidget::child_mut(&mut root);
let mut portal = portal.downcast::<Portal<Flex>>();
let mut portal = root.downcast::<Portal<Flex>>();
let mut flex = Portal::child_mut(&mut portal);
Flex::add_child(&mut flex, Label::new(self.next_task.clone()));

Expand Down Expand Up @@ -68,7 +65,7 @@ fn make_widget_tree() -> impl Widget {

fn default_props() -> Arc<DefaultProperties> {
let mut default_properties = default_property_set();
default_properties.insert::<RootWidget, _>(Padding::all(WIDGET_SPACING));
default_properties.insert::<Portal<Flex>, _>(Padding::all(WIDGET_SPACING));

Arc::new(default_properties)
}
Expand All @@ -81,7 +78,7 @@ extern "system" fn new_view_peer<'local>(
masonry_android::new_view_peer(
&mut env,
&context,
RootWidget::new(make_widget_tree()),
make_widget_tree(),
Driver {
next_task: String::new(),
},
Expand Down
2 changes: 1 addition & 1 deletion masonry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2024"
accesskit = "0.19.0"
accesskit_android = "0.2.0"
android-view = { path = ".." }
masonry = { git = "https://github.com/linebender/xilem" }
masonry = { git = "https://github.com/xorgy/xilem", branch = "ui-events-0.2.0" }
pollster = "0.4.0"
tracing = "0.1.40"
vello = "0.5.0"
47 changes: 26 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,7 @@ impl TapCounter {
.retain(|TapState { pointer_id, .. }| *pointer_id != p.pointer_id);
e.clone()
}
PointerEvent::Enter(..) | PointerEvent::Scroll { .. } => e.clone(),
PointerEvent::Enter(..) | PointerEvent::Scroll(..) => e.clone(),
}
}

Expand Down