From 038ccac6378124fa873a5ba5d25448d27bfc65d9 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Thu, 10 Aug 2023 11:07:35 -0400 Subject: [PATCH] Set up a stylesheet --- Cargo.lock | 1 + dashboard/Cargo.toml | 4 ++++ dashboard/build.rs | 7 +++++++ dashboard/resources/gresources.xml | 7 +++++++ dashboard/resources/style.css | 5 +++++ dashboard/src/app_window.rs | 18 +++++++++++++++++- dashboard/src/main.rs | 3 +++ 7 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 dashboard/build.rs create mode 100644 dashboard/resources/gresources.xml create mode 100644 dashboard/resources/style.css diff --git a/Cargo.lock b/Cargo.lock index 1739816..b25cc16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -339,6 +339,7 @@ dependencies = [ "geo-types", "gio", "glib", + "glib-build-tools", "gtk4", "ifc", "lazy_static", diff --git a/dashboard/Cargo.toml b/dashboard/Cargo.toml index 9ce0edb..e558242 100644 --- a/dashboard/Cargo.toml +++ b/dashboard/Cargo.toml @@ -26,3 +26,7 @@ serde_json = { version = "1" } serde = { version = "1" } tokio = { version = "1", features = ["full"] } unic-langid = { version = "0.9" } + +[build-dependencies] +glib-build-tools = "0.16" + diff --git a/dashboard/build.rs b/dashboard/build.rs new file mode 100644 index 0000000..2f8c7ae --- /dev/null +++ b/dashboard/build.rs @@ -0,0 +1,7 @@ +fn main() { + glib_build_tools::compile_resources( + "resources", + "resources/gresources.xml", + "com.luminescent-dreams.dashboard.gresource", + ); +} diff --git a/dashboard/resources/gresources.xml b/dashboard/resources/gresources.xml new file mode 100644 index 0000000..2baf821 --- /dev/null +++ b/dashboard/resources/gresources.xml @@ -0,0 +1,7 @@ + + + + style.css + + + diff --git a/dashboard/resources/style.css b/dashboard/resources/style.css new file mode 100644 index 0000000..6f9bc0b --- /dev/null +++ b/dashboard/resources/style.css @@ -0,0 +1,5 @@ +@define-color background_color @purple_5; + +label { + font-size: 200%; +} diff --git a/dashboard/src/app_window.rs b/dashboard/src/app_window.rs index 90e0cd6..7051687 100644 --- a/dashboard/src/app_window.rs +++ b/dashboard/src/app_window.rs @@ -3,7 +3,8 @@ use crate::{ types::State, }; use adw::prelude::AdwApplicationWindowExt; -use gtk::prelude::*; +use gio::resources_lookup_data; +use gtk::{prelude::*, STYLE_PROVIDER_PRIORITY_USER}; #[derive(Clone)] pub struct ApplicationWindow { @@ -17,6 +18,21 @@ impl ApplicationWindow { pub fn new(app: &adw::Application) -> Self { 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() .orientation(gtk::Orientation::Vertical) .hexpand(true) diff --git a/dashboard/src/main.rs b/dashboard/src/main.rs index 57a79a4..cd51809 100644 --- a/dashboard/src/main.rs +++ b/dashboard/src/main.rs @@ -70,6 +70,9 @@ pub struct Core { } pub fn main() { + gio::resources_register_include!("com.luminescent-dreams.dashboard.gresource") + .expect("Failed to register resources"); + let app = adw::Application::builder() .application_id("com.luminescent-dreams.dashboard") .resource_base_path("/com/luminescent-dreams/dashboard") -- 2.44.1