From bc4dabda4a941c0c9764fae2c8d11abbfdc0a9f5 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 13 Sep 2024 18:33:19 -0700 Subject: [PATCH] feat(bar): add accents to widget emojis --- komorebi-bar/src/bar.rs | 351 ++++++++++++++++++------------------ komorebi-bar/src/battery.rs | 69 ++++--- komorebi-bar/src/date.rs | 46 +++-- komorebi-bar/src/main.rs | 9 +- komorebi-bar/src/media.rs | 41 ++++- komorebi-bar/src/memory.rs | 35 +++- komorebi-bar/src/network.rs | 47 +++-- komorebi-bar/src/storage.rs | 36 +++- komorebi-bar/src/time.rs | 37 +++- 9 files changed, 420 insertions(+), 251 deletions(-) diff --git a/komorebi-bar/src/bar.rs b/komorebi-bar/src/bar.rs index 792620b7..4afb0219 100644 --- a/komorebi-bar/src/bar.rs +++ b/komorebi-bar/src/bar.rs @@ -59,166 +59,170 @@ impl Komobar { } => match catppuccin { Catppuccin::Frappe => { catppuccin_egui::set_theme(ctx, catppuccin_egui::FRAPPE); - if let Some(catppuccin_value) = catppuccin_value { - let accent = match catppuccin_value { - CatppuccinValue::Rosewater => catppuccin_egui::FRAPPE.rosewater, - CatppuccinValue::Flamingo => catppuccin_egui::FRAPPE.flamingo, - CatppuccinValue::Pink => catppuccin_egui::FRAPPE.pink, - CatppuccinValue::Mauve => catppuccin_egui::FRAPPE.mauve, - CatppuccinValue::Red => catppuccin_egui::FRAPPE.red, - CatppuccinValue::Maroon => catppuccin_egui::FRAPPE.maroon, - CatppuccinValue::Peach => catppuccin_egui::FRAPPE.peach, - CatppuccinValue::Yellow => catppuccin_egui::FRAPPE.yellow, - CatppuccinValue::Green => catppuccin_egui::FRAPPE.green, - CatppuccinValue::Teal => catppuccin_egui::FRAPPE.teal, - CatppuccinValue::Sky => catppuccin_egui::FRAPPE.sky, - CatppuccinValue::Sapphire => catppuccin_egui::FRAPPE.sapphire, - CatppuccinValue::Blue => catppuccin_egui::FRAPPE.blue, - CatppuccinValue::Lavender => catppuccin_egui::FRAPPE.lavender, - CatppuccinValue::Text => catppuccin_egui::FRAPPE.text, - CatppuccinValue::Subtext1 => catppuccin_egui::FRAPPE.subtext1, - CatppuccinValue::Subtext0 => catppuccin_egui::FRAPPE.subtext0, - CatppuccinValue::Overlay2 => catppuccin_egui::FRAPPE.overlay2, - CatppuccinValue::Overlay1 => catppuccin_egui::FRAPPE.overlay1, - CatppuccinValue::Overlay0 => catppuccin_egui::FRAPPE.overlay0, - CatppuccinValue::Surface2 => catppuccin_egui::FRAPPE.surface2, - CatppuccinValue::Surface1 => catppuccin_egui::FRAPPE.surface1, - CatppuccinValue::Surface0 => catppuccin_egui::FRAPPE.surface0, - CatppuccinValue::Base => catppuccin_egui::FRAPPE.base, - CatppuccinValue::Mantle => catppuccin_egui::FRAPPE.mantle, - CatppuccinValue::Crust => catppuccin_egui::FRAPPE.crust, - }; - - ctx.style_mut(|style| { - style.visuals.selection.stroke.color = accent; - style.visuals.widgets.hovered.fg_stroke.color = accent; - style.visuals.widgets.active.fg_stroke.color = accent; - style.visuals.override_text_color = None; - }); - } + let catppuccin_value = catppuccin_value.unwrap_or_default(); + + let accent = match catppuccin_value { + CatppuccinValue::Rosewater => catppuccin_egui::FRAPPE.rosewater, + CatppuccinValue::Flamingo => catppuccin_egui::FRAPPE.flamingo, + CatppuccinValue::Pink => catppuccin_egui::FRAPPE.pink, + CatppuccinValue::Mauve => catppuccin_egui::FRAPPE.mauve, + CatppuccinValue::Red => catppuccin_egui::FRAPPE.red, + CatppuccinValue::Maroon => catppuccin_egui::FRAPPE.maroon, + CatppuccinValue::Peach => catppuccin_egui::FRAPPE.peach, + CatppuccinValue::Yellow => catppuccin_egui::FRAPPE.yellow, + CatppuccinValue::Green => catppuccin_egui::FRAPPE.green, + CatppuccinValue::Teal => catppuccin_egui::FRAPPE.teal, + CatppuccinValue::Sky => catppuccin_egui::FRAPPE.sky, + CatppuccinValue::Sapphire => catppuccin_egui::FRAPPE.sapphire, + CatppuccinValue::Blue => catppuccin_egui::FRAPPE.blue, + CatppuccinValue::Lavender => catppuccin_egui::FRAPPE.lavender, + CatppuccinValue::Text => catppuccin_egui::FRAPPE.text, + CatppuccinValue::Subtext1 => catppuccin_egui::FRAPPE.subtext1, + CatppuccinValue::Subtext0 => catppuccin_egui::FRAPPE.subtext0, + CatppuccinValue::Overlay2 => catppuccin_egui::FRAPPE.overlay2, + CatppuccinValue::Overlay1 => catppuccin_egui::FRAPPE.overlay1, + CatppuccinValue::Overlay0 => catppuccin_egui::FRAPPE.overlay0, + CatppuccinValue::Surface2 => catppuccin_egui::FRAPPE.surface2, + CatppuccinValue::Surface1 => catppuccin_egui::FRAPPE.surface1, + CatppuccinValue::Surface0 => catppuccin_egui::FRAPPE.surface0, + CatppuccinValue::Base => catppuccin_egui::FRAPPE.base, + CatppuccinValue::Mantle => catppuccin_egui::FRAPPE.mantle, + CatppuccinValue::Crust => catppuccin_egui::FRAPPE.crust, + }; + + ctx.style_mut(|style| { + style.visuals.selection.stroke.color = accent; + style.visuals.widgets.hovered.fg_stroke.color = accent; + style.visuals.widgets.active.fg_stroke.color = accent; + style.visuals.override_text_color = None; + }); + self.bg_color = catppuccin_egui::FRAPPE.base; } Catppuccin::Latte => { catppuccin_egui::set_theme(ctx, catppuccin_egui::LATTE); - if let Some(catppuccin_value) = catppuccin_value { - let accent = match catppuccin_value { - CatppuccinValue::Rosewater => catppuccin_egui::LATTE.rosewater, - CatppuccinValue::Flamingo => catppuccin_egui::LATTE.flamingo, - CatppuccinValue::Pink => catppuccin_egui::LATTE.pink, - CatppuccinValue::Mauve => catppuccin_egui::LATTE.mauve, - CatppuccinValue::Red => catppuccin_egui::LATTE.red, - CatppuccinValue::Maroon => catppuccin_egui::LATTE.maroon, - CatppuccinValue::Peach => catppuccin_egui::LATTE.peach, - CatppuccinValue::Yellow => catppuccin_egui::LATTE.yellow, - CatppuccinValue::Green => catppuccin_egui::LATTE.green, - CatppuccinValue::Teal => catppuccin_egui::LATTE.teal, - CatppuccinValue::Sky => catppuccin_egui::LATTE.sky, - CatppuccinValue::Sapphire => catppuccin_egui::LATTE.sapphire, - CatppuccinValue::Blue => catppuccin_egui::LATTE.blue, - CatppuccinValue::Lavender => catppuccin_egui::LATTE.lavender, - CatppuccinValue::Text => catppuccin_egui::LATTE.text, - CatppuccinValue::Subtext1 => catppuccin_egui::LATTE.subtext1, - CatppuccinValue::Subtext0 => catppuccin_egui::LATTE.subtext0, - CatppuccinValue::Overlay2 => catppuccin_egui::LATTE.overlay2, - CatppuccinValue::Overlay1 => catppuccin_egui::LATTE.overlay1, - CatppuccinValue::Overlay0 => catppuccin_egui::LATTE.overlay0, - CatppuccinValue::Surface2 => catppuccin_egui::LATTE.surface2, - CatppuccinValue::Surface1 => catppuccin_egui::LATTE.surface1, - CatppuccinValue::Surface0 => catppuccin_egui::LATTE.surface0, - CatppuccinValue::Base => catppuccin_egui::LATTE.base, - CatppuccinValue::Mantle => catppuccin_egui::LATTE.mantle, - CatppuccinValue::Crust => catppuccin_egui::LATTE.crust, - }; - - ctx.style_mut(|style| { - style.visuals.selection.stroke.color = accent; - style.visuals.widgets.hovered.fg_stroke.color = accent; - style.visuals.widgets.active.fg_stroke.color = accent; - style.visuals.override_text_color = None; - }); - } + let catppuccin_value = catppuccin_value.unwrap_or_default(); + + let accent = match catppuccin_value { + CatppuccinValue::Rosewater => catppuccin_egui::LATTE.rosewater, + CatppuccinValue::Flamingo => catppuccin_egui::LATTE.flamingo, + CatppuccinValue::Pink => catppuccin_egui::LATTE.pink, + CatppuccinValue::Mauve => catppuccin_egui::LATTE.mauve, + CatppuccinValue::Red => catppuccin_egui::LATTE.red, + CatppuccinValue::Maroon => catppuccin_egui::LATTE.maroon, + CatppuccinValue::Peach => catppuccin_egui::LATTE.peach, + CatppuccinValue::Yellow => catppuccin_egui::LATTE.yellow, + CatppuccinValue::Green => catppuccin_egui::LATTE.green, + CatppuccinValue::Teal => catppuccin_egui::LATTE.teal, + CatppuccinValue::Sky => catppuccin_egui::LATTE.sky, + CatppuccinValue::Sapphire => catppuccin_egui::LATTE.sapphire, + CatppuccinValue::Blue => catppuccin_egui::LATTE.blue, + CatppuccinValue::Lavender => catppuccin_egui::LATTE.lavender, + CatppuccinValue::Text => catppuccin_egui::LATTE.text, + CatppuccinValue::Subtext1 => catppuccin_egui::LATTE.subtext1, + CatppuccinValue::Subtext0 => catppuccin_egui::LATTE.subtext0, + CatppuccinValue::Overlay2 => catppuccin_egui::LATTE.overlay2, + CatppuccinValue::Overlay1 => catppuccin_egui::LATTE.overlay1, + CatppuccinValue::Overlay0 => catppuccin_egui::LATTE.overlay0, + CatppuccinValue::Surface2 => catppuccin_egui::LATTE.surface2, + CatppuccinValue::Surface1 => catppuccin_egui::LATTE.surface1, + CatppuccinValue::Surface0 => catppuccin_egui::LATTE.surface0, + CatppuccinValue::Base => catppuccin_egui::LATTE.base, + CatppuccinValue::Mantle => catppuccin_egui::LATTE.mantle, + CatppuccinValue::Crust => catppuccin_egui::LATTE.crust, + }; + + ctx.style_mut(|style| { + style.visuals.selection.stroke.color = accent; + style.visuals.widgets.hovered.fg_stroke.color = accent; + style.visuals.widgets.active.fg_stroke.color = accent; + style.visuals.override_text_color = None; + }); + self.bg_color = catppuccin_egui::LATTE.base; } Catppuccin::Macchiato => { catppuccin_egui::set_theme(ctx, catppuccin_egui::MACCHIATO); - if let Some(catppuccin_value) = catppuccin_value { - let accent = match catppuccin_value { - CatppuccinValue::Rosewater => catppuccin_egui::MACCHIATO.rosewater, - CatppuccinValue::Flamingo => catppuccin_egui::MACCHIATO.flamingo, - CatppuccinValue::Pink => catppuccin_egui::MACCHIATO.pink, - CatppuccinValue::Mauve => catppuccin_egui::MACCHIATO.mauve, - CatppuccinValue::Red => catppuccin_egui::MACCHIATO.red, - CatppuccinValue::Maroon => catppuccin_egui::MACCHIATO.maroon, - CatppuccinValue::Peach => catppuccin_egui::MACCHIATO.peach, - CatppuccinValue::Yellow => catppuccin_egui::MACCHIATO.yellow, - CatppuccinValue::Green => catppuccin_egui::MACCHIATO.green, - CatppuccinValue::Teal => catppuccin_egui::MACCHIATO.teal, - CatppuccinValue::Sky => catppuccin_egui::MACCHIATO.sky, - CatppuccinValue::Sapphire => catppuccin_egui::MACCHIATO.sapphire, - CatppuccinValue::Blue => catppuccin_egui::MACCHIATO.blue, - CatppuccinValue::Lavender => catppuccin_egui::MACCHIATO.lavender, - CatppuccinValue::Text => catppuccin_egui::MACCHIATO.text, - CatppuccinValue::Subtext1 => catppuccin_egui::MACCHIATO.subtext1, - CatppuccinValue::Subtext0 => catppuccin_egui::MACCHIATO.subtext0, - CatppuccinValue::Overlay2 => catppuccin_egui::MACCHIATO.overlay2, - CatppuccinValue::Overlay1 => catppuccin_egui::MACCHIATO.overlay1, - CatppuccinValue::Overlay0 => catppuccin_egui::MACCHIATO.overlay0, - CatppuccinValue::Surface2 => catppuccin_egui::MACCHIATO.surface2, - CatppuccinValue::Surface1 => catppuccin_egui::MACCHIATO.surface1, - CatppuccinValue::Surface0 => catppuccin_egui::MACCHIATO.surface0, - CatppuccinValue::Base => catppuccin_egui::MACCHIATO.base, - CatppuccinValue::Mantle => catppuccin_egui::MACCHIATO.mantle, - CatppuccinValue::Crust => catppuccin_egui::MACCHIATO.crust, - }; - - ctx.style_mut(|style| { - style.visuals.selection.stroke.color = accent; - style.visuals.widgets.hovered.fg_stroke.color = accent; - style.visuals.widgets.active.fg_stroke.color = accent; - style.visuals.override_text_color = None; - }); - } + let catppuccin_value = catppuccin_value.unwrap_or_default(); + + let accent = match catppuccin_value { + CatppuccinValue::Rosewater => catppuccin_egui::MACCHIATO.rosewater, + CatppuccinValue::Flamingo => catppuccin_egui::MACCHIATO.flamingo, + CatppuccinValue::Pink => catppuccin_egui::MACCHIATO.pink, + CatppuccinValue::Mauve => catppuccin_egui::MACCHIATO.mauve, + CatppuccinValue::Red => catppuccin_egui::MACCHIATO.red, + CatppuccinValue::Maroon => catppuccin_egui::MACCHIATO.maroon, + CatppuccinValue::Peach => catppuccin_egui::MACCHIATO.peach, + CatppuccinValue::Yellow => catppuccin_egui::MACCHIATO.yellow, + CatppuccinValue::Green => catppuccin_egui::MACCHIATO.green, + CatppuccinValue::Teal => catppuccin_egui::MACCHIATO.teal, + CatppuccinValue::Sky => catppuccin_egui::MACCHIATO.sky, + CatppuccinValue::Sapphire => catppuccin_egui::MACCHIATO.sapphire, + CatppuccinValue::Blue => catppuccin_egui::MACCHIATO.blue, + CatppuccinValue::Lavender => catppuccin_egui::MACCHIATO.lavender, + CatppuccinValue::Text => catppuccin_egui::MACCHIATO.text, + CatppuccinValue::Subtext1 => catppuccin_egui::MACCHIATO.subtext1, + CatppuccinValue::Subtext0 => catppuccin_egui::MACCHIATO.subtext0, + CatppuccinValue::Overlay2 => catppuccin_egui::MACCHIATO.overlay2, + CatppuccinValue::Overlay1 => catppuccin_egui::MACCHIATO.overlay1, + CatppuccinValue::Overlay0 => catppuccin_egui::MACCHIATO.overlay0, + CatppuccinValue::Surface2 => catppuccin_egui::MACCHIATO.surface2, + CatppuccinValue::Surface1 => catppuccin_egui::MACCHIATO.surface1, + CatppuccinValue::Surface0 => catppuccin_egui::MACCHIATO.surface0, + CatppuccinValue::Base => catppuccin_egui::MACCHIATO.base, + CatppuccinValue::Mantle => catppuccin_egui::MACCHIATO.mantle, + CatppuccinValue::Crust => catppuccin_egui::MACCHIATO.crust, + }; + + ctx.style_mut(|style| { + style.visuals.selection.stroke.color = accent; + style.visuals.widgets.hovered.fg_stroke.color = accent; + style.visuals.widgets.active.fg_stroke.color = accent; + style.visuals.override_text_color = None; + }); + self.bg_color = catppuccin_egui::MACCHIATO.base; } Catppuccin::Mocha => { catppuccin_egui::set_theme(ctx, catppuccin_egui::MOCHA); - if let Some(catppuccin_value) = catppuccin_value { - let accent = match catppuccin_value { - CatppuccinValue::Rosewater => catppuccin_egui::MOCHA.rosewater, - CatppuccinValue::Flamingo => catppuccin_egui::MOCHA.flamingo, - CatppuccinValue::Pink => catppuccin_egui::MOCHA.pink, - CatppuccinValue::Mauve => catppuccin_egui::MOCHA.mauve, - CatppuccinValue::Red => catppuccin_egui::MOCHA.red, - CatppuccinValue::Maroon => catppuccin_egui::MOCHA.maroon, - CatppuccinValue::Peach => catppuccin_egui::MOCHA.peach, - CatppuccinValue::Yellow => catppuccin_egui::MOCHA.yellow, - CatppuccinValue::Green => catppuccin_egui::MOCHA.green, - CatppuccinValue::Teal => catppuccin_egui::MOCHA.teal, - CatppuccinValue::Sky => catppuccin_egui::MOCHA.sky, - CatppuccinValue::Sapphire => catppuccin_egui::MOCHA.sapphire, - CatppuccinValue::Blue => catppuccin_egui::MOCHA.blue, - CatppuccinValue::Lavender => catppuccin_egui::MOCHA.lavender, - CatppuccinValue::Text => catppuccin_egui::MOCHA.text, - CatppuccinValue::Subtext1 => catppuccin_egui::MOCHA.subtext1, - CatppuccinValue::Subtext0 => catppuccin_egui::MOCHA.subtext0, - CatppuccinValue::Overlay2 => catppuccin_egui::MOCHA.overlay2, - CatppuccinValue::Overlay1 => catppuccin_egui::MOCHA.overlay1, - CatppuccinValue::Overlay0 => catppuccin_egui::MOCHA.overlay0, - CatppuccinValue::Surface2 => catppuccin_egui::MOCHA.surface2, - CatppuccinValue::Surface1 => catppuccin_egui::MOCHA.surface1, - CatppuccinValue::Surface0 => catppuccin_egui::MOCHA.surface0, - CatppuccinValue::Base => catppuccin_egui::MOCHA.base, - CatppuccinValue::Mantle => catppuccin_egui::MOCHA.mantle, - CatppuccinValue::Crust => catppuccin_egui::MOCHA.crust, - }; - - ctx.style_mut(|style| { - style.visuals.selection.stroke.color = accent; - style.visuals.widgets.hovered.fg_stroke.color = accent; - style.visuals.widgets.active.fg_stroke.color = accent; - style.visuals.override_text_color = None; - }); - } + let catppuccin_value = catppuccin_value.unwrap_or_default(); + + let accent = match catppuccin_value { + CatppuccinValue::Rosewater => catppuccin_egui::MOCHA.rosewater, + CatppuccinValue::Flamingo => catppuccin_egui::MOCHA.flamingo, + CatppuccinValue::Pink => catppuccin_egui::MOCHA.pink, + CatppuccinValue::Mauve => catppuccin_egui::MOCHA.mauve, + CatppuccinValue::Red => catppuccin_egui::MOCHA.red, + CatppuccinValue::Maroon => catppuccin_egui::MOCHA.maroon, + CatppuccinValue::Peach => catppuccin_egui::MOCHA.peach, + CatppuccinValue::Yellow => catppuccin_egui::MOCHA.yellow, + CatppuccinValue::Green => catppuccin_egui::MOCHA.green, + CatppuccinValue::Teal => catppuccin_egui::MOCHA.teal, + CatppuccinValue::Sky => catppuccin_egui::MOCHA.sky, + CatppuccinValue::Sapphire => catppuccin_egui::MOCHA.sapphire, + CatppuccinValue::Blue => catppuccin_egui::MOCHA.blue, + CatppuccinValue::Lavender => catppuccin_egui::MOCHA.lavender, + CatppuccinValue::Text => catppuccin_egui::MOCHA.text, + CatppuccinValue::Subtext1 => catppuccin_egui::MOCHA.subtext1, + CatppuccinValue::Subtext0 => catppuccin_egui::MOCHA.subtext0, + CatppuccinValue::Overlay2 => catppuccin_egui::MOCHA.overlay2, + CatppuccinValue::Overlay1 => catppuccin_egui::MOCHA.overlay1, + CatppuccinValue::Overlay0 => catppuccin_egui::MOCHA.overlay0, + CatppuccinValue::Surface2 => catppuccin_egui::MOCHA.surface2, + CatppuccinValue::Surface1 => catppuccin_egui::MOCHA.surface1, + CatppuccinValue::Surface0 => catppuccin_egui::MOCHA.surface0, + CatppuccinValue::Base => catppuccin_egui::MOCHA.base, + CatppuccinValue::Mantle => catppuccin_egui::MOCHA.mantle, + CatppuccinValue::Crust => catppuccin_egui::MOCHA.crust, + }; + + ctx.style_mut(|style| { + style.visuals.selection.stroke.color = accent; + style.visuals.widgets.hovered.fg_stroke.color = accent; + style.visuals.widgets.active.fg_stroke.color = accent; + style.visuals.override_text_color = None; + }); + self.bg_color = catppuccin_egui::MOCHA.base; } }, @@ -227,32 +231,33 @@ impl Komobar { accent: base16_value, } => { ctx.set_style(base16.style()); - if let Some(base16_value) = base16_value { - let accent = match base16_value { - Base16Value::Base00 => base16.base00(), - Base16Value::Base01 => base16.base01(), - Base16Value::Base02 => base16.base02(), - Base16Value::Base03 => base16.base03(), - Base16Value::Base04 => base16.base04(), - Base16Value::Base05 => base16.base05(), - Base16Value::Base06 => base16.base06(), - Base16Value::Base07 => base16.base07(), - Base16Value::Base08 => base16.base08(), - Base16Value::Base09 => base16.base09(), - Base16Value::Base0A => base16.base0a(), - Base16Value::Base0B => base16.base0b(), - Base16Value::Base0C => base16.base0c(), - Base16Value::Base0D => base16.base0d(), - Base16Value::Base0E => base16.base0e(), - Base16Value::Base0F => base16.base0f(), - }; + let base16_value = base16_value.unwrap_or_default(); + + let accent = match base16_value { + Base16Value::Base00 => base16.base00(), + Base16Value::Base01 => base16.base01(), + Base16Value::Base02 => base16.base02(), + Base16Value::Base03 => base16.base03(), + Base16Value::Base04 => base16.base04(), + Base16Value::Base05 => base16.base05(), + Base16Value::Base06 => base16.base06(), + Base16Value::Base07 => base16.base07(), + Base16Value::Base08 => base16.base08(), + Base16Value::Base09 => base16.base09(), + Base16Value::Base0A => base16.base0a(), + Base16Value::Base0B => base16.base0b(), + Base16Value::Base0C => base16.base0c(), + Base16Value::Base0D => base16.base0d(), + Base16Value::Base0E => base16.base0e(), + Base16Value::Base0F => base16.base0f(), + }; + + ctx.style_mut(|style| { + style.visuals.selection.stroke.color = accent; + style.visuals.widgets.hovered.fg_stroke.color = accent; + style.visuals.widgets.active.fg_stroke.color = accent; + }); - ctx.style_mut(|style| { - style.visuals.selection.stroke.color = accent; - style.visuals.widgets.hovered.fg_stroke.color = accent; - style.visuals.widgets.active.fg_stroke.color = accent; - }); - } self.bg_color = base16.background(); } }, diff --git a/komorebi-bar/src/battery.rs b/komorebi-bar/src/battery.rs index 9c5820dc..3684102d 100644 --- a/komorebi-bar/src/battery.rs +++ b/komorebi-bar/src/battery.rs @@ -1,8 +1,12 @@ use crate::widget::BarWidget; use crate::WIDGET_SPACING; +use eframe::egui::text::LayoutJob; use eframe::egui::Context; +use eframe::egui::FontId; use eframe::egui::Label; use eframe::egui::Sense; +use eframe::egui::TextFormat; +use eframe::egui::TextStyle; use eframe::egui::Ui; use schemars::JsonSchema; use serde::Deserialize; @@ -24,7 +28,7 @@ pub struct BatteryConfig { impl From for Battery { fn from(value: BatteryConfig) -> Self { let manager = Manager::new().unwrap(); - let mut last_state = vec![]; + let mut last_state = String::new(); let mut state = None; if let Ok(mut batteries) = manager.batteries() { @@ -35,7 +39,8 @@ impl From for Battery { State::Discharging => state = Some(BatteryState::Discharging), _ => {} } - last_state.push(format!("{percentage}%")); + + last_state = format!("{percentage}%"); } } @@ -60,17 +65,17 @@ pub struct Battery { manager: Manager, pub state: BatteryState, data_refresh_interval: u64, - last_state: Vec, + last_state: String, last_updated: Instant, } impl Battery { - fn output(&mut self) -> Vec { - let mut outputs = self.last_state.clone(); + fn output(&mut self) -> String { + let mut output = self.last_state.clone(); let now = Instant::now(); if now.duration_since(self.last_updated) > Duration::from_secs(self.data_refresh_interval) { - outputs.clear(); + output.clear(); if let Ok(mut batteries) = self.manager.batteries() { if let Some(Ok(first)) = batteries.nth(0) { @@ -81,38 +86,56 @@ impl Battery { _ => {} } - outputs.push(format!("{percentage}%")); + output = format!("{percentage}%"); } } - self.last_state.clone_from(&outputs); + self.last_state.clone_from(&output); self.last_updated = now; } - outputs + output } } impl BarWidget for Battery { - fn render(&mut self, _ctx: &Context, ui: &mut Ui) { + fn render(&mut self, ctx: &Context, ui: &mut Ui) { if self.enable { let output = self.output(); if !output.is_empty() { - for battery in output { - let emoji = match self.state { - BatteryState::Charging => egui_phosphor::regular::BATTERY_CHARGING, - BatteryState::Discharging => egui_phosphor::regular::BATTERY_FULL, - }; - - ui.add( - Label::new(format!("{emoji} {battery}")) - .selectable(false) - .sense(Sense::click()), - ); - } + let emoji = match self.state { + BatteryState::Charging => egui_phosphor::regular::BATTERY_CHARGING, + BatteryState::Discharging => egui_phosphor::regular::BATTERY_FULL, + }; + + let font_id = ctx + .style() + .text_styles + .get(&TextStyle::Body) + .cloned() + .unwrap_or_else(FontId::default); - ui.add_space(WIDGET_SPACING); + let mut layout_job = LayoutJob::simple( + emoji.to_string(), + font_id.clone(), + ctx.style().visuals.selection.stroke.color, + 100.0, + ); + + layout_job.append( + &output, + 10.0, + TextFormat::simple(font_id, ctx.style().visuals.text_color()), + ); + + ui.add( + Label::new(layout_job) + .selectable(false) + .sense(Sense::click()), + ); } + + ui.add_space(WIDGET_SPACING); } } } diff --git a/komorebi-bar/src/date.rs b/komorebi-bar/src/date.rs index e159f77e..10ee1183 100644 --- a/komorebi-bar/src/date.rs +++ b/komorebi-bar/src/date.rs @@ -1,9 +1,14 @@ use crate::widget::BarWidget; use crate::WIDGET_SPACING; +use eframe::egui::text::LayoutJob; use eframe::egui::Context; +use eframe::egui::FontId; use eframe::egui::Label; use eframe::egui::Sense; +use eframe::egui::TextFormat; +use eframe::egui::TextStyle; use eframe::egui::Ui; +use eframe::egui::WidgetText; use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; @@ -68,26 +73,43 @@ pub struct Date { } impl Date { - fn output(&mut self) -> Vec { - vec![chrono::Local::now() + fn output(&mut self) -> String { + chrono::Local::now() .format(&self.format.fmt_string()) - .to_string()] + .to_string() } } impl BarWidget for Date { - fn render(&mut self, _ctx: &Context, ui: &mut Ui) { + fn render(&mut self, ctx: &Context, ui: &mut Ui) { if self.enable { - for output in self.output() { + let output = self.output(); + if !output.is_empty() { + let font_id = ctx + .style() + .text_styles + .get(&TextStyle::Body) + .cloned() + .unwrap_or_else(FontId::default); + + let mut layout_job = LayoutJob::simple( + egui_phosphor::regular::CALENDAR_DOTS.to_string(), + font_id.clone(), + ctx.style().visuals.selection.stroke.color, + 100.0, + ); + + layout_job.append( + &output, + 10.0, + TextFormat::simple(font_id, ctx.style().visuals.text_color()), + ); + if ui .add( - Label::new(format!( - "{} {}", - egui_phosphor::regular::CALENDAR_DOTS, - output - )) - .selectable(false) - .sense(Sense::click()), + Label::new(WidgetText::LayoutJob(layout_job.clone())) + .selectable(false) + .sense(Sense::click()), ) .clicked() { diff --git a/komorebi-bar/src/main.rs b/komorebi-bar/src/main.rs index 7762f5b4..afbb26d1 100644 --- a/komorebi-bar/src/main.rs +++ b/komorebi-bar/src/main.rs @@ -183,8 +183,8 @@ fn main() -> color_eyre::Result<()> { let config_path_cl = config_path.clone(); hotwatch.watch(config_path, move |event| match event.kind { - EventKind::Modify(_) | EventKind::Remove(_) => { - if let Ok(updated) = KomobarConfig::read(&config_path_cl) { + EventKind::Modify(_) | EventKind::Remove(_) => match KomobarConfig::read(&config_path_cl) { + Ok(updated) => { tx_config.send(updated).unwrap(); tracing::info!( @@ -192,7 +192,10 @@ fn main() -> color_eyre::Result<()> { config_path_cl.as_path().to_string_lossy() ); } - } + Err(error) => { + tracing::error!("{error}"); + } + }, _ => {} })?; diff --git a/komorebi-bar/src/media.rs b/komorebi-bar/src/media.rs index 8b6bbc2b..b2e3d703 100644 --- a/komorebi-bar/src/media.rs +++ b/komorebi-bar/src/media.rs @@ -1,8 +1,12 @@ use crate::widget::BarWidget; use crate::WIDGET_SPACING; +use eframe::egui::text::LayoutJob; use eframe::egui::Context; +use eframe::egui::FontId; use eframe::egui::Label; use eframe::egui::Sense; +use eframe::egui::TextFormat; +use eframe::egui::TextStyle; use eframe::egui::Ui; use schemars::JsonSchema; use serde::Deserialize; @@ -46,36 +50,57 @@ impl Media { } } - fn output(&mut self) -> Vec { + fn output(&mut self) -> String { if let Ok(session) = self.session_manager.GetCurrentSession() { if let Ok(operation) = session.TryGetMediaPropertiesAsync() { if let Ok(properties) = operation.get() { if let (Ok(artist), Ok(title)) = (properties.Artist(), properties.Title()) { if artist.is_empty() { - return vec![format!("{title}")]; + return format!("{title}"); } if title.is_empty() { - return vec![format!("{artist}")]; + return format!("{artist}"); } - return vec![format!("{artist} - {title}")]; + return format!("{artist} - {title}"); } } } } - vec![] + String::new() } } impl BarWidget for Media { - fn render(&mut self, _ctx: &Context, ui: &mut Ui) { + fn render(&mut self, ctx: &Context, ui: &mut Ui) { if self.enable { - for output in self.output() { + let output = self.output(); + if !output.is_empty() { + let font_id = ctx + .style() + .text_styles + .get(&TextStyle::Body) + .cloned() + .unwrap_or_else(FontId::default); + + let mut layout_job = LayoutJob::simple( + egui_phosphor::regular::HEADPHONES.to_string(), + font_id.clone(), + ctx.style().visuals.selection.stroke.color, + 100.0, + ); + + layout_job.append( + &output, + 10.0, + TextFormat::simple(font_id, ctx.style().visuals.text_color()), + ); + if ui .add( - Label::new(format!("{} {output}", egui_phosphor::regular::HEADPHONES)) + Label::new(layout_job) .selectable(false) .sense(Sense::click()), ) diff --git a/komorebi-bar/src/memory.rs b/komorebi-bar/src/memory.rs index 4e887502..308f3211 100644 --- a/komorebi-bar/src/memory.rs +++ b/komorebi-bar/src/memory.rs @@ -1,8 +1,12 @@ use crate::widget::BarWidget; use crate::WIDGET_SPACING; +use eframe::egui::text::LayoutJob; use eframe::egui::Context; +use eframe::egui::FontId; use eframe::egui::Label; use eframe::egui::Sense; +use eframe::egui::TextFormat; +use eframe::egui::TextStyle; use eframe::egui::Ui; use schemars::JsonSchema; use serde::Deserialize; @@ -45,7 +49,7 @@ pub struct Memory { } impl Memory { - fn output(&mut self) -> Vec { + fn output(&mut self) -> String { let now = Instant::now(); if now.duration_since(self.last_updated) > Duration::from_secs(self.data_refresh_interval) { self.system.refresh_memory(); @@ -54,17 +58,38 @@ impl Memory { let used = self.system.used_memory(); let total = self.system.total_memory(); - vec![format!("RAM: {}%", (used * 100) / total)] + format!("RAM: {}%", (used * 100) / total) } } impl BarWidget for Memory { - fn render(&mut self, _ctx: &Context, ui: &mut Ui) { + fn render(&mut self, ctx: &Context, ui: &mut Ui) { if self.enable { - for output in self.output() { + let output = self.output(); + if !output.is_empty() { + let font_id = ctx + .style() + .text_styles + .get(&TextStyle::Body) + .cloned() + .unwrap_or_else(FontId::default); + + let mut layout_job = LayoutJob::simple( + egui_phosphor::regular::MEMORY.to_string(), + font_id.clone(), + ctx.style().visuals.selection.stroke.color, + 100.0, + ); + + layout_job.append( + &output, + 10.0, + TextFormat::simple(font_id, ctx.style().visuals.text_color()), + ); + if ui .add( - Label::new(format!("{} {}", egui_phosphor::regular::MEMORY, output)) + Label::new(layout_job) .selectable(false) .sense(Sense::click()), ) diff --git a/komorebi-bar/src/network.rs b/komorebi-bar/src/network.rs index 0bd0b692..910b5f7b 100644 --- a/komorebi-bar/src/network.rs +++ b/komorebi-bar/src/network.rs @@ -1,8 +1,12 @@ use crate::widget::BarWidget; use crate::WIDGET_SPACING; +use eframe::egui::text::LayoutJob; use eframe::egui::Context; +use eframe::egui::FontId; use eframe::egui::Label; use eframe::egui::Sense; +use eframe::egui::TextFormat; +use eframe::egui::TextStyle; use eframe::egui::Ui; use num_derive::FromPrimitive; use schemars::JsonSchema; @@ -194,7 +198,7 @@ impl Network { } impl BarWidget for Network { - fn render(&mut self, _ctx: &Context, ui: &mut Ui) { + fn render(&mut self, ctx: &Context, ui: &mut Ui) { if self.show_total_data_transmitted { for output in self.total_data_transmitted() { ui.add(Label::new(output).selectable(false)); @@ -214,21 +218,38 @@ impl BarWidget for Network { if self.enable { self.default_interface(); - if !self.default_interface.is_empty() - && ui + if !self.default_interface.is_empty() { + let font_id = ctx + .style() + .text_styles + .get(&TextStyle::Body) + .cloned() + .unwrap_or_else(FontId::default); + + let mut layout_job = LayoutJob::simple( + egui_phosphor::regular::WIFI_HIGH.to_string(), + font_id.clone(), + ctx.style().visuals.selection.stroke.color, + 100.0, + ); + + layout_job.append( + &self.default_interface, + 10.0, + TextFormat::simple(font_id, ctx.style().visuals.text_color()), + ); + + if ui .add( - Label::new(format!( - "{} {}", - egui_phosphor::regular::WIFI_HIGH, - self.default_interface - )) - .selectable(false) - .sense(Sense::click()), + Label::new(layout_job) + .selectable(false) + .sense(Sense::click()), ) .clicked() - { - if let Err(error) = Command::new("cmd.exe").args(["/C", "ncpa"]).spawn() { - eprintln!("{}", error) + { + if let Err(error) = Command::new("cmd.exe").args(["/C", "ncpa"]).spawn() { + eprintln!("{}", error) + } } } diff --git a/komorebi-bar/src/storage.rs b/komorebi-bar/src/storage.rs index 30d5eb27..f2d9e1e1 100644 --- a/komorebi-bar/src/storage.rs +++ b/komorebi-bar/src/storage.rs @@ -1,8 +1,12 @@ use crate::widget::BarWidget; use crate::WIDGET_SPACING; +use eframe::egui::text::LayoutJob; use eframe::egui::Context; +use eframe::egui::FontId; use eframe::egui::Label; use eframe::egui::Sense; +use eframe::egui::TextFormat; +use eframe::egui::TextStyle; use eframe::egui::Ui; use schemars::JsonSchema; use serde::Deserialize; @@ -69,18 +73,34 @@ impl Storage { } impl BarWidget for Storage { - fn render(&mut self, _ctx: &Context, ui: &mut Ui) { + fn render(&mut self, ctx: &Context, ui: &mut Ui) { if self.enable { + let font_id = ctx + .style() + .text_styles + .get(&TextStyle::Body) + .cloned() + .unwrap_or_else(FontId::default); + for output in self.output() { + let mut layout_job = LayoutJob::simple( + egui_phosphor::regular::HARD_DRIVES.to_string(), + font_id.clone(), + ctx.style().visuals.selection.stroke.color, + 100.0, + ); + + layout_job.append( + &output, + 10.0, + TextFormat::simple(font_id.clone(), ctx.style().visuals.text_color()), + ); + if ui .add( - Label::new(format!( - "{} {}", - egui_phosphor::regular::HARD_DRIVES, - output - )) - .selectable(false) - .sense(Sense::click()), + Label::new(layout_job) + .selectable(false) + .sense(Sense::click()), ) .clicked() { diff --git a/komorebi-bar/src/time.rs b/komorebi-bar/src/time.rs index a290d15d..321c25ec 100644 --- a/komorebi-bar/src/time.rs +++ b/komorebi-bar/src/time.rs @@ -1,8 +1,12 @@ use crate::widget::BarWidget; use crate::WIDGET_SPACING; +use eframe::egui::text::LayoutJob; use eframe::egui::Context; +use eframe::egui::FontId; use eframe::egui::Label; use eframe::egui::Sense; +use eframe::egui::TextFormat; +use eframe::egui::TextStyle; use eframe::egui::Ui; use schemars::JsonSchema; use serde::Deserialize; @@ -60,20 +64,41 @@ pub struct Time { } impl Time { - fn output(&mut self) -> Vec { - vec![chrono::Local::now() + fn output(&mut self) -> String { + chrono::Local::now() .format(&self.format.fmt_string()) - .to_string()] + .to_string() } } impl BarWidget for Time { - fn render(&mut self, _ctx: &Context, ui: &mut Ui) { + fn render(&mut self, ctx: &Context, ui: &mut Ui) { if self.enable { - for output in self.output() { + let output = self.output(); + if !output.is_empty() { + let font_id = ctx + .style() + .text_styles + .get(&TextStyle::Body) + .cloned() + .unwrap_or_else(FontId::default); + + let mut layout_job = LayoutJob::simple( + egui_phosphor::regular::CLOCK.to_string(), + font_id.clone(), + ctx.style().visuals.selection.stroke.color, + 100.0, + ); + + layout_job.append( + &output, + 10.0, + TextFormat::simple(font_id, ctx.style().visuals.text_color()), + ); + if ui .add( - Label::new(format!("{} {}", egui_phosphor::regular::CLOCK, output)) + Label::new(layout_job) .selectable(false) .sense(Sense::click()), )