This repository was archived by the owner on Mar 4, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathmain.rs
56 lines (45 loc) · 1.58 KB
/
main.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
use gtk::glib;
use gtk::prelude::*;
use gtk::Orientation::Vertical;
use gtk::{ApplicationWindow, Button, Label, PackType};
fn build_ui(application: >k::Application) {
let vbox = gtk::Box::new(Vertical, 0);
let plus_button = Button::with_label("+");
vbox.add(&plus_button);
// Set some child properties.
// These calls need to be added after the Widget is added to the Box.
vbox.set_child_expand(&plus_button, true);
vbox.set_child_fill(&plus_button, true);
vbox.set_child_padding(&plus_button, 50);
vbox.set_child_pack_type(&plus_button, PackType::End);
let counter_label = Label::new(Some("0"));
vbox.add(&counter_label);
let minus_button = Button::with_label("-");
vbox.add(&minus_button);
minus_button.connect_clicked(glib::clone!(@weak counter_label => move |_| {
let nb = counter_label.text()
.parse()
.unwrap_or(0);
if nb > 0 {
counter_label.set_text(&format!("{}", nb - 1));
}
}));
plus_button.connect_clicked(glib::clone!(@weak counter_label => move |_| {
let nb = counter_label.text()
.parse()
.unwrap_or(0);
counter_label.set_text(&format!("{}", nb + 1));
}));
let window = ApplicationWindow::new(application);
window.set_default_size(200, 200);
window.add(&vbox);
window.show_all();
}
fn main() {
let application = gtk::Application::new(
Some("com.github.gtk-rs.examples.child_properties"),
Default::default(),
);
application.connect_activate(build_ui);
application.run();
}