From 1f2c7b80020e3d935134f8e111e889ce44f4701f Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Thu, 10 Aug 2023 11:52:44 -0400 Subject: [PATCH] Add icons to the rise and set times --- dashboard/src/components/label.rs | 58 ++++++++++++++++++++++++ dashboard/src/components/mod.rs | 3 ++ dashboard/src/components/transit_card.rs | 21 ++++----- 3 files changed, 71 insertions(+), 11 deletions(-) create mode 100644 dashboard/src/components/label.rs diff --git a/dashboard/src/components/label.rs b/dashboard/src/components/label.rs new file mode 100644 index 0000000..b793ccc --- /dev/null +++ b/dashboard/src/components/label.rs @@ -0,0 +1,58 @@ +use crate::soluna_client::SunMoon; +use glib::Object; +use gtk::{prelude::*, subclass::prelude::*, IconLookupFlags}; + +#[derive(Default)] +pub struct LabelPrivate { + label: gtk::Label, + icon: gtk::Image, +} + +#[glib::object_subclass] +impl ObjectSubclass for LabelPrivate { + const NAME: &'static str = "Label"; + type Type = Label; + type ParentType = gtk::Box; +} + +impl ObjectImpl for LabelPrivate {} +impl WidgetImpl for LabelPrivate {} +impl BoxImpl for LabelPrivate {} + +glib::wrapper! { + pub struct Label(ObjectSubclass) @extends gtk::Box, gtk::Widget, + @implements gtk::Orientable; +} + +impl Label { + pub fn new(text: Option<&str>, icon: Option) -> Self { + let s: Self = Object::builder().build(); + s.set_orientation(gtk::Orientation::Horizontal); + s.set_spacing(8); + s.set_margin_bottom(8); + s.set_margin_top(8); + s.set_margin_start(8); + s.set_margin_end(8); + + s.append(&s.imp().icon); + s.append(&s.imp().label); + + if let Some(text) = text { + s.set_text(text); + } + + if let Some(icon) = icon { + s.set_icon(icon); + } + + s + } + + pub fn set_text(&self, text: &str) { + self.imp().label.set_text(text); + } + + pub fn set_icon(&self, icon: gio::ThemedIcon) { + self.imp().icon.set_from_gicon(&icon); + } +} diff --git a/dashboard/src/components/mod.rs b/dashboard/src/components/mod.rs index 2abc253..02a5aa4 100644 --- a/dashboard/src/components/mod.rs +++ b/dashboard/src/components/mod.rs @@ -1,6 +1,9 @@ mod date; pub use date::Date; +mod label; +pub use label::Label; + mod transit_card; pub use transit_card::TransitCard; diff --git a/dashboard/src/components/transit_card.rs b/dashboard/src/components/transit_card.rs index 565fd4c..27334e7 100644 --- a/dashboard/src/components/transit_card.rs +++ b/dashboard/src/components/transit_card.rs @@ -1,22 +1,21 @@ -use crate::soluna_client::SunMoon; +use crate::{components::Label, soluna_client::SunMoon}; use glib::Object; -use gtk::{prelude::*, subclass::prelude::*}; -use std::{cell::RefCell, rc::Rc}; +use gtk::{prelude::*, subclass::prelude::*, IconLookupFlags}; pub struct TransitCardPrivate { - sunrise: gtk::Label, - sunset: gtk::Label, - moonrise: gtk::Label, - moonset: gtk::Label, + sunrise: Label, + sunset: Label, + moonrise: Label, + moonset: Label, } impl Default for TransitCardPrivate { fn default() -> Self { Self { - sunrise: gtk::Label::new(None), - sunset: gtk::Label::new(None), - moonrise: gtk::Label::new(None), - moonset: gtk::Label::new(None), + sunrise: Label::new(None, Some(gio::ThemedIcon::new("daytime-sunrise-symbolic"))), + sunset: Label::new(None, Some(gio::ThemedIcon::new("daytime-sunset-symbolic"))), + moonrise: Label::new(None, Some(gio::ThemedIcon::new("moon-outline-symbolic"))), + moonset: Label::new(None, Some(gio::ThemedIcon::new("moon-outline-symbolic"))), } } }