From 8671a962b491d38093b43335f4a003c53bcf4042 Mon Sep 17 00:00:00 2001 From: Manuel Riquelme Date: Wed, 5 Jul 2023 11:28:28 +0200 Subject: [PATCH] gtk hello3 button --- gtk4/hello3/Cargo.toml | 9 +++++++++ gtk4/hello3/src/main.rs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 gtk4/hello3/Cargo.toml create mode 100644 gtk4/hello3/src/main.rs diff --git a/gtk4/hello3/Cargo.toml b/gtk4/hello3/Cargo.toml new file mode 100644 index 0000000..76431f4 --- /dev/null +++ b/gtk4/hello3/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "hello2" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +gtk = { version = "0.6.6", package = "gtk4", features = ["v4_8"] } diff --git a/gtk4/hello3/src/main.rs b/gtk4/hello3/src/main.rs new file mode 100644 index 0000000..ab6f891 --- /dev/null +++ b/gtk4/hello3/src/main.rs @@ -0,0 +1,36 @@ +use gtk::prelude::*; +use gtk::{glib, Application, ApplicationWindow, Button}; + +const APP_ID: &str = "com.clonbg.Helloword2"; + +fn build_ui(app: &Application) { + // Create a button with label and margins + let button = Button::builder() + .label("Press me!") + .margin_top(12) + .margin_bottom(12) + .margin_start(12) + .margin_end(12) + .build(); + + // Connect to "clicked" signal of `button` + button.connect_clicked(|button| { + // Set the label to "Hello World!" after the button has been clicked on + button.set_label("Hello World!"); + }); + + let window = ApplicationWindow::builder() + .application(app) + .title("Mi aplicacióng gtk") + .child(&button) + .build(); + + // presenta la ventana, será la última orden + window.present(); +} + +fn main() -> glib::ExitCode { + let app = Application::builder().application_id(APP_ID).build(); + app.connect_activate(build_ui); + app.run() +}