diff --git a/crates/yakui/examples/dropdown.rs b/crates/yakui/examples/dropdown.rs index 09ef7ad1..de5e1191 100644 --- a/crates/yakui/examples/dropdown.rs +++ b/crates/yakui/examples/dropdown.rs @@ -3,51 +3,70 @@ #![allow(clippy::collapsible_if)] -use yakui::widgets::Layer; -use yakui::{align, button, column, reflow, use_state, widgets::Pad, Alignment, Dim2}; +use yakui::widgets::{Layer, Scrollable}; +use yakui::{button, column, reflow, use_state, widgets::Pad, Alignment, Dim2}; +use yakui::{constrained, row, Constraints, Vec2}; use yakui_core::Pivot; pub fn run() { let open = use_state(|| false); - let options = ["Hello", "World", "Foobar"]; + let options = ["Hello", "World", "Foobar", "Meow", "Woof"]; let selected = use_state(|| 0); - align(Alignment::TOP_LEFT, || { - column(|| { - if button("Upper Button").clicked { - println!("Upper button clicked"); - } - - column(|| { - if button(options[selected.get()]).clicked { - open.modify(|x| !x); - } - - if open.get() { - Pad::ZERO.show(|| { - Layer::new().show(|| { - reflow(Alignment::BOTTOM_LEFT, Pivot::TOP_LEFT, Dim2::ZERO, || { - column(|| { - let current = selected.get(); - for (i, option) in options.iter().enumerate() { - if i != current { - if button(*option).clicked { - selected.set(i); - open.set(false); - } - } - } + row(|| { + constrained(Constraints::loose(Vec2::new(f32::INFINITY, 50.0)), || { + Scrollable::vertical().show(|| { + column(|| { + if button("Upper Button").clicked { + println!("Upper button clicked"); + } + + column(|| { + if button(options[selected.get()]).clicked { + open.modify(|x| !x); + } + + if open.get() { + Pad::ZERO.show(|| { + Layer::new().show(|| { + reflow( + Alignment::BOTTOM_LEFT, + Pivot::TOP_LEFT, + Dim2::ZERO, + || { + constrained( + Constraints::loose(Vec2::new(f32::INFINITY, 80.0)), + || { + Scrollable::vertical().show(|| { + column(|| { + let current = selected.get(); + for (i, option) in + options.iter().enumerate() + { + if i != current { + if button(*option).clicked { + selected.set(i); + open.set(false); + } + } + } + }); + }); + }, + ); + }, + ); }); }); - }); + } }); - } + }); }); - - if button("Lower Button").clicked { - println!("Lower button clicked"); - } }); + + if button("Side Button").clicked { + println!("Side button clicked"); + } }); }