Skip to navigation
Pgk-config and rust
01.03.25
pkg-config helps you find the needed libs to build ## Requirements ``` sudo apt install libgtk-4-dev build-essential ``` ## Project Setup ``` cargo new my-gtk-app cd my-gtk-app pkg-config --modversion gtk4 cargo add gtk4 --rename gtk --features v4_8 ``` ## Hello World Code ``` use gtk::prelude::*; use gtk::{glib, Application, ApplicationWindow, Button}; const APP_ID: &str = "org.gtk_rs.HelloWorld2"; fn main() -> glib::ExitCode { // Create a new application let app = Application::builder().application_id(APP_ID).build(); // Connect to "activate" signal of `app` app.connect_activate(build_ui); // Run the application app.run() } 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!"); }); // Create a window let window = ApplicationWindow::builder() .application(app) .title("My GTK App") .child(&button) .build(); // Present window window.present(); } ```
https://gtk-rs.org/gtk4-rs/git/book/hello_world.html
Reply
Anonymous
Information Epoch 1741793308
Data dominates.
Home
Notebook
Contact us