Extract an application window and encapsulate the entire UI
This commit is contained in:
parent
e2d3875587
commit
5e2b7fbc99
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<SunMoon>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Core {
|
||||
tx: Arc<RwLock<Option<Sender<Message>>>>,
|
||||
|
@ -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 || {});
|
||||
|
|
|
@ -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<Option<YearlyEvents>> {
|
|||
pub struct Solstices(HashMap<i32, YearlyEvents>);
|
||||
|
||||
impl Solstices {
|
||||
pub fn akiru(&self, year: i32) -> Option<YearlyEvents> {
|
||||
pub fn acquire(&self, year: i32) -> Option<YearlyEvents> {
|
||||
self.0.get(&year).map(|c| c.clone())
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
use crate::soluna_client::SunMoon;
|
||||
use ifc::IFC;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct State {
|
||||
pub date: IFC,
|
||||
pub transit: Option<SunMoon>,
|
||||
}
|
Loading…
Reference in New Issue