Skip to content

Commit

Permalink
Add scroll view to taffy example
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Nov 17, 2023
1 parent 551e55b commit 0c8d42b
Showing 1 changed file with 44 additions and 30 deletions.
74 changes: 44 additions & 30 deletions examples/taffy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use vello::peniko::Color;
use xilem::view::{button, div, flex_column, flex_row};
use xilem::view::{button, div, flex_column, flex_row, scroll_view};
use xilem::{view::View, App, AppLauncher};

use taffy::style::{AlignItems, JustifyContent};
Expand All @@ -15,42 +15,56 @@ fn app_logic(data: &mut i32) -> impl View<i32> {

// 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_background_color(Color::BLUE_VIOLET)
.with_style(|s| {
s.gap.width = length(20.0);
s.flex_grow = 1.0;
s.justify_content = Some(JustifyContent::Center);
s.align_items = Some(AlignItems::Center);
}),
div(String::from("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."))
div(String::from("FIXED HEADER"))
.with_background_color(Color::RED)
.with_style(|s| s.padding = length(20.0)),
div(())
.with_background_color(Color::FOREST_GREEN)
.with_style(|s| s.flex_grow = 1.0),
))
.with_style(|s| {
s.gap.height = length(20.0);
scroll_view(
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_background_color(Color::BLUE_VIOLET)
.with_style(|s| {
s.gap.width = length(20.0);
s.flex_grow = 1.0;
s.justify_content = Some(JustifyContent::Center);
s.align_items = Some(AlignItems::Center);
}),
div(String::from("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."))
.with_background_color(Color::RED)
.with_style(|s| s.padding = length(20.0)),
div(())
.with_background_color(Color::FOREST_GREEN)
.with_style(|s| s.flex_grow = 1.0),
))
.with_style(|s| {
s.size.height = length(1200.0);
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)
)
)).with_style(|s| {
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)
.with_background_color(Color::BLACK)
}

fn main() {
Expand Down

0 comments on commit 0c8d42b

Please sign in to comment.