@@ -56,34 +56,30 @@ extern crate gtk;
56
56
use gtk :: prelude :: * ;
57
57
~~~
58
58
59
- Create a window , etc.
59
+ Create an application , etc.
60
60
61
61
~~~ rust
62
- use gtk :: {Button , Window , WindowType };
62
+ use gtk :: {Application , ApplicationWindow , Button };
63
63
64
64
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 );
81
72
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 ();
84
80
});
85
81
86
- gtk :: main ( );
82
+ application . run ( & [] );
87
83
}
88
84
~~~
89
85
@@ -94,7 +90,7 @@ Include `gtk` in your `Cargo.toml` not as crate but from git:
94
90
~~~ toml
95
91
[dependencies .gtk ]
96
92
git = " https://github.com/gtk-rs/gtk"
97
- features = [" v3_10 " ]
93
+ features = [" v3_16 " ]
98
94
~~~
99
95
100
96
## Projects using gtk-rs
0 commit comments