Compare commits

...

3 Commits

Author SHA1 Message Date
Savanni D'Gerinel 8e36091a19 styling 2023-08-10 11:09:27 -04:00
Savanni D'Gerinel 3e13cbcdaa Add the transit times to a card 2023-08-10 11:08:12 -04:00
Savanni D'Gerinel 038ccac637 Set up a stylesheet 2023-08-10 11:07:35 -04:00
10 changed files with 127 additions and 6 deletions

1
Cargo.lock generated
View File

@ -339,6 +339,7 @@ dependencies = [
"geo-types", "geo-types",
"gio", "gio",
"glib", "glib",
"glib-build-tools",
"gtk4", "gtk4",
"ifc", "ifc",
"lazy_static", "lazy_static",

View File

@ -26,3 +26,7 @@ serde_json = { version = "1" }
serde = { version = "1" } serde = { version = "1" }
tokio = { version = "1", features = ["full"] } tokio = { version = "1", features = ["full"] }
unic-langid = { version = "0.9" } unic-langid = { version = "0.9" }
[build-dependencies]
glib-build-tools = "0.16"

7
dashboard/build.rs Normal file
View File

@ -0,0 +1,7 @@
fn main() {
glib_build_tools::compile_resources(
"resources",
"resources/gresources.xml",
"com.luminescent-dreams.dashboard.gresource",
);
}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/com/luminescent-dreams/dashboard/">
<file>style.css</file>
</gresource>
</gresources>

View File

@ -0,0 +1,5 @@
@define-color background_color @purple_5;
label {
font-size: 200%;
}

View File

@ -1,15 +1,17 @@
use crate::{ use crate::{
components::{Date, TransitClock}, components::{Date, TransitCard, TransitClock},
types::State, types::State,
}; };
use adw::prelude::AdwApplicationWindowExt; use adw::prelude::AdwApplicationWindowExt;
use gtk::prelude::*; use gio::resources_lookup_data;
use gtk::{prelude::*, STYLE_PROVIDER_PRIORITY_USER};
#[derive(Clone)] #[derive(Clone)]
pub struct ApplicationWindow { pub struct ApplicationWindow {
pub window: adw::ApplicationWindow, pub window: adw::ApplicationWindow,
pub date_label: Date, pub date_label: Date,
pub next_event: gtk::Label, pub next_event: gtk::Label,
pub transit_card: TransitCard,
pub transit_clock: TransitClock, pub transit_clock: TransitClock,
} }
@ -17,6 +19,21 @@ impl ApplicationWindow {
pub fn new(app: &adw::Application) -> Self { pub fn new(app: &adw::Application) -> Self {
let window = adw::ApplicationWindow::new(app); let window = adw::ApplicationWindow::new(app);
let stylesheet = String::from_utf8(
resources_lookup_data(
"/com/luminescent-dreams/dashboard/style.css",
gio::ResourceLookupFlags::NONE,
)
.expect("stylesheet should just be available")
.to_vec(),
)
.expect("to parse stylesheet");
let provider = gtk::CssProvider::new();
provider.load_from_data(&stylesheet);
let context = window.style_context();
context.add_provider(&provider, STYLE_PROVIDER_PRIORITY_USER);
let layout = gtk::Box::builder() let layout = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical) .orientation(gtk::Orientation::Vertical)
.hexpand(true) .hexpand(true)
@ -32,10 +49,11 @@ impl ApplicationWindow {
.margin_start(8) .margin_start(8)
.margin_end(8) .margin_end(8)
.build(); .build();
next_event.add_css_class("card");
next_event.add_css_class("activatable");
layout.append(&next_event); layout.append(&next_event);
let transit_card = TransitCard::new();
layout.append(&transit_card);
let transit_clock = TransitClock::new(); let transit_clock = TransitClock::new();
layout.append(&transit_clock); layout.append(&transit_clock);
@ -45,6 +63,7 @@ impl ApplicationWindow {
window, window,
date_label, date_label,
next_event, next_event,
transit_card,
transit_clock, transit_clock,
} }
} }
@ -53,6 +72,7 @@ impl ApplicationWindow {
self.date_label.update_date(state.date); self.date_label.update_date(state.date);
self.next_event.set_text(&format!("{:?}", state.next_event)); self.next_event.set_text(&format!("{:?}", state.next_event));
if let Some(transit) = state.transit { if let Some(transit) = state.transit {
self.transit_card.update_transit(&transit);
self.transit_clock.update_transit(transit); self.transit_clock.update_transit(transit);
} }
} }

