Skip to content

Commit

Permalink
more sophisticated example for dropdown to test SecondHalfGames#149
Browse files Browse the repository at this point in the history
  • Loading branch information
msparkles committed Apr 17, 2024
1 parent 3a61051 commit 6ef5e05
Showing 1 changed file with 53 additions and 34 deletions.
87 changes: 53 additions & 34 deletions crates/yakui/examples/dropdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
});
}

Expand Down

0 comments on commit 6ef5e05

Please sign in to comment.