X-Git-Url: https://piware.de/gitweb/?p=learn-rust.git;a=blobdiff_plain;f=gtk3-hello-world%2Fsrc%2Fmain.rs;fp=gtk3-hello-world%2Fsrc%2Fmain.rs;h=a44bc6274f9249bfaabcd1fb9c179e8e839e31e2;hp=0000000000000000000000000000000000000000;hb=5931f0a88bd65592cb76fcac25896471dd82186d;hpb=99e82684904554a79987f77c68af00cc84b1f197 diff --git a/gtk3-hello-world/src/main.rs b/gtk3-hello-world/src/main.rs new file mode 100644 index 0000000..a44bc62 --- /dev/null +++ b/gtk3-hello-world/src/main.rs @@ -0,0 +1,41 @@ +use gtk::prelude::*; +use gtk::{ + Application, ApplicationWindow, + Button, + Widget, +}; + +fn build_ui(app: &Application) { + let button = Button::builder() + .label("Click me!") + .margin_top(12) + .margin_bottom(12) + .margin_start(12) + .margin_end(12) + .build(); + + button.connect_clicked(move |button| { + button.set_label("Hello world!"); + }); + + let button_w: &Widget = button.upcast_ref::(); + + println!("button visible: {}", button_w.is_visible()); + + let window = ApplicationWindow::builder() + .application(app) + .title("Hello GTK") + .child(&button) + .build(); + + window.show_all(); +} + +fn main() { + let app = Application::builder() + .application_id("ork.gtk-rs.example") + .build(); + + app.connect_activate(build_ui); + app.run(); +}