Skip to content

Commit

Permalink
feat(bar): add font size config opt
Browse files Browse the repository at this point in the history
  • Loading branch information
LGUG2Z committed Sep 19, 2024
1 parent 50b89cc commit 14d2ebd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
6 changes: 3 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ docgen:
Get-ChildItem -Path "docs/cli" -Recurse -File | ForEach-Object { (Get-Content $_.FullName) -replace 'Usage: ', 'Usage: komorebic.exe ' | Set-Content $_.FullName }

schemagen:
komorebic static-config-schema > schema.json
komorebic application-specific-configuration-schema > schema.asc.json
komorebi-bar --schema > schema.bar.json
cargo run --package komorebic -- static-config-schema > schema.json
cargo run --package komorebic -- application-specific-configuration-schema > schema.asc.json
cargo run --package komorebi-bar -- --schema > schema.bar.json
generate-schema-doc .\schema.json --config template_name=js_offline --config minify=false .\static-config-docs\
32 changes: 32 additions & 0 deletions komorebi-bar/src/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ use eframe::egui::Context;
use eframe::egui::FontData;
use eframe::egui::FontDefinitions;
use eframe::egui::FontFamily;
use eframe::egui::FontId;
use eframe::egui::Frame;
use eframe::egui::Layout;
use eframe::egui::Margin;
use eframe::egui::Style;
use eframe::egui::TextStyle;
use eframe::egui::Vec2;
use eframe::egui::ViewportCommand;
use font_loader::system_fonts;
Expand Down Expand Up @@ -176,6 +178,11 @@ impl Komobar {
}
}

if let Some(font_size) = &config.font_size {
tracing::info!("attempting to set custom font size: {font_size}");
Self::set_font_size(ctx, *font_size);
}

let mut komorebi_widget = None;
let mut komorebi_widget_idx = None;
let mut komorebi_notification_state = previous_notification_state;
Expand Down Expand Up @@ -263,6 +270,31 @@ impl Komobar {
komobar
}

fn set_font_size(ctx: &Context, font_size: f32) {
ctx.style_mut(|style| {
style.text_styles = [
(TextStyle::Small, FontId::new(9.0, FontFamily::Proportional)),
(
TextStyle::Body,
FontId::new(font_size, FontFamily::Proportional),
),
(
TextStyle::Button,
FontId::new(font_size, FontFamily::Proportional),
),
(
TextStyle::Heading,
FontId::new(18.0, FontFamily::Proportional),
),
(
TextStyle::Monospace,
FontId::new(font_size, FontFamily::Monospace),
),
]
.into();
});
}

fn add_custom_font(ctx: &Context, name: &str) {
let mut fonts = FontDefinitions::default();
egui_phosphor::add_to_fonts(&mut fonts, egui_phosphor::Variant::Regular);
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 @@ -19,6 +19,8 @@ pub struct KomobarConfig {
pub monitor: MonitorConfig,
/// Font family
pub font_family: Option<String>,
/// Font size (default: 12.5)
pub font_size: Option<f32>,
/// Theme
pub theme: Option<KomobarTheme>,
/// Left side widgets (ordered left-to-right)
Expand Down
5 changes: 5 additions & 0 deletions schema.bar.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"description": "Font family",
"type": "string"
},
"font_size": {
"description": "Font size (default: 12.5)",
"type": "number",
"format": "float"
},
"frame": {
"description": "Frame options (see: https://docs.rs/egui/latest/egui/containers/struct.Frame.html)",
"type": "object",
Expand Down

0 comments on commit 14d2ebd

Please sign in to comment.