Add a CSS stylesheet

This commit is contained in:
Savanni D'Gerinel 2023-08-24 22:10:05 -04:00
parent cc828c417a
commit 16c8dcb682
4 changed files with 26 additions and 11 deletions

View File

@ -1,7 +1,7 @@
fn main() { fn main() {
glib_build_tools::compile_resources( glib_build_tools::compile_resources(
&["resources"], &["resources"],
"resources/resources.gresources.xml", "resources/gresources.xml",
"com.luminescent-dreams.kifu-gtk.gresource", "com.luminescent-dreams.kifu-gtk.gresource",
); );
} }

View File

@ -2,5 +2,6 @@
<gresources> <gresources>
<gresource prefix="/com/luminescent-dreams/kifu-gtk/"> <gresource prefix="/com/luminescent-dreams/kifu-gtk/">
<file>wood_texture.jpg</file> <file>wood_texture.jpg</file>
<file>style.css</file>
</gresource> </gresource>
</gresources> </gresources>

View File

@ -0,0 +1 @@
@define_color accent_color: @purple_5;

View File

@ -1,6 +1,7 @@
use adw::prelude::*; use adw::prelude::*;
use gio::resources_lookup_data;
use glib::IsA; use glib::IsA;
use gtk::prelude::*; use gtk::{prelude::*, STYLE_PROVIDER_PRIORITY_USER};
mod chat; mod chat;
pub use chat::Chat; pub use chat::Chat;
@ -14,9 +15,6 @@ pub use game_preview::GamePreview;
mod library; mod library;
pub use library::Library; pub use library::Library;
mod layout;
pub use layout::Layout;
mod player_card; mod player_card;
pub use player_card::PlayerCard; pub use player_card::PlayerCard;
@ -40,6 +38,27 @@ pub struct AppWindow {
impl AppWindow { impl AppWindow {
pub fn new(app: &adw::Application) -> Self { 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() let header = adw::HeaderBar::builder()
.title_widget(&gtk::Label::new(Some("Kifu"))) .title_widget(&gtk::Label::new(Some("Kifu")))
.build(); .build();
@ -66,12 +85,6 @@ impl AppWindow {
layout.append(&header); layout.append(&header);
layout.append(&content); layout.append(&content);
let window = adw::ApplicationWindow::builder()
.application(app)
.width_request(800)
.height_request(500)
.build();
window.set_content(Some(&layout)); window.set_content(Some(&layout));
Self { Self {