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
53 lines (42 loc) · 1.37 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
use std::cell::RefCell;
use std::rc::Rc;
use gtk::glib;
use gtk::{prelude::*, Application, ApplicationWindow, Button};
#[derive(Default)]
struct State {
started: bool,
count: i32,
}
impl State {
fn new() -> Self {
Self {
started: false,
count: 0,
}
}
}
fn main() {
let application =
Application::new(Some("com.github.gtk-rs.examples.basic"), Default::default());
let state = Rc::new(RefCell::new(State::new()));
{
let state2 = Rc::new(RefCell::new(State::new()));
application.connect_activate(glib::clone!(@weak state, @strong state2 => move |app| {
state.borrow_mut().started = true;
let window = ApplicationWindow::new(app);
window.set_title("First GTK+ Program");
window.set_default_size(350, 70);
let button = Button::with_label("Click me!");
button.connect_clicked(glib::clone!(@weak state, @weak state2 => move |_| {
let mut state = state.borrow_mut();
let mut state2 = state2.borrow_mut();
println!("Clicked (started: {}): {} - {}!", state.started, state.count, state2.count);
state.count += 1;
state2.count += 1;
}));
window.add(&button);
window.show_all();
}));
}
application.run();
}