Skip to content
Snippets Groups Projects
Unverified Commit 0f7ab841 authored by Ygg01's avatar Ygg01
Browse files

Add rand to grow/shrink example

parent 33d09c82
No related branches found
No related tags found
No related merge requests found
......@@ -1904,6 +1904,7 @@ dependencies = [
"kayak_core",
"kayak_font",
"kayak_render_macros",
"rand",
]
[[package]]
......
......@@ -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"
......
......@@ -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),
_ => {}
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment