feat: added logic to the buttons
This commit is contained in:
@@ -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();
|
||||
|
||||
+20
-5
@@ -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 action_column = {
|
||||
let text_list1 = text_list.clone();
|
||||
let text_list2 = text_list.clone();
|
||||
let input_form = components::input_form::build(move |text| {
|
||||
components::text_list::append_item(&text_list2, &text);
|
||||
});
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user