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
579 changes: 354 additions & 225 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 = { version = "0.2.0", default-features = false }

[profile.dev]
panic = "abort"
Expand Down
8 changes: 4 additions & 4 deletions demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ android-view = { path = ".." }
android_logger = "0.15.0"
anyhow = "1.0.96"
log = "0.4.26"
parley = { git = "https://github.com/linebender/parley", rev = "587b7634ae8601c10de7f0361bfd56085a5b7b4e", features = ["accesskit"] }
peniko = { version = "0.4.0", default-features = false }
parley = { version = "0.6.0", features = ["accesskit"] }
peniko = { version = "0.5.0", default-features = false }
pollster = "0.4.0"
ui-events = "0.1.0"
vello = "0.5.0"
ui-events = { version = "0.2.0", default-features = false }
vello = "0.6.0"

# Send tracing events to Android GPU inspector, for profiling
tracing_android_trace = "0.1.1"
Expand Down
16 changes: 12 additions & 4 deletions demo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ impl DemoViewPeer {
// 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 set_composing_text_internal(&mut self, text: &str, new_cursor_position: jint) {
Expand Down Expand Up @@ -371,7 +372,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 Expand Up @@ -437,9 +438,16 @@ impl ViewPeer for DemoViewPeer {
width: jint,
height: jint,
) {
self.tap_counter = TapCounter::new(ctx.view.view_configuration(&mut ctx.env));
let android_ctx = ctx.view.context(&mut ctx.env);
let scale_factor = {
let res = android_ctx.resources(&mut ctx.env);
let metrics = res.display_metrics(&mut ctx.env);
metrics.density(&mut ctx.env) as f64
};
self.tap_counter = TapCounter::new(ctx.view.view_configuration(&mut ctx.env), scale_factor);
let editor = self.editor.editor_mut();
editor.set_scale(1.0);
#[allow(clippy::cast_possible_truncation, reason = "Unavoidable")]
editor.set_scale(scale_factor as f32);
editor.set_width(Some(width as f32 - 2_f32 * text::INSET));
self.last_drawn_generation = Default::default();
let focused = ctx.view.is_focused(&mut ctx.env);
Expand Down
47 changes: 24 additions & 23 deletions demo/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ 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,
kurbo::{Affine, Line, Stroke},
kurbo::{Affine, Line, Rect, Stroke},
peniko::color::palette,
peniko::{Brush, Fill},
};
Expand Down Expand Up @@ -148,7 +148,7 @@ impl Editor {
pub fn cursor_blink(&mut self) {
self.cursor_visible = self.start_time.is_some_and(|start_time| {
let elapsed = Instant::now().duration_since(start_time);
(elapsed.as_millis() / self.blink_period.as_millis()) % 2 == 0
(elapsed.as_millis() / self.blink_period.as_millis()).is_multiple_of(2)
});
}

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 All @@ -346,10 +346,10 @@ impl Editor {
}

pub fn handle_accesskit_action_request(&mut self, req: &accesskit::ActionRequest) {
if req.action == accesskit::Action::SetTextSelection {
if let Some(accesskit::ActionData::SetTextSelection(selection)) = &req.data {
self.driver().select_from_accesskit(selection);
}
if req.action == accesskit::Action::SetTextSelection
&& let Some(accesskit::ActionData::SetTextSelection(selection)) = &req.data
{
self.driver().select_from_accesskit(selection);
}
}

Expand All @@ -363,25 +363,26 @@ impl Editor {
/// Returns drawn `Generation`.
pub fn draw(&mut self, scene: &mut Scene) -> Generation {
let transform = Affine::translate((INSET as f64, INSET as f64));
self.editor.selection_geometry_with(|rect, _| {
scene.fill(
Fill::NonZero,
transform,
palette::css::STEEL_BLUE,
None,
&rect,
);
});
if self.cursor_visible {
if let Some(cursor) = self.editor.cursor_geometry(5.0) {
self.editor
.selection_geometry_with(|parley::BoundingBox { x0, x1, y0, y1 }, _| {
scene.fill(
Fill::NonZero,
transform,
palette::css::CADET_BLUE,
palette::css::STEEL_BLUE,
None,
&cursor,
&Rect { x0, x1, y0, y1 },
);
}
});
if self.cursor_visible
&& let Some(parley::BoundingBox { x0, x1, y0, y1 }) = self.editor.cursor_geometry(5.0)
{
scene.fill(
Fill::NonZero,
transform,
palette::css::CADET_BLUE,
None,
&Rect { x0, x1, y0, y1 },
);
}
let layout = self.editor.layout(&mut self.font_cx, &mut self.layout_cx);
for line in layout.lines() {
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/linebender/xilem", rev = "de88321" }
masonry_android = { path = "../masonry" }

# Send tracing events to Android GPU inspector, for profiling
Expand Down
10 changes: 5 additions & 5 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 All @@ -29,7 +29,7 @@ struct Driver {
impl AppDriver for Driver {
fn on_action(&mut self, ctx: &mut DriverCtx<'_>, _widget_id: WidgetId, action: ErasedAction) {
if action.is::<ButtonPress>() {
ctx.render_root().edit_root_widget(|mut root| {
ctx.render_root().edit_base_layer(|mut root| {
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()).with_auto_id());
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/linebender/xilem", rev = "de88321" }
pollster = "0.4.0"
tracing = "0.1.40"
30 changes: 23 additions & 7 deletions masonry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ impl MasonryState {
default_properties,
use_system_fonts: true,
size_policy: WindowSizePolicy::User,
size: Default::default(),
scale_factor,
test_font: None,
},
Expand Down Expand Up @@ -170,6 +171,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 @@ -228,6 +232,15 @@ impl<Driver: AppDriver> MasonryViewPeer<Driver> {
};
info!("Widget selected in inspector: {widget_id} - {display_name}");
}
RenderRootSignal::NewLayer(..) => {
// TODO
}
RenderRootSignal::RepositionLayer(..) => {
// TODO
}
RenderRootSignal::RemoveLayer(..) => {
// TODO
}
}
}

Expand All @@ -243,10 +256,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 +331,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 +362,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 Expand Up @@ -436,9 +451,10 @@ impl<Driver: AppDriver> ViewPeer for MasonryViewPeer<Driver> {
width: jint,
height: jint,
) {
self.state.tap_counter = TapCounter::new(ctx.view.view_configuration(&mut ctx.env));
let android_ctx = ctx.view.context(&mut ctx.env);
let scale_factor = scale_factor(&mut ctx.env, &android_ctx);
self.state.tap_counter =
TapCounter::new(ctx.view.view_configuration(&mut ctx.env), scale_factor);
self.state
.render_root
.handle_window_event(WindowEvent::Rescale(scale_factor));
Expand Down
Loading