Skip to content
Open
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
573 changes: 351 additions & 222 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 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"
vello = "0.6.0"

# Send tracing events to Android GPU inspector, for profiling
tracing_android_trace = "0.1.1"
Expand Down
3 changes: 2 additions & 1 deletion 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
41 changes: 21 additions & 20 deletions demo/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use ui_events::{
};
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 @@ -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" }

Choose a reason for hiding this comment

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

I think you could use the crates.io release instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It didn't exist at that point 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh and also that has to go in the ui-events 0.2.0 PR, because that's a separate set of changes.

masonry = { git = "https://github.com/linebender/xilem", rev = "2750659" }
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()),

Choose a reason for hiding this comment

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

You can make this code slightly more readable with Button::with_text.

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 = "2750659" }
pollster = "0.4.0"
tracing = "0.1.40"
29 changes: 22 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
}
Comment on lines +235 to +243

Choose a reason for hiding this comment

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

If you don't know how to handle those, you should replicate the version in masonry_winit which calls RenderRoot::add_layer and the like. We should probably document this in Masonry.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do, thanks.

}
}

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);
self.handle_signals(ctx);
}
result
Expand Down Expand Up @@ -436,9 +451,9 @@ 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));
self.state
.render_root
.handle_window_event(WindowEvent::Rescale(scale_factor));
Expand Down
16 changes: 10 additions & 6 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,11 @@ impl<'local> MotionEvent<'local> {
let contact_geometry = if pointer.pointer_type == PointerType::Touch {
let height = self.axis(env, Axis::TouchMajor, action_index) as f64;
let width = self.axis(env, Axis::TouchMinor, action_index) as f64;
(height > 0.0 && width > 0.0)
.then_some(ContactGeometry { width, height })
.unwrap_or_default()
if height > 0.0 && width > 0.0 {
ContactGeometry { width, height }
} else {
Default::default()
}
} else {
Default::default()
};
Expand Down Expand Up @@ -492,9 +494,11 @@ impl<'local> MotionEvent<'local> {
self.historical_axis(env, Axis::TouchMajor, action_index, pos) as f64;
let width =
self.historical_axis(env, Axis::TouchMinor, action_index, pos) as f64;
(height > 0.0 && width > 0.0)
.then_some(ContactGeometry { width, height })
.unwrap_or_default()
if height > 0.0 && width > 0.0 {
ContactGeometry { width, height }
} else {
Default::default()
}
} else {
Default::default()
};
Expand Down