diff --git a/dashboard/src/app_window.rs b/dashboard/src/app_window.rs new file mode 100644 index 0000000..dbe9979 --- /dev/null +++ b/dashboard/src/app_window.rs @@ -0,0 +1,44 @@ +use crate::{ + components::{Date, TransitClock}, + types::State, +}; +use gtk::prelude::*; + +#[derive(Clone)] +pub struct ApplicationWindow { + pub window: gtk::ApplicationWindow, + pub date_label: Date, + pub transit_clock: TransitClock, +} + +impl ApplicationWindow { + pub fn new(app: >k::Application) -> Self { + let window = gtk::ApplicationWindow::new(app); + let date_label = Date::new(); + let transit_clock = TransitClock::new(); + + let layout = gtk::Box::builder() + .orientation(gtk::Orientation::Vertical) + .hexpand(true) + .vexpand(true) + .build(); + + layout.append(&date_label); + layout.append(&transit_clock); + + window.set_child(Some(&layout)); + + Self { + window, + date_label, + transit_clock, + } + } + + pub fn update_state(&self, state: State) { + self.date_label.update_date(state.date); + if let Some(transit) = state.transit { + self.transit_clock.update_transit(transit); + } + } +} diff --git a/dashboard/src/main.rs b/dashboard/src/main.rs index 3ed36a5..7b5ebd6 100644 --- a/dashboard/src/main.rs +++ b/dashboard/src/main.rs @@ -8,6 +8,9 @@ use std::{ sync::{Arc, RwLock}, }; +mod app_window; +use app_window::ApplicationWindow; + mod components; use components::{Date, TransitClock}; @@ -16,11 +19,13 @@ mod drawing; mod soluna_client; use soluna_client::{SolunaClient, SunMoon}; -/* mod solstices; use solstices::EVENTS; -*/ +mod types; +use types::State; + +/* const EO_TEXT: &'static str = " day = {$day -> *[Sunday] Dimanĉo @@ -53,18 +58,13 @@ summer_solstice = Somera Solstico autumn_equinox = Aŭtuna Ekvinokso winter_solstice = Vintra Solstico "; +*/ #[derive(Clone, Debug)] pub enum Message { Refresh(State), } -#[derive(Clone, Debug)] -pub struct State { - date: IFC, - transit: Option, -} - #[derive(Clone)] pub struct Core { tx: Arc>>>, @@ -118,31 +118,17 @@ pub fn main() { *core.tx.write().unwrap() = Some(gtk_tx); - let window = gtk::ApplicationWindow::new(app); - window.present(); + let window = ApplicationWindow::new(app); + window.window.present(); - let layout = gtk::Box::builder() - .orientation(Orientation::Vertical) - .hexpand(true) - .vexpand(true) - .build(); - let date_label = Date::new(); - layout.append(&date_label); + gtk_rx.attach(None, { + let window = window.clone(); + move |msg| { + let Message::Refresh(state) = msg; + ApplicationWindow::update_state(&window, state); - let transit_clock = TransitClock::new(); - layout.append(&transit_clock); - - window.set_child(Some(&layout)); - - gtk_rx.attach(None, move |msg| { - let Message::Refresh(state) = msg; - println!("new state: {:?}", state); - date_label.update_date(state.date); - if let Some(transit) = state.transit { - transit_clock.update_transit(transit); + Continue(true) } - - Continue(true) }); std::thread::spawn(move || {}); diff --git a/dashboard/src/solstices.rs b/dashboard/src/solstices.rs index 048ece7..210be72 100644 --- a/dashboard/src/solstices.rs +++ b/dashboard/src/solstices.rs @@ -1,7 +1,7 @@ use chrono; use chrono::prelude::*; +use lazy_static::lazy_static; use serde_derive::{Deserialize, Serialize}; -use serde_json; use std::collections::HashMap; // http://astropixels.com/ephemeris/soleq2001.html @@ -133,7 +133,7 @@ fn parse_events() -> Vec> { pub struct Solstices(HashMap); impl Solstices { - pub fn akiru(&self, year: i32) -> Option { + pub fn acquire(&self, year: i32) -> Option { self.0.get(&year).map(|c| c.clone()) } diff --git a/dashboard/src/types.rs b/dashboard/src/types.rs new file mode 100644 index 0000000..d82f9e6 --- /dev/null +++ b/dashboard/src/types.rs @@ -0,0 +1,8 @@ +use crate::soluna_client::SunMoon; +use ifc::IFC; + +#[derive(Clone, Debug)] +pub struct State { + pub date: IFC, + pub transit: Option, +}