smoke_dialogs/
smoke_dialogs.rs1use rungui::*;
4
5fn main() {
6 let app = App::new("smoke-dialogs").expect("init");
7 let win = Window::new("smoke-dialogs");
8 let col = VBox::new(win);
9 let field = TextInput::new(col);
10 field.on_activate(|| println!("ACTIVATE"));
11 let ask = Button::new(col, "Ask");
12 ask.on_click(move || {
13 let r = Prompt::new("Rename").message("New name?").initial("old").run(Some(win));
14 println!("PROMPT {r:?}");
15 });
16 let modal = Button::new(col, "Modal");
17 modal.on_click(move || {
18 let d = Window::new("smoke-modal");
19 Label::new(d, "modal window");
20 let close = Button::new(d, "Close");
21 close.on_click(move || d.hide());
22 d.on_cancel(move || {
23 println!("MODAL_CANCEL");
24 d.hide();
25 });
26 println!("MODAL_OPEN");
27 d.run_modal(Some(win));
28 println!("MODAL_DONE");
29 d.destroy();
30 });
31 let list = ListBox::new(col);
32 list.set_items(&["one", "two", "three", "four", "five"]);
33 list.set_multi_select(true);
34 list.on_selection(|s| println!("LIST_SEL {s:?}"));
35 let table = Table::new(col);
36 table.set_columns(&[Column::new("Name").width(100)]);
37 table.set_rows(&[vec!["a"], vec!["b"], vec!["c"], vec!["d"]]);
38 table.set_multi_select(true);
39 table.on_selection(|s| println!("TABLE_SEL {s:?}"));
40 let cal = Calendar::new(col);
41 cal.set_date(Date::new(2031, 7, 4).unwrap());
42 cal.on_change(|d| println!("DATE {}-{:02}-{:02}", d.year, d.month, d.day));
43 win.on_close(|| {
44 App::quit();
45 true
46 });
47 win.show();
48 println!("TODAY {:?}", Date::today().is_valid());
49 let _t = Timer::once(600, move || {
50 for (n, w) in [
51 ("field", field.bounds()),
52 ("ask", ask.bounds()),
53 ("modal", modal.bounds()),
54 ("list", list.bounds()),
55 ("table", table.bounds()),
56 ("cal", cal.bounds()),
57 ] {
58 println!("BOUNDS {n} {} {} {} {}", w.x, w.y, w.w, w.h);
59 }
60 println!("READY");
61 });
62 let _exit = std::env::var("RUNGUI_EXIT_AFTER_MS")
63 .ok()
64 .and_then(|v| v.parse::<u32>().ok())
65 .map(|ms| Timer::once(ms, App::quit));
66 app.run();
67 println!("BYE");
68}