Skip to content

Commit 59d5e3a

Browse files
Merge pull request #110 from ketsuban/update-example
Update the front-page example
2 parents 1d54829 + 6adb59f commit 59d5e3a

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

index.md

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,34 +56,30 @@ extern crate gtk;
5656
use gtk::prelude::*;
5757
~~~
5858

59-
Create a window, etc.
59+
Create an application, etc.
6060

6161
~~~rust
62-
use gtk::{Button, Window, WindowType};
62+
use gtk::{Application, ApplicationWindow, Button};
6363

6464
fn main() {
65-
if gtk::init().is_err() {
66-
println!("Failed to initialize GTK.");
67-
return;
68-
}
69-
70-
let window = Window::new(WindowType::Toplevel);
71-
window.set_title("First GTK+ Program");
72-
window.set_default_size(350, 70);
73-
let button = Button::new_with_label("Click me!");
74-
window.add(&button);
75-
window.show_all();
76-
77-
window.connect_delete_event(|_, _| {
78-
gtk::main_quit();
79-
Inhibit(false)
80-
});
65+
let application = Application::new("com.github.gtk-rs.examples.basic", Default::default()))
66+
.expect("failed to initialize GTK application");
67+
68+
application.connect_activate(|app| {
69+
let window = ApplicationWindow::new();
70+
window.set_title("First GTK+ Program");
71+
window.set_default_size(350, 70);
8172

82-
button.connect_clicked(|_| {
83-
println!("Clicked!");
73+
let button = Button::new_with_label("Click me!");
74+
button.connect_clicked(|_| {
75+
println!("Clicked!");
76+
});
77+
window.add(&button);
78+
79+
window.show_all();
8480
});
8581

86-
gtk::main();
82+
application.run(&[]);
8783
}
8884
~~~
8985

@@ -94,7 +90,7 @@ Include `gtk` in your `Cargo.toml` not as crate but from git:
9490
~~~toml
9591
[dependencies.gtk]
9692
git = "https://github.com/gtk-rs/gtk"
97-
features = ["v3_10"]
93+
features = ["v3_16"]
9894
~~~
9995

10096
## Projects using gtk-rs

0 commit comments

Comments
 (0)