Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bar): added icon_scale to the config #1189

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions komorebi-bar/src/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,11 @@ impl Komobar {
Self::set_font_size(ctx, *font_size);
}

self.render_config
.replace(config.new_renderconfig(ctx, *self.bg_color.borrow()));
self.render_config.replace(config.new_renderconfig(
ctx,
*self.bg_color.borrow(),
config.icon_scale,
));

let mut komorebi_notification_state = previous_notification_state;
let mut komorebi_widgets = Vec::new();
Expand Down
2 changes: 2 additions & 0 deletions komorebi-bar/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub struct KomobarConfig {
pub font_family: Option<String>,
/// Font size (default: 12.5)
pub font_size: Option<f32>,
/// Scale of the icons relative to the font_size [[1.0-2.0]]. (default: 1.4)
pub icon_scale: Option<f32>,
/// Max label width before text truncation (default: 400.0)
pub max_label_width: Option<f32>,
/// Theme
Expand Down
16 changes: 13 additions & 3 deletions komorebi-bar/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,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<f32>,
) -> 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<f32>,
) -> RenderConfig {
let text_font_id = ctx
.style()
.text_styles
Expand All @@ -69,7 +79,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,
Expand Down