styling with CSS

This commit is contained in:
Greg Johnston 2024-03-30 08:01:34 -04:00
parent 5feaf1aea6
commit f69dbb48ca
3 changed files with 18 additions and 0 deletions

View file

@ -2,6 +2,7 @@
<html>
<head>
<meta name="color-scheme" content="dark">
<link rel="css" href="style.css" data-trunk>
</head>
<body></body>
</html>

View file

@ -27,6 +27,8 @@ fn main() {
_ = Executor::init_glib();
let app = Application::builder().application_id(APP_ID).build();
app.connect_startup(|_| load_css());
app.connect_activate(|app| {
// Connect to "activate" signal of `app`
let owner = Owner::new();
@ -156,3 +158,18 @@ fn hstack(children: impl Render<Rndr>) -> impl Render<Rndr> {
.child(children)
}
}
#[cfg(feature = "gtk")]
fn load_css() {
use gtk::{gdk::Display, CssProvider};
let provider = CssProvider::new();
provider.load_from_path("style.css");
// Add the provider to the default screen
gtk::style_context_add_provider_for_display(
&Display::default().expect("Could not connect to a display."),
&provider,
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
);
}

0
examples/gtk/style.css Normal file
View file