feat: added logic to the buttons

This commit is contained in:
2026-08-23 22:45:52 +02:00
parent ae7a1cd3b0
commit 9dfdeb92d9
2 changed files with 34 additions and 7 deletions
+13 -1
View File
@@ -3,7 +3,11 @@ use gtk4::{
prelude::ButtonExt, 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() let button_start = Button::builder()
.label("Start machine") .label("Start machine")
.css_classes(vec!["btn"]) .css_classes(vec!["btn"])
@@ -17,6 +21,14 @@ pub fn build(app: &Application) -> Box {
.css_classes(vec!["btn"]) .css_classes(vec!["btn"])
.build(); .build();
button_start.connect_clicked(move |_| {
on_start();
});
button_stop.connect_clicked(move |_| {
on_stop();
});
let app = app.clone(); let app = app.clone();
button_quit.connect_clicked(move |_| { button_quit.connect_clicked(move |_| {
app.quit(); app.quit();
+21 -6
View File
@@ -9,16 +9,31 @@ use gtk4::{
}; };
const APP_ID: &str = "de.matthiasschild.gtk4-learning"; const APP_ID: &str = "de.matthiasschild.gtk4-learning";
const FULLSCREEN: bool = false; const FULLSCREEN: bool = true;
fn build_window(app: &Application) { fn build_window(app: &Application) {
css::load(); css::load();
let action_column = components::action_column::build(app);
let text_list = components::text_list::build(); let text_list = components::text_list::build();
let text_list2 = text_list.clone();
let input_form = components::input_form::build(move |text| { let action_column = {
components::text_list::append_item(&text_list2, &text); 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() let text_list_scroll = gtk4::ScrolledWindow::builder()
.vexpand(true) .vexpand(true)
.hexpand(true) .hexpand(true)