@@ -11,10 +11,10 @@ use android_view::{
1111 * ,
1212} ;
1313use 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} ;
1919use masonry_android:: { AppDriver , DriverCtx } ;
2020use std:: { ffi:: c_void, sync:: Arc } ;
@@ -27,43 +27,43 @@ struct Driver {
2727}
2828
2929impl 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
5456fn 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 } ,
0 commit comments