Skip to content

Instantly share code, notes, and snippets.

@Fredemus
Created March 23, 2023 23:24
Show Gist options
  • Save Fredemus/de1a0e749c7d26409584598fbc0173e5 to your computer and use it in GitHub Desktop.
Save Fredemus/de1a0e749c7d26409584598fbc0173e5 to your computer and use it in GitHub Desktop.
use vizia::prelude::*;
#[derive(Lens)]
pub struct AppData {
pub check1: bool,
pub check2: bool,
pub test: Vec<String>,
}
impl Model for AppData {}
fn main() {
Application::new(|cx| {
AppData {
check1: false,
check2: true,
test: vec!["test1".to_owned(), "test2".to_owned(), "test3".to_owned()],
}
.build(cx);
MenuController::new(cx, false, |cx| {
MenuStack::new_horizontal(cx, |cx| {
Menu::new(
cx,
|cx| Label::new(cx, "menu 1"),
|cx| {
List::new(cx, AppData::test, |cx, _, val| {
let text = val.get(cx);
// create nested dropdown
if &text == "test1" {
Menu::new(
cx,
move |cx| Label::new(cx, &text.clone()),
|cx| {
MenuButton::new_simple(cx, "nested1", |_| {});
MenuButton::new_simple(cx, "nested2", |_| {});
},
);
} else {
MenuButton::new_simple(cx, val, |_| {});
}
});
},
);
Menu::new(
cx,
|cx| Label::new(cx, "menu 2"),
|cx| {
Menu::new(
cx,
move |cx| Label::new(cx, "test1"),
|cx| {
MenuButton::new_simple(cx, "nested1", |_| {});
MenuButton::new_simple(cx, "nested2", |_| {});
},
);
MenuButton::new_simple(cx, "test2", |_| {});
MenuButton::new_simple(cx, "test3", |_| {});
},
);
});
});
})
.title("Menu")
.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment