97 lines
2.6 KiB
Rust
97 lines
2.6 KiB
Rust
use crate::{
|
|
components::Date,
|
|
solstices::{self, YearlyEvents},
|
|
};
|
|
use glib::Object;
|
|
use gtk::{prelude::*, subclass::prelude::*};
|
|
use ifc::IFC;
|
|
|
|
/*
|
|
#[derive(PartialEq)]
|
|
pub enum UpcomingEvent {
|
|
SpringEquinox,
|
|
SummerSolstice,
|
|
AutumnEquinox,
|
|
WinterSolstice,
|
|
}
|
|
*/
|
|
|
|
#[derive(Default)]
|
|
pub struct EventsPrivate {
|
|
spring_equinox: Date,
|
|
summer_solstice: Date,
|
|
autumn_equinox: Date,
|
|
winter_solstice: Date,
|
|
// next: UpcomingEvent,
|
|
}
|
|
|
|
#[glib::object_subclass]
|
|
impl ObjectSubclass for EventsPrivate {
|
|
const NAME: &'static str = "Events";
|
|
type Type = Events;
|
|
type ParentType = gtk::Box;
|
|
}
|
|
|
|
impl ObjectImpl for EventsPrivate {}
|
|
impl WidgetImpl for EventsPrivate {}
|
|
impl BoxImpl for EventsPrivate {}
|
|
|
|
glib::wrapper! {
|
|
pub struct Events(ObjectSubclass<EventsPrivate>) @extends gtk::Widget, gtk::Box, @implements gtk::Orientable;
|
|
}
|
|
|
|
impl Default for Events {
|
|
fn default() -> Self {
|
|
let s: Self = Object::builder().build();
|
|
s.set_orientation(gtk::Orientation::Horizontal);
|
|
s.set_spacing(8);
|
|
|
|
s.append(&s.imp().spring_equinox);
|
|
s.append(&s.imp().summer_solstice);
|
|
s.append(&s.imp().autumn_equinox);
|
|
s.append(&s.imp().winter_solstice);
|
|
|
|
s
|
|
}
|
|
}
|
|
|
|
impl Events {
|
|
pub fn set_events(&self, events: YearlyEvents, next_event: solstices::Event) {
|
|
self.imp()
|
|
.spring_equinox
|
|
.update_date(IFC::from(events.spring_equinox.date_naive()));
|
|
|
|
self.imp()
|
|
.summer_solstice
|
|
.update_date(IFC::from(events.summer_solstice.date_naive()));
|
|
|
|
self.imp()
|
|
.autumn_equinox
|
|
.update_date(IFC::from(events.autumn_equinox.date_naive()));
|
|
|
|
self.imp()
|
|
.winter_solstice
|
|
.update_date(IFC::from(events.winter_solstice.date_naive()));
|
|
|
|
self.imp().spring_equinox.remove_css_class("highlight");
|
|
self.imp().summer_solstice.remove_css_class("highlight");
|
|
self.imp().autumn_equinox.remove_css_class("highlight");
|
|
self.imp().winter_solstice.remove_css_class("highlight");
|
|
|
|
match next_event {
|
|
solstices::Event::SpringEquinox(_) => {
|
|
self.imp().spring_equinox.add_css_class("highlight")
|
|
}
|
|
solstices::Event::SummerSolstice(_) => {
|
|
self.imp().summer_solstice.add_css_class("highlight")
|
|
}
|
|
solstices::Event::AutumnEquinox(_) => {
|
|
self.imp().autumn_equinox.add_css_class("highlight")
|
|
}
|
|
solstices::Event::WinterSolstice(_) => {
|
|
self.imp().winter_solstice.add_css_class("highlight")
|
|
}
|
|
}
|
|
}
|
|
}
|