use appy::{components::*, hooks::*, types::*, *}; use glapp::AppEvent; #[derive_component(ComponentBuilder, Default, SnakeFactory)] pub struct Slider { 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 FlowItem { text: String, } #[function_component] fn _flow_item(props: FlowItem) -> Elements { let app_context = use_context::(); let w = app_context.default_font.get_str_width(&*props.text, 24.); 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] pub fn app() -> Elements { let width_pct = use_state(|| 50.0); let height_pct = use_state(|| 50.0); let num_words = use_state(|| 10.0); let gap = use_state(|| 10.0); let vgap = use_state(|| 10.0); let align = use_state(|| Align::Left); let valign = use_state(|| VAlign::Top); let lorem="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam convallis nisl sit amet neque iaculis commodo. Maecenas viverra imperdiet sem vel scelerisque. Nullam cursus, justo id dapibus sollicitudin, nisl justo tempor massa, quis mollis dolor risus vitae lorem. Nam id nunc dapibus nunc elementum congue. Sed augue justo, vehicula eu enim nec, maximus varius nisi. Vivamus dapibus magna id nisl eleifend egestas. Cras rhoncus eros eu magna venenatis vestibulum. Cras nisi sapien, finibus non risus eget, blandit vehicula mi. Fusce venenatis eleifend nisi, eu varius sem bibendum vitae. Sed lobortis arcu ut tortor elementum, et luctus nunc malesuada. Etiam vestibulum."; let mut flow_items: Elements = vec![]; let mut n: i32 = 0; for word in lorem.split([' ', '\n']) { if n <= *num_words as i32 { flow_items.append(&mut apx! { }); } n += 1; } apx! { {flow_items} } }