View File

@ -38,8 +38,6 @@ glib::wrapper! {
impl Date { impl Date {
pub fn new() -> Self { pub fn new() -> Self {
let s: Self = Object::builder().build(); let s: Self = Object::builder().build();
s.add_css_class("card");
s.add_css_class("activatable");
s.set_margin_bottom(8); s.set_margin_bottom(8);
s.set_margin_top(8); s.set_margin_top(8);
s.set_margin_start(8); s.set_margin_start(8);

View File

@ -1,5 +1,8 @@
mod date; mod date;
pub use date::Date; pub use date::Date;
mod transit_card;
pub use transit_card::TransitCard;
mod transit_clock; mod transit_clock;
pub use transit_clock::TransitClock; pub use transit_clock::TransitClock;

View File

@ -0,0 +1,73 @@
use crate::soluna_client::SunMoon;
use glib::Object;
use gtk::{prelude::*, subclass::prelude::*};
use std::{cell::RefCell, rc::Rc};
pub struct TransitCardPrivate {
sunrise: gtk::Label,
sunset: gtk::Label,
moonrise: gtk::Label,
moonset: gtk::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),
}
}
}
#[glib::object_subclass]
impl ObjectSubclass for TransitCardPrivate {
const NAME: &'static str = "TransitCard";
type Type = TransitCard;
type ParentType = gtk::Grid;
}
impl ObjectImpl for TransitCardPrivate {}
impl WidgetImpl for TransitCardPrivate {}
impl GridImpl for TransitCardPrivate {}
glib::wrapper! {
pub struct TransitCard(ObjectSubclass<TransitCardPrivate>) @extends gtk::Grid, gtk::Widget;
}
impl TransitCard {
pub fn new() -> Self {
let s: Self = Object::builder().build();
s.add_css_class("card");
s.set_column_homogeneous(true);
s.attach(&s.imp().sunrise, 0, 0, 1, 1);
s.attach(&s.imp().sunset, 0, 1, 1, 1);
s.attach(&s.imp().moonrise, 1, 0, 1, 1);
s.attach(&s.imp().moonset, 1, 1, 1, 1);
s
}
pub fn update_transit(&self, transit_info: &SunMoon) {
self.imp()
.sunrise
.set_text(format!("{}", transit_info.sunrise.format("%H:%M")).as_ref());
self.imp()
.sunset
.set_text(format!("{}", transit_info.sunset.format("%H:%M")).as_ref());
self.imp().moonrise.set_text(
&transit_info
.moonrise
.map(|time| format!("{}", time.format("%H:%M")))
.unwrap_or("".to_owned()),
);
self.imp().moonset.set_text(
&transit_info
.moonset
.map(|time| format!("{}", time.format("%H:%M")))
.unwrap_or("".to_owned()),
);
}
}

View File

@ -70,6 +70,9 @@ pub struct Core {
} }
pub fn main() { pub fn main() {
gio::resources_register_include!("com.luminescent-dreams.dashboard.gresource")
.expect("Failed to register resources");
let app = adw::Application::builder() let app = adw::Application::builder()
.application_id("com.luminescent-dreams.dashboard") .application_id("com.luminescent-dreams.dashboard")
.resource_base_path("/com/luminescent-dreams/dashboard") .resource_base_path("/com/luminescent-dreams/dashboard")