use appy::{components::*, hooks::*, types::*, *}; use glapp::AppEvent; #[derive_component(ComponentBuilder, Default, SnakeFactory)] pub struct Slider { label: String, value: Option>, max: f32, } #[function_component] fn _slider(props: Slider) -> Elements { let mut val = use_state(|| 0.0); if props.value.is_some() { val = props.value.unwrap(); } let down = use_state(|| false); let app_context = use_context::(); let max = props.max; use_app_event(rc_with_clone!([val, app_context, down, max], move |e| { let update = rc_with_clone!([val, app_context], move |x: f32| { let v = max * (x - app_context.rect.x) / app_context.rect.w; val.set(v.max(0.0).min(max)); }); match *e { AppEvent::MouseDown { x, y, .. } => { if app_context.rect.contains(x, y) { update(x); down.set(true); } } AppEvent::MouseMove { x, .. } => { if *down { update(x); } } AppEvent::MouseUp { .. } => { down.set(false); } _ => {} } })); let p = (*val / max) * (app_context.rect.w - 20.); apx! { } } #[derive_component(ComponentBuilder, Default, SnakeFactory)] pub struct CheckBox { value: Option>, } #[function_component] fn _check_box(props: CheckBox) -> Elements { let mut val = use_state(|| false); if props.value.is_some() { val = props.value.unwrap(); } apx! { {if *val { apx!{ } } else {apx!{}}} } } #[derive_component(ComponentBuilder, Default, SnakeFactory)] pub struct Setting { text: String, value: Option>, max: f32, } #[function_component] fn _setting(props: Setting) -> Elements { apx! { } } #[main_window] fn main() -> Elements { let rad = use_state(|| 10.0); let border = use_state(|| 5.0); let borders = [ use_state(|| true), use_state(|| true), use_state(|| true), use_state(|| true), ]; apx! { {borders.iter().flat_map(move|b|{ apx!{ } }).collect()} } }