Add icons to the rise and set times

This commit is contained in:
Savanni D'Gerinel 2023-08-10 11:52:44 -04:00
parent 8e36091a19
commit 1f2c7b8002
3 changed files with 71 additions and 11 deletions

View File

@ -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<LabelPrivate>) @extends gtk::Box, gtk::Widget,
@implements gtk::Orientable;
}
impl Label {
pub fn new(text: Option<&str>, icon: Option<gio::ThemedIcon>) -> 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);
}
}

View File

@ -1,6 +1,9 @@
mod date; mod date;
pub use date::Date; pub use date::Date;
mod label;
pub use label::Label;
mod transit_card; mod transit_card;
pub use transit_card::TransitCard; pub use transit_card::TransitCard;

View File

@ -1,22 +1,21 @@
use crate::soluna_client::SunMoon; use crate::{components::Label, soluna_client::SunMoon};
use glib::Object; use glib::Object;
use gtk::{prelude::*, subclass::prelude::*}; use gtk::{prelude::*, subclass::prelude::*, IconLookupFlags};
use std::{cell::RefCell, rc::Rc};
pub struct TransitCardPrivate { pub struct TransitCardPrivate {
sunrise: gtk::Label, sunrise: Label,
sunset: gtk::Label, sunset: Label,
moonrise: gtk::Label, moonrise: Label,
moonset: gtk::Label, moonset: Label,
} }
impl Default for TransitCardPrivate { impl Default for TransitCardPrivate {
fn default() -> Self { fn default() -> Self {
Self { Self {
sunrise: gtk::Label::new(None), sunrise: Label::new(None, Some(gio::ThemedIcon::new("daytime-sunrise-symbolic"))),
sunset: gtk::Label::new(None), sunset: Label::new(None, Some(gio::ThemedIcon::new("daytime-sunset-symbolic"))),
moonrise: gtk::Label::new(None), moonrise: Label::new(None, Some(gio::ThemedIcon::new("moon-outline-symbolic"))),
moonset: gtk::Label::new(None), moonset: Label::new(None, Some(gio::ThemedIcon::new("moon-outline-symbolic"))),
} }
} }
} }