diff --git a/Cargo.lock b/Cargo.lock index f042d6ecd92276a5e56632d11a19afef21563cdc..9f711643a12626729f604b7134a93a2ebf5b9ad1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1904,6 +1904,7 @@ dependencies = [ "kayak_core", "kayak_font", "kayak_render_macros", + "rand", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index e6cddfcfb511d18f6f90602c7482599b32df3f1f..82d186d16f99128a07da7fb5ec0adeced25d9019 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ kayak_render_macros = { path = "kayak_render_macros" } [dev-dependencies] bevy = { version = "0.6.0" } +rand = { version = "0.8.4" } [[example]] name = "todo" diff --git a/examples/shrink_grow_layout.rs b/examples/shrink_grow_layout.rs index c25cbcadb4149682f1aab906368342ad5c990b23..041b4e5346d55baaf57cf5082c099ac71fecdc38 100644 --- a/examples/shrink_grow_layout.rs +++ b/examples/shrink_grow_layout.rs @@ -15,12 +15,15 @@ use kayak_core::{ }; use kayak_core::{Color, EventType, OnEvent}; use kayak_render_macros::use_state; -use kayak_ui::{core::{render, rsx, widget, Index}, widgets::Background}; use kayak_ui::widgets::{App, Text, Window}; use kayak_ui::{ bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}, widgets::Button, }; +use kayak_ui::{ + core::{render, rsx, widget, Index}, + widgets::Background, +}; /// This widget provides a theme to its children #[widget] @@ -30,7 +33,7 @@ fn GrowShrink() { let panel_style = Style { layout_type: StyleProp::Value(LayoutType::Row), - background_color: StyleProp::Value(Color::new(0.33, 0.33, 0.33,0.2)), + background_color: StyleProp::Value(Color::new(0.33, 0.33, 0.33, 0.2)), width: StyleProp::Value(Units::Auto), height: StyleProp::Value(Units::Pixels(50.0)), ..Default::default() @@ -39,7 +42,7 @@ fn GrowShrink() { // Grow/Shrink button styles let button_styles = Style { width: StyleProp::Value(Units::Pixels(100.0)), - height: StyleProp::Value(Units::Pixels(24.0)), + height: StyleProp::Value(Units::Pixels(24.0)), background_color: StyleProp::Value(Color::new(0.33, 0.33, 0.33, 1.0)), ..Default::default() }; @@ -58,12 +61,12 @@ fn GrowShrink() { let shrink_fn = set_width.clone(); let grow = OnEvent::new(move |_, event| match event.event_type { - EventType::Click(..) => grow_fn(background_width + 10.0), + EventType::Click(..) => grow_fn(background_width + rand::random::<f32>() * 10.0), _ => {} }); let shrink = OnEvent::new(move |_, event| match event.event_type { - EventType::Click(..) => shrink_fn(background_width - 10.0), + EventType::Click(..) => shrink_fn(background_width - rand::random::<f32>() * 10.0), _ => {} });