From 46eb00955a545141b9bb5ef0476883cefbbb2a55 Mon Sep 17 00:00:00 2001 From: Csaba Date: Wed, 18 Dec 2024 11:13:12 +0100 Subject: [PATCH] feat(bar): added icon_scale to the config allowing a custom value between 1.0 and 2.0 --- komorebi-bar/src/bar.rs | 2 +- komorebi-bar/src/config.rs | 2 ++ komorebi-bar/src/render.rs | 16 +++++++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/komorebi-bar/src/bar.rs b/komorebi-bar/src/bar.rs index e1f14f2b..4521a7fa 100644 --- a/komorebi-bar/src/bar.rs +++ b/komorebi-bar/src/bar.rs @@ -279,7 +279,7 @@ impl Komobar { } self.render_config - .replace(config.new_renderconfig(ctx, theme_color)); + .replace(config.new_renderconfig(ctx, theme_color, config.icon_scale)); let mut komorebi_notification_state = previous_notification_state; let mut komorebi_widgets = Vec::new(); diff --git a/komorebi-bar/src/config.rs b/komorebi-bar/src/config.rs index 7a9ac9dc..d6ff6597 100644 --- a/komorebi-bar/src/config.rs +++ b/komorebi-bar/src/config.rs @@ -25,6 +25,8 @@ pub struct KomobarConfig { pub font_family: Option, /// Font size (default: 12.5) pub font_size: Option, + /// Scale of the icons relative to the font_size [[1.0-2.0]]. (default: 1.4) + pub icon_scale: Option, /// Max label width before text truncation (default: 400.0) pub max_label_width: Option, /// Theme diff --git a/komorebi-bar/src/render.rs b/komorebi-bar/src/render.rs index bc12705f..ace4b748 100644 --- a/komorebi-bar/src/render.rs +++ b/komorebi-bar/src/render.rs @@ -55,11 +55,21 @@ pub struct RenderConfig { } pub trait RenderExt { - fn new_renderconfig(&self, ctx: &Context, background_color: Color32) -> RenderConfig; + fn new_renderconfig( + &self, + ctx: &Context, + background_color: Color32, + icon_scale: Option, + ) -> RenderConfig; } impl RenderExt for &KomobarConfig { - fn new_renderconfig(&self, ctx: &Context, background_color: Color32) -> RenderConfig { + fn new_renderconfig( + &self, + ctx: &Context, + background_color: Color32, + icon_scale: Option, + ) -> RenderConfig { let text_font_id = ctx .style() .text_styles @@ -68,7 +78,7 @@ impl RenderExt for &KomobarConfig { .unwrap_or_else(FontId::default); let mut icon_font_id = text_font_id.clone(); - icon_font_id.size *= 1.4; + icon_font_id.size *= icon_scale.unwrap_or(1.4).clamp(1.0, 2.0); RenderConfig { monitor_idx: self.monitor.index,