smoke_cocoa/
smoke_cocoa.rs1use rungui::*;
5
6fn main() {
7 let app = App::new("smoke-cocoa").expect("init");
8 let a = Window::new("cc-a");
9 let bar = MenuBar::new(a);
10 let file = Menu::new(bar, "File");
11 let flag = CheckMenuItem::new(file, "Flag");
12 flag.set_accel("Ctrl+K");
13 flag.on_toggle(|v| println!("MENUTOGGLE {v}"));
14 let go = MenuItem::new(file, "Go");
15 go.set_accel("Ctrl+Shift+G");
16 go.on_click(|| println!("MENU_GO"));
17 let quit = MenuItem::new(file, "Quit");
18 quit.set_accel("Ctrl+Q");
19 quit.on_click(|| {
20 println!("MENU_QUIT");
21 App::quit();
22 });
23
24 let col = VBox::new(a);
25 let row = HBox::new(col);
26 let btn = Button::new(row, "Press ünï");
27 let spin = SpinBox::new(row, 0.0, 10.0, 1.0);
28 let txt = TextInput::new(col);
29 let chk = CheckBox::new(col, "Monospace");
30 let hs = Splitter::new(col, Orientation::Horizontal);
31 let ta1 = TextArea::new(hs);
32 let ta2 = TextArea::new(hs);
33 ta2.set_text(
34 "long line without wrapping: 0123456789 0123456789 0123456789 0123456789 0123456789",
35 );
36 ta2.set_wrap(false);
37 hs.set_position(200);
38 hs.set_min_pane_sizes(60, 60);
39 let slider = Slider::new(col, 0.0, 100.0);
40 let combo = ComboBox::new(col);
41 combo.set_items(&["x", "y", "z"]);
42 let tabs = Tabs::new(col);
43 let p1 = tabs.add_page("First");
44 let p2 = tabs.add_page("Second");
45 Label::new(p1, "page one");
46 Label::new(p2, "page two");
47 let vs = Splitter::new(col, Orientation::Vertical);
48 let table = Table::new(vs);
49 table.set_columns(&[
50 Column::new("Name").width(80).sortable(true),
51 Column::new("Size").align(ColumnAlign::Right),
52 ]);
53 table.set_rows(&[vec!["a", "1"], vec!["b", "2"], vec!["c", "3"]]);
54 let tree = Tree::new(vs);
55 let root = tree.add(None, "root");
56 tree.add(Some(root), "kid");
57 let lazy = tree.add(None, "lazy");
58 tree.set_has_children(lazy, true);
59 vs.set_position(100);
60 vs.set_min_pane_sizes(40, 40);
61
62 btn.on_click(|| println!("CLICK"));
63 spin.on_change(|v| println!("SPIN {v}"));
64 txt.on_change(|t| println!("TEXT {t}"));
65 ta1.on_change(|t| println!("AREA {}", t.replace('\n', "|")));
66 chk.on_toggle(move |on| {
67 println!("MONO {on}");
68 txt.set_monospace(on);
69 ta1.set_monospace(on);
70 });
71 hs.on_move(|p| println!("HSPLIT {p}"));
72 vs.on_move(|p| println!("VSPLIT {p}"));
73 slider.on_change(|v| println!("VALUE {v:.0}"));
74 combo.on_select(|i| println!("COMBO {i:?}"));
75 tabs.on_select(|i| println!("TAB {i:?}"));
76 table.on_select(|i| println!("TABLE_SEL {i:?}"));
77 table.on_column_click(move |c| {
78 let ascending = table.sort_indicator() != Some((c, true));
79 let mut rows = table.rows();
80 rows.sort_by(|x, y| x[c].cmp(&y[c]));
81 if !ascending {
82 rows.reverse();
83 }
84 table.set_rows(&rows);
85 table.set_sort_indicator(Some((c, ascending)));
86 println!(
87 "TABLE_COL {c} {} {}",
88 if ascending { "asc" } else { "desc" },
89 rows[0][0]
90 );
91 });
92 tree.on_select(move |n| println!("TREE_SEL {}", n.is_some()));
93 tree.on_expand(|_, open| println!("TREE_EXPAND {open}"));
94 a.set_context_menu({
95 let p = PopupMenu::new();
96 MenuItem::new(p, "Ctx item").on_click(|| println!("CTXMENU"));
97 p
98 });
99 a.on_resize(|w, h| println!("RESIZED {w} {h}"));
100 a.on_move(|x, y| println!("MOVED {x} {y}"));
101 a.set_min_size(300, 400);
102 a.set_position(220, 100);
103 a.set_size(560, 700);
104 a.on_close(|| {
105 println!("CLOSE_REQUESTED");
106 true
107 });
108 a.show();
109 println!(
110 "HANDLE {}",
111 a.native_handle().is_some() && btn.native_handle().is_some()
112 );
113 let _t = Timer::once(700, move || {
114 for (n, w) in [
115 ("btn", btn.bounds()),
116 ("spin", spin.bounds()),
117 ("txt", txt.bounds()),
118 ("chk", chk.bounds()),
119 ("hs", hs.bounds()),
120 ("slider", slider.bounds()),
121 ("combo", combo.bounds()),
122 ("tabs", tabs.bounds()),
123 ("vs", vs.bounds()),
124 ("table", table.bounds()),
125 ("tree", tree.bounds()),
126 ] {
127 println!("BOUNDS {n} {} {} {} {}", w.x, w.y, w.w, w.h);
128 }
129 println!("SPLITPOS h {} v {}", hs.position(), vs.position());
130 println!("READY");
131 });
132 app.run();
133 println!("BYE");
134}