PV281: Programování v Rustu1/49 Obsah 1. Přístupy k vývoji desktopových aplikací 2. GTK 4 3. Tauri 2/49 Přístupy k vývoji desktopových aplikací 3/49 Koncept okna 4/49 Header bar 5/49 Sidebar 6/49 Taby 7/49 Dialog 8/49 GTK 4 9/49 GTK 4 GTK je multiplatformní knihovna pro tvorbu UI. Je psaná v C, takže se vyžívá bindingů pro Rust. 10/49 Závislosti gtk = { version = "0.5.2", package = "gtk4" } # Notice that we are renaming the package from `gtk4` to just `gtk`. Kromě toho je potřeba nainstalovat knihovny pro vývoj dle dokumentace, např. pro UN*X: Distribution Binary package Development package Additional packages Arch gtk4 - Debian/Ubuntu libgtk-4-1 libgtk-4-dev gtk-4-examples Fedora gtk4 gtk4-devel - 11/49 Vytvoření aplikace use gtk::prelude::*; use gtk::Application; fn main() { let app = Application::builder() // Create a new application .application_id("org.gtk-rs.example") .build(); app.run(); // Run the application } 12/49 Vytvoření okna use gtk::{Application, ApplicationWindow, prelude::*}; fn main() { let app = Application::builder() // Create a new application .application_id("org.gtk-rs.example") .build(); app.connect_activate(build_ui); // Connect to "activate" signal of `app` app.run(); // Run the application } fn build_ui(app: &Application) { let window = ApplicationWindow::builder() // Create a window and set the title .application(app) .title("My GTK App") .build(); window.present(); // Present window to the user } 13/49 Přidání tlačítka fn build_ui(app: &Application) { let window = ApplicationWindow::builder() // Create a window and set the title .application(app) .title("My GTK App") .build(); let button = Button::builder() // Create a button with label and margins .label("Press me!") .margin_top(12) .margin_bottom(12) .margin_start(12) .margin_end(12) .build(); button.connect_clicked(move |button| { // Connect to "clicked" signal of `button` button.set_label("Hello World!"); // Set the label to "Hello World!" after the button has been clicked on }); window.set_child(Some(&button)); // Add button window.present(); // Present window to the user } 14/49 Události (signály) // ... button.connect_local("clicked", false, move |args| { // Connect callback let button = args[0] // Get the button from the arguments .get::