Skyler Grey | cfee096 | 2022-08-19 22:40:53 +0100 | [diff] [blame] | 1 | use cursive::theme; |
| 2 | use cursive::theme::BaseColor; |
| 3 | use cursive::theme::Color; |
| 4 | use cursive::traits::Nameable; |
| 5 | use cursive::views::Checkbox; |
| 6 | use cursive::views::Dialog; |
| 7 | use cursive::views::ListView; |
| 8 | use cursive::views::NamedView; |
| 9 | use cursive::views::TextView; |
| 10 | use cursive::Cursive; |
| 11 | |
| 12 | fn button_pressed(siv: &mut Cursive) { |
| 13 | siv.quit(); |
| 14 | } |
| 15 | |
| 16 | fn checkbox_changed(i: i8) -> impl Fn(&mut Cursive, bool) { |
| 17 | return move |siv: &mut Cursive, value: bool| { |
| 18 | let un = if value { "" } else { "un" }; |
| 19 | let mut dialog = Dialog::around(TextView::new(format!("You {un}checked checkbox {i}"))); |
| 20 | dialog.add_button("Close", |siv| { |
| 21 | siv.pop_layer(); |
| 22 | }); |
| 23 | siv.add_layer(dialog); |
| 24 | }; |
| 25 | } |
| 26 | |
| 27 | fn main() { |
| 28 | let mut siv = cursive::default(); |
| 29 | |
| 30 | let mut siv_theme = theme::load_default(); |
| 31 | siv_theme |
| 32 | .palette |
| 33 | .set_color("background", Color::Dark(BaseColor::Black)); |
| 34 | siv_theme.palette.set_color("view", Color::Rgb(49, 54, 64)); |
| 35 | siv_theme |
| 36 | .palette |
| 37 | .set_color("primary", Color::Dark(BaseColor::White)); |
| 38 | siv_theme.shadow = false; |
| 39 | siv.set_theme(siv_theme); |
| 40 | // siv.set_theme() |
| 41 | |
| 42 | let mut list = ListView::new(); |
| 43 | |
| 44 | for i in 0..3 { |
| 45 | let checkbox = Checkbox::new() |
| 46 | .on_change(checkbox_changed(i)) |
| 47 | .with_name("checkbox".to_owned() + i.to_string().as_str()); |
| 48 | list.add_child((i.to_string() + ": A checkbox").as_str(), checkbox); |
| 49 | } |
| 50 | |
| 51 | let mut base_layer = Dialog::around(NamedView::new("checkboxes", list)); |
| 52 | base_layer.add_button("I'm done", button_pressed); |
| 53 | |
| 54 | siv.add_layer(base_layer); |
| 55 | |
| 56 | siv.run(); |
| 57 | } |