Skip to content

Commit 0dea0e6

Browse files
committed
Update ui-events to 0.2.0.
1 parent bec6c62 commit 0dea0e6

File tree

10 files changed

+430
-293
lines changed

10 files changed

+430
-293
lines changed

Cargo.lock

Lines changed: 293 additions & 216 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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ android-view = { path = ".." }
1414
android_logger = "0.15.0"
1515
anyhow = "1.0.96"
1616
log = "0.4.26"
17-
parley = { git = "https://github.com/linebender/parley", rev = "587b7634ae8601c10de7f0361bfd56085a5b7b4e", features = ["accesskit"] }
18-
peniko = { version = "0.4.0", default-features = false }
17+
parley = { version = "0.6.0", features = ["accesskit"] }
18+
peniko = { version = "0.5.0", default-features = false }
1919
pollster = "0.4.0"
20-
ui-events = "0.1.0"
21-
vello = "0.5.0"
20+
ui-events = { version = "0.2.0", default-features = false }
21+
vello = "0.6.0"
2222

2323
# Send tracing events to Android GPU inspector, for profiling
2424
tracing_android_trace = "0.1.1"

demo/src/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ impl DemoViewPeer {
290290
// Queue the texture to be presented on the surface.
291291
surface_texture.present();
292292

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

296297
fn set_composing_text_internal(&mut self, text: &str, new_cursor_position: jint) {
@@ -371,7 +372,7 @@ impl ViewPeer for DemoViewPeer {
371372
return false;
372373
};
373374

374-
if matches!(ev, PointerEvent::Up { .. }) {
375+
if matches!(ev, PointerEvent::Up(..)) {
375376
ctx.push_static_deferred_callback(show_soft_input);
376377
}
377378

@@ -437,9 +438,16 @@ impl ViewPeer for DemoViewPeer {
437438
width: jint,
438439
height: jint,
439440
) {
440-
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);
441448
let editor = self.editor.editor_mut();
442-
editor.set_scale(1.0);
449+
#[allow(clippy::cast_possible_truncation, reason = "Unavoidable")]
450+
editor.set_scale(scale_factor as f32);
443451
editor.set_width(Some(width as f32 - 2_f32 * text::INSET));
444452
self.last_drawn_generation = Default::default();
445453
let focused = ctx.view.is_focused(&mut ctx.env);

demo/src/text.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ 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,
19-
kurbo::{Affine, Line, Stroke},
19+
kurbo::{Affine, Line, Rect, Stroke},
2020
peniko::color::palette,
2121
peniko::{Brush, Fill},
2222
};
@@ -148,7 +148,7 @@ impl Editor {
148148
pub fn cursor_blink(&mut self) {
149149
self.cursor_visible = self.start_time.is_some_and(|start_time| {
150150
let elapsed = Instant::now().duration_since(start_time);
151-
(elapsed.as_millis() / self.blink_period.as_millis()) % 2 == 0
151+
(elapsed.as_millis() / self.blink_period.as_millis()).is_multiple_of(2)
152152
});
153153
}
154154

@@ -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(
@@ -346,11 +346,10 @@ impl Editor {
346346
}
347347

348348
pub fn handle_accesskit_action_request(&mut self, req: &accesskit::ActionRequest) {
349-
if req.action == accesskit::Action::SetTextSelection {
350-
if let Some(accesskit::ActionData::SetTextSelection(selection)) = &req.data {
349+
if req.action == accesskit::Action::SetTextSelection
350+
&& let Some(accesskit::ActionData::SetTextSelection(selection)) = &req.data {
351351
self.driver().select_from_accesskit(selection);
352352
}
353-
}
354353
}
355354

356355
/// Return the current `Generation` of the layout.
@@ -363,26 +362,26 @@ impl Editor {
363362
/// Returns drawn `Generation`.
364363
pub fn draw(&mut self, scene: &mut Scene) -> Generation {
365364
let transform = Affine::translate((INSET as f64, INSET as f64));
366-
self.editor.selection_geometry_with(|rect, _| {
367-
scene.fill(
368-
Fill::NonZero,
369-
transform,
370-
palette::css::STEEL_BLUE,
371-
None,
372-
&rect,
373-
);
374-
});
375-
if self.cursor_visible {
376-
if let Some(cursor) = self.editor.cursor_geometry(5.0) {
365+
self.editor
366+
.selection_geometry_with(|parley::BoundingBox { x0, x1, y0, y1 }, _| {
367+
scene.fill(
368+
Fill::NonZero,
369+
transform,
370+
palette::css::STEEL_BLUE,
371+
None,
372+
&Rect { x0, x1, y0, y1 },
373+
);
374+
});
375+
if self.cursor_visible
376+
&& let Some(parley::BoundingBox { x0, x1, y0, y1 }) = self.editor.cursor_geometry(5.0) {
377377
scene.fill(
378378
Fill::NonZero,
379379
transform,
380380
palette::css::CADET_BLUE,
381381
None,
382-
&cursor,
382+
&Rect { x0, x1, y0, y1 },
383383
);
384384
}
385-
}
386385
let layout = self.editor.layout(&mut self.font_cx, &mut self.layout_cx);
387386
for line in layout.lines() {
388387
for item in line.items() {

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" }
12+
masonry = { git = "https://github.com/xorgy/xilem", branch = "ui-events-0.2.0" }
1313
masonry_android = { path = "../masonry" }
1414

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

masonry-demo/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ use android_view::{
1212
};
1313
use masonry::{
1414
core::{ErasedAction, NewWidget, Properties, Widget, WidgetId},
15-
properties::Padding,
15+
properties::{Padding, types::Length},
1616
theme::default_property_set,
1717
widgets::{Button, ButtonPress, Flex, Label, Portal, TextAction, TextArea, TextInput},
1818
};
1919
use masonry_android::{AppDriver, DriverCtx};
2020
use std::{ffi::c_void, sync::Arc};
2121
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
2222

23-
const WIDGET_SPACING: f64 = 5.0;
23+
const WIDGET_SPACING: Length = Length::const_px(5.0);
2424

2525
struct Driver {
2626
next_task: String,
@@ -29,7 +29,7 @@ struct Driver {
2929
impl AppDriver for Driver {
3030
fn on_action(&mut self, ctx: &mut DriverCtx<'_>, _widget_id: WidgetId, action: ErasedAction) {
3131
if action.is::<ButtonPress>() {
32-
ctx.render_root().edit_root_widget(|mut root| {
32+
ctx.render_root().edit_base_layer(|mut root| {
3333
let mut portal = root.downcast::<Portal<Flex>>();
3434
let mut flex = Portal::child_mut(&mut portal);
3535
Flex::add_child(&mut flex, Label::new(self.next_task.clone()).with_auto_id());
@@ -59,8 +59,8 @@ fn make_widget_tree() -> impl Widget {
5959
.with_child(NewWidget::new_with_props(
6060
Flex::row()
6161
.with_flex_child(TextInput::new("").with_auto_id(), 1.0)
62-
.with_child(Button::new("Add task").with_auto_id()),
63-
Properties::new().with(Padding::all(WIDGET_SPACING)),
62+
.with_child(Button::new(NewWidget::new(Label::new("Add task"))).with_auto_id()),
63+
Properties::new().with(Padding::all(WIDGET_SPACING.get())),
6464
))
6565
.with_spacer(WIDGET_SPACING)
6666
.with_auto_id(),

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" }
9+
masonry_core = { git = "https://github.com/xorgy/xilem", branch = "ui-events-0.2.0" }
1010
pollster = "0.4.0"
1111
tracing = "0.1.40"

masonry/src/lib.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ impl MasonryState {
116116
default_properties,
117117
use_system_fonts: true,
118118
size_policy: WindowSizePolicy::User,
119+
size: Default::default(),
119120
scale_factor,
120121
test_font: None,
121122
},
@@ -170,6 +171,9 @@ impl<Driver: AppDriver> MasonryViewPeer<Driver> {
170171
self.app_driver
171172
.on_action(&mut driver_ctx, widget_id, action);
172173
}
174+
RenderRootSignal::ClipboardStore(..) => {
175+
// TODO
176+
}
173177
RenderRootSignal::StartIme => {
174178
ctx.push_static_deferred_callback(show_soft_input);
175179
}
@@ -228,6 +232,15 @@ impl<Driver: AppDriver> MasonryViewPeer<Driver> {
228232
};
229233
info!("Widget selected in inspector: {widget_id} - {display_name}");
230234
}
235+
RenderRootSignal::NewLayer(..) => {
236+
// TODO
237+
}
238+
RenderRootSignal::RepositionLayer(..) => {
239+
// TODO
240+
}
241+
RenderRootSignal::RemoveLayer(..) => {
242+
// TODO
243+
}
231244
}
232245
}
233246

@@ -243,10 +256,11 @@ impl<Driver: AppDriver> MasonryViewPeer<Driver> {
243256

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

246-
if let Some(events) = self
247-
.state
248-
.accesskit_adapter
249-
.update_if_active(|| tree_update)
259+
if let Some(tree_update) = tree_update
260+
&& let Some(events) = self
261+
.state
262+
.accesskit_adapter
263+
.update_if_active(|| tree_update)
250264
{
251265
ctx.push_dynamic_deferred_callback(move |env, view| {
252266
events.raise(env, &view.0);
@@ -317,7 +331,8 @@ impl<Driver: AppDriver> MasonryViewPeer<Driver> {
317331
// Queue the texture to be presented on the surface.
318332
surface_texture.present();
319333

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

323338
fn on_key_event<'local>(
@@ -347,7 +362,7 @@ impl<Driver: AppDriver> MasonryViewPeer<Driver> {
347362
if handler.requested_initial_tree {
348363
self.state
349364
.render_root
350-
.handle_window_event(WindowEvent::RebuildAccessTree);
365+
.handle_window_event(WindowEvent::EnableAccessTree);
351366
self.handle_signals(ctx);
352367
}
353368
result
@@ -436,9 +451,10 @@ impl<Driver: AppDriver> ViewPeer for MasonryViewPeer<Driver> {
436451
width: jint,
437452
height: jint,
438453
) {
439-
self.state.tap_counter = TapCounter::new(ctx.view.view_configuration(&mut ctx.env));
440454
let android_ctx = ctx.view.context(&mut ctx.env);
441455
let scale_factor = scale_factor(&mut ctx.env, &android_ctx);
456+
self.state.tap_counter =
457+
TapCounter::new(ctx.view.view_configuration(&mut ctx.env), scale_factor);
442458
self.state
443459
.render_root
444460
.handle_window_event(WindowEvent::Rescale(scale_factor));

0 commit comments

Comments
 (0)