-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathbasic.rs
72 lines (63 loc) · 2.16 KB
/
basic.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
extern crate iui;
use iui::controls::{Button, ColorButton, Group, Label, Rgba, VerticalBox};
use iui::prelude::*;
fn main() {
// Initialize the UI library
let ui = UI::init().expect("Couldn't initialize UI library");
// Create a window into which controls can be placed
let mut win = Window::new(&ui, "Test App", 200, 200, WindowType::NoMenubar);
// Create a vertical layout to hold the controls
let mut vbox = VerticalBox::new(&ui);
vbox.set_padded(&ui, true);
let mut group_vbox = VerticalBox::new(&ui);
let mut group = Group::new(&ui, "Group");
// Create two buttons to place in the window
let mut button = Button::new(&ui, "Button");
button.on_clicked(&ui, {
let ui = ui.clone();
move |btn| {
btn.set_text(&ui, "Clicked!");
}
});
let mut quit_button = Button::new(&ui, "Quit");
quit_button.on_clicked(&ui, {
let ui = ui.clone();
move |_| {
ui.quit();
}
});
let mut color_button = ColorButton::new(&ui);
color_button.set_color(
&ui,
Rgba {
r: 1.0,
g: 0.0,
b: 0.0,
a: 1.0,
},
);
color_button.on_changed(&ui, {
let ui = ui.clone();
move |btn| {
dbg!(btn.color(&ui));
}
});
// Create a new label. Note that labels don't auto-wrap!
let mut label_text = String::new();
label_text.push_str("There is a ton of text in this label.\n");
label_text.push_str("Pretty much every unicode character is supported.\n");
label_text.push_str("🎉 用户界面 사용자 인터페이스");
let label = Label::new(&ui, &label_text);
vbox.append(&ui, label, LayoutStrategy::Stretchy);
group_vbox.append(&ui, button, LayoutStrategy::Compact);
group_vbox.append(&ui, quit_button, LayoutStrategy::Compact);
group_vbox.append(&ui, color_button, LayoutStrategy::Compact);
group.set_child(&ui, group_vbox);
vbox.append(&ui, group, LayoutStrategy::Compact);
// Actually put the button in the window
win.set_child(&ui, vbox);
// Show the window
win.show(&ui);
// Run the application
ui.main();
}