Skip to content

Commit 5397176

Browse files
committed
Update Masonry
1 parent f17cab0 commit 5397176

File tree

4 files changed

+39
-41
lines changed

4 files changed

+39
-41
lines changed

Cargo.lock

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

masonry-demo/src/lib.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ use android_view::{
1111
*,
1212
};
1313
use masonry::{
14-
core::{Action, Properties, Widget, WidgetId, WidgetPod},
14+
core::{ErasedAction, NewWidget, Properties, Widget, WidgetId},
1515
properties::Padding,
1616
theme::default_property_set,
17-
widgets::{Button, Flex, Label, Portal, TextArea, TextInput},
17+
widgets::{Button, ButtonPress, Flex, Label, Portal, TextAction, TextArea, TextInput},
1818
};
1919
use masonry_android::{AppDriver, DriverCtx};
2020
use std::{ffi::c_void, sync::Arc};
@@ -27,43 +27,43 @@ struct Driver {
2727
}
2828

2929
impl AppDriver for Driver {
30-
fn on_action(&mut self, ctx: &mut DriverCtx<'_>, _widget_id: WidgetId, action: Action) {
31-
match action {
32-
Action::ButtonPressed(_) => {
33-
ctx.render_root().edit_root_widget(|mut root| {
34-
let mut portal = root.downcast::<Portal<Flex>>();
35-
let mut flex = Portal::child_mut(&mut portal);
36-
Flex::add_child(&mut flex, Label::new(self.next_task.clone()));
30+
fn on_action(&mut self, ctx: &mut DriverCtx<'_>, _widget_id: WidgetId, action: ErasedAction) {
31+
if action.is::<ButtonPress>() {
32+
ctx.render_root().edit_root_widget(|mut root| {
33+
let mut portal = root.downcast::<Portal<Flex>>();
34+
let mut flex = Portal::child_mut(&mut portal);
35+
Flex::add_child(&mut flex, Label::new(self.next_task.clone()).with_auto_id());
3736

38-
let mut first_row = Flex::child_mut(&mut flex, 0).unwrap();
39-
let mut first_row = first_row.downcast::<Flex>();
40-
let mut text_input = Flex::child_mut(&mut first_row, 0).unwrap();
41-
let mut text_input = text_input.downcast::<TextInput>();
42-
let mut text_area = TextInput::text_mut(&mut text_input);
43-
TextArea::reset_text(&mut text_area, "");
44-
});
37+
let mut first_row = Flex::child_mut(&mut flex, 0).unwrap();
38+
let mut first_row = first_row.downcast::<Flex>();
39+
let mut text_input = Flex::child_mut(&mut first_row, 0).unwrap();
40+
let mut text_input = text_input.downcast::<TextInput>();
41+
let mut text_area = TextInput::text_mut(&mut text_input);
42+
TextArea::reset_text(&mut text_area, "");
43+
});
44+
} else if action.is::<TextAction>() {
45+
let action = action.downcast::<TextAction>().unwrap();
46+
match *action {
47+
TextAction::Changed(new_text) => {
48+
self.next_task = new_text.clone();
49+
}
50+
TextAction::Entered(_) => {}
4551
}
46-
Action::TextChanged(new_text) => {
47-
self.next_task = new_text.clone();
48-
}
49-
_ => {}
5052
}
5153
}
5254
}
5355

5456
fn make_widget_tree() -> impl Widget {
5557
Portal::new(
5658
Flex::column()
57-
.with_child_pod(
58-
WidgetPod::new_with_props(
59-
Flex::row()
60-
.with_flex_child(TextInput::new(""), 1.0)
61-
.with_child(Button::new("Add task")),
62-
Properties::new().with(Padding::all(WIDGET_SPACING)),
63-
)
64-
.erased(),
65-
)
66-
.with_spacer(WIDGET_SPACING),
59+
.with_child(NewWidget::new_with_props(
60+
Flex::row()
61+
.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)),
64+
))
65+
.with_spacer(WIDGET_SPACING)
66+
.with_auto_id(),
6767
)
6868
}
6969

@@ -75,7 +75,7 @@ extern "system" fn new_view_peer<'local>(
7575
masonry_android::new_view_peer(
7676
&mut env,
7777
&context,
78-
WidgetPod::new(make_widget_tree()).erased(),
78+
NewWidget::new(make_widget_tree()).erased(),
7979
Driver {
8080
next_task: String::new(),
8181
},

masonry/src/app_driver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use masonry::{
55
app::RenderRoot,
6-
core::{Action, WidgetId},
6+
core::{ErasedAction, WidgetId},
77
};
88

99
use crate::MasonryState;
@@ -27,7 +27,7 @@ pub struct DriverCtx<'a> {
2727
/// a type that implements this trait.
2828
pub trait AppDriver {
2929
/// A hook which will be executed when a widget emits an [`Action`].
30-
fn on_action(&mut self, ctx: &mut DriverCtx<'_>, widget_id: WidgetId, action: Action);
30+
fn on_action(&mut self, ctx: &mut DriverCtx<'_>, widget_id: WidgetId, action: ErasedAction);
3131

3232
#[expect(unused_variables, reason = "Default impl doesn't use arguments")]
3333
/// A hook which will be executed when the application starts, to allow initial configuration of the `MasonryState`.

masonry/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ use android_view::{
1111
*,
1212
};
1313
use masonry::{
14-
Handled,
1514
app::{RenderRoot, RenderRootOptions, RenderRootSignal, WindowSizePolicy},
16-
core::{DefaultProperties, TextEvent, Widget, WidgetPod, WindowEvent},
15+
core::{DefaultProperties, Handled, NewWidget, TextEvent, Widget, WindowEvent},
1716
dpi::PhysicalSize,
1817
peniko::Color,
1918
util::Instant,
@@ -99,7 +98,7 @@ pub struct MasonryState {
9998

10099
impl MasonryState {
101100
pub fn new(
102-
root_widget: WidgetPod<dyn Widget>,
101+
root_widget: NewWidget<dyn Widget>,
103102
default_properties: Arc<DefaultProperties>,
104103
scale_factor: f64,
105104
) -> Self {
@@ -594,7 +593,7 @@ impl<Driver: AppDriver> AccessibilityNodeProvider for MasonryViewPeer<Driver> {
594593
pub fn new_view_peer<'local>(
595594
env: &mut JNIEnv<'local>,
596595
android_ctx: &Context<'local>,
597-
root_widget: WidgetPod<dyn Widget>,
596+
root_widget: NewWidget<dyn Widget>,
598597
mut app_driver: impl AppDriver + 'static,
599598
default_properties: Arc<DefaultProperties>,
600599
) -> jlong {

0 commit comments

Comments
 (0)