basic/
basic.rs

1extern crate libui;
2
3use libui::controls::{Button, Group, Label, VerticalBox};
4use libui::prelude::*;
5
6fn main() {
7    // Initialize the UI library
8    let ui = UI::init().expect("Couldn't initialize UI library");
9
10    // Create a window into which controls can be placed
11    let mut win = Window::new(&ui.clone(), "Test App", 200, 200, WindowType::NoMenubar);
12
13    // Create a vertical layout to hold the controls
14    let mut vbox = VerticalBox::new();
15    vbox.set_padded(true);
16
17    let mut group_vbox = VerticalBox::new();
18    let mut group = Group::new("Group");
19
20    // Create two buttons to place in the window
21    let mut button = Button::new("Button");
22    button.on_clicked({
23        move |btn| {
24            btn.set_text("Clicked!");
25        }
26    });
27
28    let mut quit_button = Button::new("Quit");
29    quit_button.on_clicked({
30        let ui = ui.clone();
31        move |_| {
32            ui.quit();
33        }
34    });
35    // Create a new label. Note that labels don't auto-wrap!
36    let mut label_text = String::new();
37    label_text.push_str("There is a ton of text in this label.\n");
38    label_text.push_str("Pretty much every unicode character is supported.\n");
39    label_text.push_str("πŸŽ‰ η”¨ζˆ·η•Œι’ μ‚¬μš©μž μΈν„°νŽ˜μ΄μŠ€");
40    let label = Label::new(&label_text);
41
42    vbox.append(label, LayoutStrategy::Stretchy);
43    group_vbox.append(button, LayoutStrategy::Compact);
44    group_vbox.append(quit_button, LayoutStrategy::Compact);
45    group.set_child(group_vbox);
46    vbox.append(group, LayoutStrategy::Compact);
47
48    // Actually put the button in the window
49    win.set_child(vbox);
50    // Show the window
51    win.show();
52    // Run the application
53    ui.main();
54}