Set up a stylesheet

This commit is contained in:
Savanni D'Gerinel 2023-08-10 11:07:35 -04:00
parent 4afdd16414
commit 038ccac637
7 changed files with 44 additions and 1 deletions

1
Cargo.lock generated
View File

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

View File

@ -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"

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

@ -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)

View File

@ -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")