From 0b46e51694e051c765bff7e611f8a4e33f6437be Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Tue, 11 Feb 2025 19:16:15 +0100 Subject: [PATCH] two buttons --- src/main.rs | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index e66a1fc..c7c50c9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,38 +4,54 @@ use chrono::Local; use gtk4 as gtk; use gtk::prelude::*; -use gtk::{glib, Application, ApplicationWindow, Button}; +use gtk::{glib}; fn main() -> glib::ExitCode { - let application = Application::builder() + let application = gtk::Application::builder() .application_id("de.privacy1st.pdt") .build(); - application.connect_activate(build_ui); - application.run() } fn build_ui(app: >k::Application) { - let window = ApplicationWindow::builder() + let window = gtk::ApplicationWindow::builder() .application(app) .title("PleaseDisturbTimer") .default_width(350) .default_height(70) .build(); - let button_start = Button::with_label("Start"); + let container = gtk::Box::builder() + .orientation(gtk::Orientation::Vertical) + .margin_top(24) + .margin_bottom(24) + .margin_start(24) + .margin_end(24) + .halign(gtk::Align::Center) + .valign(gtk::Align::Center) + .spacing(24) + .build(); + + let button_start = gtk::Button::with_label("Start"); button_start.connect_clicked(|_| { eprintln!("Timer started."); }); - window.set_child(Some(&button_start)); + container.append(&button_start); + + let button_stop = gtk::Button::with_label("Stop"); + button_stop.connect_clicked(|_| { + eprintln!("Timer stopped."); + }); + container.append(&button_stop); let time = current_time(); let label = gtk::Label::default(); label.set_text(&time); // label.set_halign(gtk::Align::Center); - window.set_child(Some(&label)); + container.append(&label); + window.set_child(Some(&container)); window.present(); // we are using a closure to capture the label (else we could also use a normal function)