Show a card for sunrise, sunset, moonrise, and moonset #57

Merged
savanni merged 3 commits from rise-set into main 2023-08-10 15:54:38 +00:00
3 changed files with 71 additions and 11 deletions
Showing only changes of commit 1f2c7b8002 - Show all commits

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;
pub use date::Date;
mod label;
pub use label::Label;
mod transit_card;
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 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"))),
}
}
}