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
49 lines (40 loc) · 1.39 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
use gtk::glib;
use gtk::prelude::*;
use gtk::{ApplicationWindow, Builder, MessageDialog};
fn build_ui(application: >k::Application) {
let glade_src = include_str!("builder_signal.ui");
let builder = Builder::from_string(glade_src);
let window: ApplicationWindow = builder.object("window1").expect("Couldn't get window1");
window.set_application(Some(application));
let dialog: MessageDialog = builder
.object("messagedialog1")
.expect("Couldn't get messagedialog1");
dialog.connect_delete_event(|dialog, _| {
dialog.hide();
glib::Propagation::Stop
});
builder.connect_signals(move |_, handler_name| {
// This is the one-time callback to register signals.
// Here we map each handler name to its handler.
if handler_name == "button1_clicked" {
// Return the signal handler.
Box::new(
glib::clone!(@weak dialog => @default-return None, move |_| {
dialog.show_all();
None
}),
)
} else {
panic!("Unknown handler name {handler_name}")
}
});
window.show_all();
}
fn main() {
let application = gtk::Application::new(
Some("com.github.gtk-rs.examples.builder_signal"),
Default::default(),
);
application.connect_activate(build_ui);
application.run();
}