use crate::{ components::{Date, TransitClock}, types::State, }; use gtk::prelude::*; #[derive(Clone)] pub struct ApplicationWindow { pub window: gtk::ApplicationWindow, pub date_label: Date, pub next_event: gtk::Label, pub transit_clock: TransitClock, } impl ApplicationWindow { pub fn new(app: >k::Application) -> Self { let window = gtk::ApplicationWindow::new(app); let layout = gtk::Box::builder() .orientation(gtk::Orientation::Vertical) .hexpand(true) .vexpand(true) .build(); let date_label = Date::new(); layout.append(&date_label); let next_event = gtk::Label::builder() .margin_bottom(8) .margin_top(8) .margin_start(8) .margin_end(8) .build(); next_event.add_css_class("card"); next_event.add_css_class("activatable"); layout.append(&next_event); let transit_clock = TransitClock::new(); layout.append(&transit_clock); window.set_child(Some(&layout)); Self { window, date_label, next_event, transit_clock, } } pub fn update_state(&self, state: State) { self.date_label.update_date(state.date); self.next_event.set_text(&format!("{:?}", state.next_event)); if let Some(transit) = state.transit { self.transit_clock.update_transit(transit); } } }