Skip to content

Commit

Permalink
Add taffy example
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Nov 1, 2023
1 parent a5177a2 commit e81c642
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions examples/taffy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use xilem::view::{button, flex_column, flex_row};
use xilem::{view::View, App, AppLauncher};

use taffy::style::{AlignItems, AlignSelf};
use taffy::style_helpers::length;

fn app_logic(data: &mut i32) -> impl View<i32> {
// here's some logic, deriving state for the view from our state
let label = if *data == 1 {
"clicked 1 time".to_string()
} else {
format!("clicked {data} times")
};

// The actual UI Code starts here
flex_column((
button(label, |data| {
println!("clicked");
*data += 1;
}),
flex_row((
button("decrease", |data| {
println!("clicked decrease");
*data -= 1;
}),
button("reset", |data| {
println!("clicked reset");
*data = 0;
}),
))
.with_style(|s| {
s.flex_grow = 1.0;
s.align_self = Some(AlignSelf::Center);
s.align_items = Some(AlignItems::Center);
}),
))
.with_style(|s| s.gap.height = length(20.0))
}

fn main() {
let app = App::new(0, app_logic);
AppLauncher::new(app).run()
}

0 comments on commit e81c642

Please sign in to comment.