From 16c8dcb682cdc7cb104ea2a5ee26d16dd7fd00da Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Thu, 24 Aug 2023 22:10:05 -0400 Subject: [PATCH] Add a CSS stylesheet --- kifu/gtk/build.rs | 2 +- ...esources.gresources.xml => gresources.xml} | 1 + kifu/gtk/resources/style.css | 1 + kifu/gtk/src/ui/mod.rs | 33 +++++++++++++------ 4 files changed, 26 insertions(+), 11 deletions(-) rename kifu/gtk/resources/{resources.gresources.xml => gresources.xml} (85%) create mode 100644 kifu/gtk/resources/style.css diff --git a/kifu/gtk/build.rs b/kifu/gtk/build.rs index 18b1e1e..6e5a750 100644 --- a/kifu/gtk/build.rs +++ b/kifu/gtk/build.rs @@ -1,7 +1,7 @@ fn main() { glib_build_tools::compile_resources( &["resources"], - "resources/resources.gresources.xml", + "resources/gresources.xml", "com.luminescent-dreams.kifu-gtk.gresource", ); } diff --git a/kifu/gtk/resources/resources.gresources.xml b/kifu/gtk/resources/gresources.xml similarity index 85% rename from kifu/gtk/resources/resources.gresources.xml rename to kifu/gtk/resources/gresources.xml index 31ca0a0..557a5ba 100644 --- a/kifu/gtk/resources/resources.gresources.xml +++ b/kifu/gtk/resources/gresources.xml @@ -2,5 +2,6 @@ wood_texture.jpg + style.css diff --git a/kifu/gtk/resources/style.css b/kifu/gtk/resources/style.css new file mode 100644 index 0000000..c8af75c --- /dev/null +++ b/kifu/gtk/resources/style.css @@ -0,0 +1 @@ +@define_color accent_color: @purple_5; diff --git a/kifu/gtk/src/ui/mod.rs b/kifu/gtk/src/ui/mod.rs index 30cd24d..c1f1034 100644 --- a/kifu/gtk/src/ui/mod.rs +++ b/kifu/gtk/src/ui/mod.rs @@ -1,6 +1,7 @@ use adw::prelude::*; +use gio::resources_lookup_data; use glib::IsA; -use gtk::prelude::*; +use gtk::{prelude::*, STYLE_PROVIDER_PRIORITY_USER}; mod chat; pub use chat::Chat; @@ -14,9 +15,6 @@ pub use game_preview::GamePreview; mod library; pub use library::Library; -mod layout; -pub use layout::Layout; - mod player_card; pub use player_card::PlayerCard; @@ -40,6 +38,27 @@ pub struct AppWindow { impl AppWindow { pub fn new(app: &adw::Application) -> Self { + let window = adw::ApplicationWindow::builder() + .application(app) + .width_request(800) + .height_request(500) + .build(); + + let stylesheet = String::from_utf8( + resources_lookup_data( + "/com/luminescent-dreams/kifu-gtk/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 content = window.style_context(); + content.add_provider(&provider, STYLE_PROVIDER_PRIORITY_USER); + let header = adw::HeaderBar::builder() .title_widget(>k::Label::new(Some("Kifu"))) .build(); @@ -66,12 +85,6 @@ impl AppWindow { layout.append(&header); layout.append(&content); - let window = adw::ApplicationWindow::builder() - .application(app) - .width_request(800) - .height_request(500) - .build(); - window.set_content(Some(&layout)); Self {