Skip to content

Commit

Permalink
Update taffy example to use background colours
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Nov 2, 2023
1 parent b9330a8 commit 7eae31b
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions examples/taffy.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use xilem::view::{button, flex_column, flex_row};
use vello::peniko::Color;
use xilem::view::{button, div, flex_column, flex_row};
use xilem::{view::View, App, AppLauncher};

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

fn app_logic(data: &mut i32) -> impl View<i32> {
Expand All @@ -28,13 +29,25 @@ fn app_logic(data: &mut i32) -> impl View<i32> {
*data = 0;
}),
))
.with_background_color(Color::BLUE_VIOLET)
.with_style(|s| {
s.gap.width = length(20.0);
s.flex_grow = 1.0;
s.align_self = Some(AlignSelf::Center);
s.justify_content = Some(JustifyContent::Center);
s.align_items = Some(AlignItems::Center);
}),
div(())
.with_background_color(Color::RED)
.with_style(|s| s.flex_grow = 1.0),
))
.with_style(|s| s.gap.height = length(20.0))
.with_style(|s| {
s.gap.height = length(20.0);
s.padding.left = length(20.0);
s.padding.right = length(20.0);
s.padding.top = length(20.0);
s.padding.bottom = length(20.0);
})
.with_background_color(Color::WHITE)
}

fn main() {
Expand Down

0 comments on commit 7eae31b

Please sign in to comment.