From e81c64271e13f02056f206116632ed6499db95b5 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 1 Nov 2023 20:36:12 +0000 Subject: [PATCH] Add taffy example --- examples/taffy.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 examples/taffy.rs diff --git a/examples/taffy.rs b/examples/taffy.rs new file mode 100644 index 000000000..f7333b4b3 --- /dev/null +++ b/examples/taffy.rs @@ -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 { + // 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() +}