From 1d10d8b48141f6adca5bff2f2168e5daa0ee9f27 Mon Sep 17 00:00:00 2001 From: Ward from fusion-voyager-3 Date: Mon, 17 Jun 2024 02:32:55 +0300 Subject: [PATCH] add github badge like kernel indicators --- data/style.css | 18 +++++++++++++ src/build_ui/mod.rs | 8 +++++- src/content/mod.rs | 63 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 87 insertions(+), 2 deletions(-) diff --git a/data/style.css b/data/style.css index c16ece3..ed862a7 100644 --- a/data/style.css +++ b/data/style.css @@ -1,3 +1,21 @@ .symbolic-accent-bg { color: @accent_bg_color; +} + +.background-accent-bg { + background: @accent_bg_color; + border-radius: 10px; + padding: 5px; +} + +.background-green-bg { + background: green; + border-radius: 10px; + padding: 5px; +} + +.background-salmon-bg { + background: darksalmon; + border-radius: 10px; + padding: 5px; } \ No newline at end of file diff --git a/src/build_ui/mod.rs b/src/build_ui/mod.rs index e05b568..8ce9dc5 100644 --- a/src/build_ui/mod.rs +++ b/src/build_ui/mod.rs @@ -3,13 +3,19 @@ use gtk::prelude::*; use adw::*; use adw::prelude::*; use crate::{content, PRETTY_NAME}; -use content::content; pub fn build_ui(app: &adw::Application) { let window = adw::ApplicationWindow::new(app); load_icon_theme(&window); + window.connect_close_request(move |window| { + if let Some(application) = window.application() { + application.remove_window(window); + } + glib::Propagation::Proceed + }); + let window_headerbar = adw::HeaderBar::builder() .title_widget(&adw::WindowTitle::builder().title(PRETTY_NAME).build()) .build(); diff --git a/src/content/mod.rs b/src/content/mod.rs index f81c50c..2909af3 100644 --- a/src/content/mod.rs +++ b/src/content/mod.rs @@ -1,4 +1,5 @@ -use gtk::{Align, IconSize}; +use adw::prelude::ActionRowExt; +use gtk::{Align, IconSize, Orientation, SelectionMode, SizeGroupMode}; use gtk::prelude::{BoxExt, WidgetExt}; pub fn content() -> gtk::Box { @@ -6,19 +7,79 @@ pub fn content() -> gtk::Box { let content_box = gtk::Box::builder() .hexpand(true) .vexpand(true) + .orientation(Orientation::Vertical) .build(); let tux_icon = gtk::Image::builder() .pixel_size(128) .halign(Align::Center) .hexpand(true) + .margin_start(10) + .margin_end(10) + .margin_bottom(20) + .margin_top(20) .build(); tux_icon.set_icon_name(Some("tux-symbolic")); tux_icon.add_css_class("symbolic-accent-bg"); + let kernel_badges_size_group = gtk::SizeGroup::new(SizeGroupMode::Both); + + content_box.append(&create_kernel_badge("Kernel Branch", "cachy", "background-accent-bg", &kernel_badges_size_group)); + content_box.append(&create_kernel_badge("Latest Version", "6.9", "background-accent-bg", &kernel_badges_size_group)); + content_box.append(&create_kernel_badge("Running Version", "6.8.3", "background-salmon-bg", &kernel_badges_size_group)); + content_box.append(&create_kernel_badge("Running Sched", "sched-ext: rusty", "background-accent-bg", &kernel_badges_size_group)); content_box.append(&tux_icon); content_box +} + +fn create_kernel_badge(label0_text: &str, label1_text: &str, css_style: &str, group_size: >k::SizeGroup) -> gtk::ListBox { + let badge_box = gtk::Box::builder() + .build(); + + let label0 = gtk::Label::builder() + .label(label0_text) + .margin_start(5) + .margin_end(5) + .margin_bottom(1) + .margin_top(1) + .hexpand(true) + .vexpand(true) + .build(); + + let label_seprator = gtk::Separator::builder() + .build(); + + let label1 = gtk::Label::builder() + .label(label1_text) + .margin_start(3) + .margin_end(0) + .margin_bottom(1) + .margin_top(1) + .hexpand(true) + .vexpand(true) + .build(); + + label1.add_css_class(css_style); + + badge_box.append(&label0); + badge_box.append(&label_seprator); + badge_box.append(&label1); + + let boxedlist = gtk::ListBox::builder() + .selection_mode(SelectionMode::None) + .halign(Align::Center) + .valign(Align::End) + .margin_start(5) + .margin_end(5) + .margin_bottom(5) + .margin_top(5) + .build(); + + boxedlist.add_css_class("boxed-list"); + boxedlist.append(&badge_box); + group_size.add_widget(&boxedlist); + boxedlist } \ No newline at end of file