Skip to content

Commit

Permalink
Update simple_flexbox example to demonstrate focusing.
Browse files Browse the repository at this point in the history
  • Loading branch information
abutcher-gh committed Jul 2, 2023
1 parent af2ce94 commit c59f4e3
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions examples/simple_flexbox.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use cursive::{
theme::{BorderStyle, ColorStyle, Palette, Theme},
view::IntoBoxedView,
views::{Layer, Panel, TextView},
Cursive, CursiveExt,
view::{IntoBoxedView, Resizable, Nameable},
views::{Layer, Panel, TextView, EditView, TextArea, Button},
Cursive, CursiveExt, With,
};

use cursive_flexbox::prelude::*;
Expand All @@ -27,8 +27,8 @@ fn main() {
))
.into_boxed_view(),
Panel::new(Layer::with_color(
TextView::new("I doubt I will be wrapped..."),
ColorStyle::back(cursive::theme::BaseColor::Green.dark()),
EditView::new().with(|v| { v.set_content("I doubt I will be wrapped..."); }).min_width(28),
ColorStyle::back(cursive::theme::BaseColor::Blue.dark()),
))
.into_boxed_view(),
Panel::new(Layer::with_color(
Expand All @@ -37,16 +37,25 @@ fn main() {
))
.into_boxed_view(),
Panel::new(Layer::with_color(
TextView::new(
TextArea::new().with(|v| { v.set_content(
"And a bigger container\nto test out the alignment\nof items in the main \
axis\na bit better.",
),
ColorStyle::back(cursive::theme::BaseColor::Green.dark()),
axis\na bit better.\n\nEdit me.",
); }).min_width(20),
ColorStyle::back(cursive::theme::BaseColor::Blue.dark()),
))
.into_boxed_view(),
Panel::new(Layer::with_color(
TextView::new("And a final item for good luck."),
ColorStyle::back(cursive::theme::BaseColor::Green.dark()),
Button::new("And a final button for good luck.", |c| {
let mut flexbox = c.find_name::<Flexbox>("flexbox").unwrap();
let new_align = match flexbox.align_items() {
AlignItems::FlexStart => AlignItems::Center,
AlignItems::Center => AlignItems::FlexEnd,
AlignItems::FlexEnd => AlignItems::Stretch,
AlignItems::Stretch => AlignItems::FlexStart,
};
flexbox.set_align_items(new_align);
}),
ColorStyle::back(cursive::theme::BaseColor::Red.dark()),
))
.into_boxed_view(),
]);
Expand Down Expand Up @@ -77,7 +86,7 @@ fn main() {
flexbox.set_flex_direction(FlexDirection::Row);

// Add the flexbox to the ui.
cursive.add_fullscreen_layer(flexbox);
cursive.add_fullscreen_layer(flexbox.with_name("flexbox"));

// Start running the eventloop.
cursive.run();
Expand Down

0 comments on commit c59f4e3

Please sign in to comment.