From 9dfdeb92d925bc25877a3eb829a2db8970f6bf8c Mon Sep 17 00:00:00 2001 From: Matthias Schild Date: Sun, 23 Aug 2026 22:45:52 +0200 Subject: [PATCH] feat: added logic to the buttons --- src/components/action_column.rs | 14 +++++++++++++- src/main.rs | 27 +++++++++++++++++++++------ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/components/action_column.rs b/src/components/action_column.rs index 80c1c06..b2ba3fd 100644 --- a/src/components/action_column.rs +++ b/src/components/action_column.rs @@ -3,7 +3,11 @@ use gtk4::{ prelude::ButtonExt, }; -pub fn build(app: &Application) -> Box { +pub fn build( + app: &Application, + on_start: impl Fn() + 'static, + on_stop: impl Fn() + 'static, +) -> Box { let button_start = Button::builder() .label("Start machine") .css_classes(vec!["btn"]) @@ -17,6 +21,14 @@ pub fn build(app: &Application) -> Box { .css_classes(vec!["btn"]) .build(); + button_start.connect_clicked(move |_| { + on_start(); + }); + + button_stop.connect_clicked(move |_| { + on_stop(); + }); + let app = app.clone(); button_quit.connect_clicked(move |_| { app.quit(); diff --git a/src/main.rs b/src/main.rs index 01f9464..fdf0e81 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,16 +9,31 @@ use gtk4::{ }; const APP_ID: &str = "de.matthiasschild.gtk4-learning"; -const FULLSCREEN: bool = false; +const FULLSCREEN: bool = true; fn build_window(app: &Application) { css::load(); - let action_column = components::action_column::build(app); let text_list = components::text_list::build(); - let text_list2 = text_list.clone(); - let input_form = components::input_form::build(move |text| { - components::text_list::append_item(&text_list2, &text); - }); + + let action_column = { + let text_list1 = text_list.clone(); + let text_list2 = text_list.clone(); + components::action_column::build( + app, + move || { + components::text_list::append_item(&text_list1, "Machine started"); + }, + move || { + components::text_list::append_item(&text_list2, "Machine stopped"); + }, + ) + }; + let input_form = { + let text_list = text_list.clone(); + components::input_form::build(move |text| { + components::text_list::append_item(&text_list, &text); + }) + }; let text_list_scroll = gtk4::ScrolledWindow::builder() .vexpand(true) .hexpand(true)