Add the CSS style context to the main window #121
|
@ -0,0 +1,7 @@
|
|||
fn main() {
|
||||
glib_build_tools::compile_resources(
|
||||
&["resources"],
|
||||
"resources/gresources.xml",
|
||||
"com.luminescent-dreams.fitnesstrax.gresource",
|
||||
);
|
||||
}
|
|
@ -1,5 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<schemalist>
|
||||
<schema id="com.luminescent-dreams.fitnesstrax" path="/com/luminescent-dreams/fitnesstrax/">
|
||||
<key name="series-path" type="s">
|
||||
<default>""</default>
|
||||
<summary>Path to the series</summary>
|
||||
</key>
|
||||
</schema>
|
||||
<schema id="com.luminescent-dreams.fitnesstrax.dev" path="/com/luminescent-dreams/fitnesstrax/dev/">
|
||||
<key name="series-path" type="s">
|
||||
<default>""</default>
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gresources>
|
||||
<gresource prefix="/com/luminescent-dreams/fitnesstrax/">
|
||||
<file>style.css</file>
|
||||
</gresource>
|
||||
</gresources>
|
|
@ -1,11 +1,11 @@
|
|||
use gtk::prelude::*;
|
||||
use gio::resources_lookup_data;
|
||||
use gtk::{prelude::*, STYLE_PROVIDER_PRIORITY_USER};
|
||||
use std::env;
|
||||
|
||||
const APP_ID_DEV: &str = "com.luminescent-dreams.fitnesstrax.dev";
|
||||
const APP_ID_PROD: &str = "com.luminescent-dreams.fitnesstrax";
|
||||
|
||||
const RESOURCE_BASE_PATH_DEV: &str = "/com/luminescent-dreams/fitnesstrax/dev/";
|
||||
const RESOURCE_BASE_PATH_PROD: &str = "/com/luminescent-dreams/fitnesstrax/";
|
||||
const RESOURCE_BASE_PATH: &str = "/com/luminescent-dreams/fitnesstrax/";
|
||||
|
||||
struct AppState {}
|
||||
|
||||
|
@ -14,10 +14,17 @@ struct AppWindow {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let (app_id, base_path) = if std::env::var_os("ENV") == Some("dev".into()) {
|
||||
(APP_ID_DEV, RESOURCE_BASE_PATH_DEV)
|
||||
// I still don't fully understand gio resources. resources_register_include! is convenient
|
||||
// because I don't have to deal with filesystem locations at runtime. However, I think other
|
||||
// GTK applications do that rather than compiling the resources directly into the app. So, I'm
|
||||
// unclear as to how I want to handle this.
|
||||
gio::resources_register_include!("com.luminescent-dreams.fitnesstrax.gresource")
|
||||
.expect("to register resources");
|
||||
|
||||
let app_id = if std::env::var_os("ENV") == Some("dev".into()) {
|
||||
APP_ID_DEV
|
||||
} else {
|
||||
(APP_ID_PROD, RESOURCE_BASE_PATH_PROD)
|
||||
APP_ID_PROD
|
||||
};
|
||||
|
||||
let settings = gio::Settings::new(app_id);
|
||||
|
@ -26,7 +33,7 @@ fn main() {
|
|||
|
||||
let app = adw::Application::builder()
|
||||
.application_id(app_id)
|
||||
.resource_base_path(base_path)
|
||||
.resource_base_path(RESOURCE_BASE_PATH)
|
||||
.build();
|
||||
|
||||
/*
|
||||
|
@ -37,12 +44,28 @@ fn main() {
|
|||
*/
|
||||
|
||||
let app = adw::Application::builder()
|
||||
.application_id("com.luminescent-dreams.fitnesstrax")
|
||||
.resource_base_path("/com/luminescent-dreams/fitnesstrax")
|
||||
.application_id(app_id)
|
||||
.resource_base_path(RESOURCE_BASE_PATH)
|
||||
.build();
|
||||
|
||||
app.connect_activate(move |app| {
|
||||
let stylesheet = String::from_utf8(
|
||||
resources_lookup_data(
|
||||
&format!("{}style.css", RESOURCE_BASE_PATH),
|
||||
gio::ResourceLookupFlags::NONE,
|
||||
)
|
||||
.expect("stylesheet must be available in the resources")
|
||||
.to_vec(),
|
||||
)
|
||||
.expect("to parse stylesheet");
|
||||
|
||||
let provider = gtk::CssProvider::new();
|
||||
provider.load_from_data(&stylesheet);
|
||||
|
||||
let window = adw::ApplicationWindow::new(app);
|
||||
let context = window.style_context();
|
||||
context.add_provider(&provider, STYLE_PROVIDER_PRIORITY_USER);
|
||||
|
||||
window.present();
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue