Skip to main content

smoke_layout/
smoke_layout.rs

1//! Second scripted smoke target (driven by scripts/smoke-gtk.sh): splitter drag, monospace / wrap,
2//! window position, window shrinking and a table + tree inside splitters. Prints one line per
3//! event and the splitter / window bounds on stdout.
4use rungui::*;
5
6fn main() {
7    let app = App::new("smoke-layout").expect("init");
8    let w = Window::new("smoke-layout");
9    w.set_position(120, 90);
10    let col = VBox::new(w);
11    let mono = TextInput::new(col);
12    mono.set_monospace(true);
13    mono.set_text("monospace entry");
14    let hs = Splitter::new(col, Orientation::Horizontal);
15    hs.set_position(200);
16    hs.set_min_pane_sizes(60, 60);
17    let area = TextArea::new(hs);
18    area.set_monospace(true);
19    area.set_wrap(false);
20    area.set_text("a long line that does not wrap: 0123456789 0123456789 0123456789 0123456789\n");
21    let table = Table::new(hs);
22    table.set_columns(&[Column::new("Name").width(80), Column::new("Size")]);
23    table.set_rows(&[vec!["a", "1"], vec!["b", "2"]]);
24    let vs = Splitter::new(col, Orientation::Vertical);
25    let tree = Tree::new(vs);
26    let r = tree.add(None, "root");
27    tree.add(Some(r), "kid");
28    let list = ListBox::new(vs);
29    list.set_items(&["one", "two"]);
30    table.on_select(|i| println!("TABLE_SEL {i:?}"));
31    tree.on_select(|n| println!("TREE_SEL {}", n.is_some()));
32    tree.on_expand(|_, open| println!("TREE_EXPAND {open}"));
33    hs.on_move(|p| println!("HSPLIT {p}"));
34    vs.on_move(|p| println!("VSPLIT {p}"));
35    w.on_move(|x, y| println!("MOVED {x} {y}"));
36    w.on_resize(|w, h| println!("RESIZED {w} {h}"));
37    w.on_close(|| {
38        App::quit();
39        true
40    });
41    w.show();
42    let _t = Timer::once(600, move || {
43        println!("POS {:?}", w.position());
44        for (n, b) in [
45            ("hs", hs.bounds()),
46            ("vs", vs.bounds()),
47            ("table", table.bounds()),
48            ("tree", tree.bounds()),
49            ("area", area.bounds()),
50        ] {
51            println!("BOUNDS {n} {} {} {} {}", b.x, b.y, b.w, b.h);
52        }
53        println!("HPOS {} VPOS {}", hs.position(), vs.position());
54        println!(
55            "MONO {} {} WRAP {}",
56            mono.monospace(),
57            area.monospace(),
58            area.wrap()
59        );
60        println!("READY");
61    });
62    app.run();
63    println!("BYE");
64}