two buttons

This commit is contained in:
Daniel Langbein 2025-02-11 19:16:15 +01:00
parent 097fefb947
commit 0b46e51694
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002

View File

@ -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: &gtk::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)