Include CSS as GResource
Also use explicit namespace for bare functions and constants used in main.rs.
This commit is contained in:
parent
fc5bfd5876
commit
5e5df5c401
6 changed files with 39 additions and 6 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
|
@ -364,6 +364,15 @@ dependencies = [
|
||||||
"smallvec",
|
"smallvec",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "glib-build-tools"
|
||||||
|
version = "0.21.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "86aebe63bb050d4918cb1d629880cb35fcba7ccda6f6fc0ec1beffdaa1b9d5c3"
|
||||||
|
dependencies = [
|
||||||
|
"gio",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glib-macros"
|
name = "glib-macros"
|
||||||
version = "0.21.5"
|
version = "0.21.5"
|
||||||
|
|
@ -1109,6 +1118,7 @@ name = "zoodex"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-sqlite",
|
"async-sqlite",
|
||||||
|
"glib-build-tools",
|
||||||
"gtk4",
|
"gtk4",
|
||||||
"libadwaita",
|
"libadwaita",
|
||||||
"relm4",
|
"relm4",
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,10 @@ license = "GPL-3.0-or-later"
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
# Keep version in sync with GLib as included in GTK4
|
||||||
|
glib-build-tools = "0.21.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-sqlite = { version = "0.5.4", default-features = false }
|
async-sqlite = { version = "0.5.4", default-features = false }
|
||||||
gtk4 = { version = "0.10.3", features = ["v4_20"] }
|
gtk4 = { version = "0.10.3", features = ["v4_20"] }
|
||||||
|
|
|
||||||
7
build.rs
Normal file
7
build.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
use glib_build_tools::compile_resources;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
compile_resources(&["data"], "data/zoodex.gresource.xml", "zoodex.gresource");
|
||||||
|
}
|
||||||
6
data/zoodex.gresource.xml
Normal file
6
data/zoodex.gresource.xml
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<gresources>
|
||||||
|
<gresource prefix="/com/kernelmaft/zoodex/">
|
||||||
|
<file>application.css</file>
|
||||||
|
</gresource>
|
||||||
|
</gresources>
|
||||||
18
src/main.rs
18
src/main.rs
|
|
@ -5,10 +5,8 @@ mod ui;
|
||||||
mod views;
|
mod views;
|
||||||
|
|
||||||
use gtk4::gdk::Display;
|
use gtk4::gdk::Display;
|
||||||
use gtk4::{
|
use gtk4::gio::File;
|
||||||
CssProvider, STYLE_PROVIDER_PRIORITY_APPLICATION, Settings,
|
use gtk4::{CssProvider, Settings, gio};
|
||||||
style_context_add_provider_for_display,
|
|
||||||
};
|
|
||||||
use relm4::RelmApp;
|
use relm4::RelmApp;
|
||||||
|
|
||||||
use crate::ui::App;
|
use crate::ui::App;
|
||||||
|
|
@ -30,11 +28,19 @@ fn include_app_css() {
|
||||||
// We can't use relm4::set_global_css because we need access to the CSS provider
|
// We can't use relm4::set_global_css because we need access to the CSS provider
|
||||||
// to relay color scheme changes to it.
|
// to relay color scheme changes to it.
|
||||||
|
|
||||||
|
gio::resources_register_include!("zoodex.gresource")
|
||||||
|
.expect("CSS resource bundle should have valid format");
|
||||||
|
let app_css = File::for_uri("resource:///com/kernelmaft/zoodex/application.css");
|
||||||
|
|
||||||
let provider = CssProvider::new();
|
let provider = CssProvider::new();
|
||||||
let display = Display::default().expect("getting the default GDK4 display should never fail");
|
let display = Display::default().expect("getting the default GDK4 display should never fail");
|
||||||
|
|
||||||
provider.load_from_string(include_str!("application.css"));
|
provider.load_from_file(&app_css);
|
||||||
style_context_add_provider_for_display(&display, &provider, STYLE_PROVIDER_PRIORITY_APPLICATION);
|
gtk4::style_context_add_provider_for_display(
|
||||||
|
&display,
|
||||||
|
&provider,
|
||||||
|
gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION,
|
||||||
|
);
|
||||||
|
|
||||||
let settings = Settings::for_display(&display);
|
let settings = Settings::for_display(&display);
|
||||||
provider.set_prefers_color_scheme(settings.gtk_interface_color_scheme());
|
provider.set_prefers_color_scheme(settings.gtk_interface_color_scheme());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue