From 0f7ab841089462370473193ce85073ec63f6757e Mon Sep 17 00:00:00 2001 From: Ygg01 <y.laughing.man.y@gmail.com> Date: Wed, 23 Mar 2022 03:32:47 +0100 Subject: [PATCH] Add rand to grow/shrink example --- Cargo.lock | 1 + Cargo.toml | 1 + examples/shrink_grow_layout.rs | 13 ++++++++----- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f042d6e..9f71164 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 e6cddfc..82d186d 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 c25cbca..041b4e5 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), _ => {} }); -- GitLab