11use cursive:: {
22 theme:: { BorderStyle , ColorStyle , Palette , Theme } ,
3- view:: IntoBoxedView ,
4- views:: { Layer , Panel , TextView } ,
5- Cursive , CursiveExt ,
3+ view:: { IntoBoxedView , Resizable , Nameable } ,
4+ views:: { Layer , Panel , TextView , EditView , TextArea , Button } ,
5+ Cursive , CursiveExt , With ,
66} ;
77
88use cursive_flexbox:: prelude:: * ;
@@ -27,8 +27,8 @@ fn main() {
2727 ) )
2828 . into_boxed_view( ) ,
2929 Panel :: new( Layer :: with_color(
30- TextView :: new( "I doubt I will be wrapped..." ) ,
31- ColorStyle :: back( cursive:: theme:: BaseColor :: Green . dark( ) ) ,
30+ EditView :: new( ) . with ( |v| { v . set_content ( "I doubt I will be wrapped..." ) ; } ) . min_width ( 28 ) ,
31+ ColorStyle :: back( cursive:: theme:: BaseColor :: Blue . dark( ) ) ,
3232 ) )
3333 . into_boxed_view( ) ,
3434 Panel :: new( Layer :: with_color(
@@ -37,16 +37,25 @@ fn main() {
3737 ) )
3838 . into_boxed_view( ) ,
3939 Panel :: new( Layer :: with_color(
40- TextView :: new(
40+ TextArea :: new( ) . with ( |v| { v . set_content (
4141 "And a bigger container\n to test out the alignment\n of items in the main \
42- axis\n a bit better.",
43- ) ,
44- ColorStyle :: back( cursive:: theme:: BaseColor :: Green . dark( ) ) ,
42+ axis\n a bit better.\n \n Edit me. ",
43+ ) ; } ) . min_width ( 20 ) ,
44+ ColorStyle :: back( cursive:: theme:: BaseColor :: Blue . dark( ) ) ,
4545 ) )
4646 . into_boxed_view( ) ,
4747 Panel :: new( Layer :: with_color(
48- TextView :: new( "And a final item for good luck." ) ,
49- ColorStyle :: back( cursive:: theme:: BaseColor :: Green . dark( ) ) ,
48+ Button :: new( "And a final button for good luck." , |c| {
49+ let mut flexbox = c. find_name:: <Flexbox >( "flexbox" ) . unwrap( ) ;
50+ let new_align = match flexbox. align_items( ) {
51+ AlignItems :: FlexStart => AlignItems :: Center ,
52+ AlignItems :: Center => AlignItems :: FlexEnd ,
53+ AlignItems :: FlexEnd => AlignItems :: Stretch ,
54+ AlignItems :: Stretch => AlignItems :: FlexStart ,
55+ } ;
56+ flexbox. set_align_items( new_align) ;
57+ } ) ,
58+ ColorStyle :: back( cursive:: theme:: BaseColor :: Red . dark( ) ) ,
5059 ) )
5160 . into_boxed_view( ) ,
5261 ] ) ;
@@ -77,7 +86,7 @@ fn main() {
7786 flexbox. set_flex_direction ( FlexDirection :: Row ) ;
7887
7988 // Add the flexbox to the ui.
80- cursive. add_fullscreen_layer ( flexbox) ;
89+ cursive. add_fullscreen_layer ( flexbox. with_name ( "flexbox" ) ) ;
8190
8291 // Start running the eventloop.
8392 cursive. run ( ) ;
0 commit comments