From 6f31ac1e8d8c10838b84d62ef5fafa654152bd60 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Mon, 7 Aug 2023 23:53:42 -0400 Subject: [PATCH] Add clock ticks --- dashboard/src/main.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/dashboard/src/main.rs b/dashboard/src/main.rs index 7447564..e945f3c 100644 --- a/dashboard/src/main.rs +++ b/dashboard/src/main.rs @@ -204,26 +204,26 @@ impl Date { } #[derive(Default)] -pub struct DayPrivate { +pub struct ClockPrivate { info: Rc>>, } #[glib::object_subclass] -impl ObjectSubclass for DayPrivate { - const NAME: &'static str = "Day"; - type Type = Day; +impl ObjectSubclass for ClockPrivate { + const NAME: &'static str = "Clock"; + type Type = Clock; type ParentType = gtk::DrawingArea; } -impl ObjectImpl for DayPrivate {} -impl WidgetImpl for DayPrivate {} -impl DrawingAreaImpl for DayPrivate {} +impl ObjectImpl for ClockPrivate {} +impl WidgetImpl for ClockPrivate {} +impl DrawingAreaImpl for ClockPrivate {} glib::wrapper! { - pub struct Day(ObjectSubclass) @extends gtk::DrawingArea, gtk::Widget; + pub struct Clock(ObjectSubclass) @extends gtk::DrawingArea, gtk::Widget; } -impl Day { +impl Clock { pub fn new(sun_moon_info: SunMoon) -> Self { let s: Self = Object::builder().build(); s.set_width_request(500); @@ -244,6 +244,15 @@ impl Day { context.arc(width as f64 / 2., height as f64 / 2., 200., 0., PI * 2.); let _ = context.stroke(); + (0..24).for_each(|hour| { + context.translate(width as f64 / 2., height as f64 / 2.); + context.rotate(PI / 12. * hour as f64); + context.move_to(210., 0.); + context.line_to(230., 0.); + context.identity_matrix(); + let _ = context.stroke(); + }); + if let Some(info) = info.deref() { context.move_to(width as f64 / 2., height as f64 / 2.); let full_day = Duration::days(1).num_seconds() as f64; @@ -287,7 +296,7 @@ pub fn main() { .orientation(Orientation::Vertical) .build(); let date = Date::new(); - let day = Day::new(SunMoon { + let day = Clock::new(SunMoon { sunrise: NaiveTime::from_hms_opt(6, 0, 0).unwrap(), sunset: NaiveTime::from_hms_opt(0, 0, 0).unwrap(), moonrise: NaiveTime::from_hms_opt(15, 0, 0),