From 5d52b1b26d70a4cd1906c200ed6356c065994cdb Mon Sep 17 00:00:00 2001 From: ferrreo Date: Fri, 30 Jun 2023 18:01:45 +0100 Subject: [PATCH] Style middle bit using css --- src/main.rs | 29 ++++++++++++++++++++--------- src/style.css | 5 +++++ 2 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 src/style.css diff --git a/src/main.rs b/src/main.rs index 8601155..d1e5a2a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,14 +2,25 @@ use std::process::Command; use gtk::prelude::*; use gtk::*; use glib::*; - +use gdk::Display; fn main() { - let app = Application::builder() - .application_id("com.pika.drivers") - .build(); - - app.connect_activate(build_ui); - app.run(); + let application = Application::new(Some("com.pika.drivers"), Default::default()); + application.connect_startup(|app| { + // The CSS "magic" happens here. + let provider = CssProvider::new(); + provider.load_from_data(include_str!("style.css")); + // We give the CssProvided to the default screen so the CSS rules we added + // can be applied to our window. + gtk::style_context_add_provider_for_display( + &Display::default().expect("Could not connect to a display."), + &provider, + STYLE_PROVIDER_PRIORITY_APPLICATION, + ); + + app.connect_activate(build_ui); + }); + + application.run(); } @@ -159,10 +170,10 @@ fn build_ui(app: &Application) { .margin_start(12) .margin_end(12) .hexpand(true) - .justify(Justification::Center) + .justify(Justification::Left) .wrap(true) .build(); - + driver_middle_part_description_label.add_css_class("midLabel"); driver_version_icon.set_tooltip_text(Some(&String::from_utf8(command_version_label.stdout).unwrap())); driver_device_icon.set_tooltip_text(Some(&String::from_utf8(command_device_label.stdout).unwrap())); driver_middle_part_description_label.set_text(&String::from_utf8(command_description_label.stdout).unwrap()); diff --git a/src/style.css b/src/style.css new file mode 100644 index 0000000..13359ff --- /dev/null +++ b/src/style.css @@ -0,0 +1,5 @@ +.midLabel { + padding-left: 30px; + margin-left: 30px; + color: red; +} \ No newline at end of file