feat(bar): expand theme sources

This commit is contained in:
LGUG2Z
2024-09-13 16:00:37 -07:00
parent d77944a581
commit 632b1887dd
6 changed files with 388 additions and 64 deletions
+37 -19
View File
@@ -1,3 +1,4 @@
use crate::config::Catppuccin;
use crate::config::KomobarConfig;
use crate::config::Theme;
use crate::komorebi::Komorebi;
@@ -7,6 +8,7 @@ use crate::widget::WidgetConfig;
use crossbeam_channel::Receiver;
use eframe::egui::Align;
use eframe::egui::CentralPanel;
use eframe::egui::Color32;
use eframe::egui::Context;
use eframe::egui::FontData;
use eframe::egui::FontDefinitions;
@@ -28,6 +30,7 @@ pub struct Komobar {
pub right_widgets: Vec<Box<dyn BarWidget>>,
pub rx_gui: Receiver<komorebi_client::Notification>,
pub rx_config: Receiver<KomobarConfig>,
pub bg_color: Color32,
}
impl Komobar {
@@ -43,22 +46,34 @@ impl Komobar {
}
match config.theme {
Some(Theme::CatppuccinFrappe) => {
catppuccin_egui::set_theme(ctx, catppuccin_egui::FRAPPE);
tracing::info!("theme updated: Catppuccin Frappe");
}
Some(Theme::CatppuccinMacchiato) => {
catppuccin_egui::set_theme(ctx, catppuccin_egui::MACCHIATO);
tracing::info!("theme updated: Catppuccin Macchiato");
}
Some(Theme::CatppuccinMocha) => {
catppuccin_egui::set_theme(ctx, catppuccin_egui::MOCHA);
tracing::info!("theme updated: Catppuccin Mocha");
}
Some(Theme::Default) | None => {
None => {
ctx.set_style(Style::default());
tracing::info!("theme updated: Egui Default");
self.bg_color = Style::default().visuals.panel_fill;
}
Some(theme) => match theme {
Theme::Catppuccin { name: catppuccin } => match catppuccin {
Catppuccin::Frappe => {
catppuccin_egui::set_theme(ctx, catppuccin_egui::FRAPPE);
self.bg_color = catppuccin_egui::FRAPPE.base;
}
Catppuccin::Latte => {
catppuccin_egui::set_theme(ctx, catppuccin_egui::LATTE);
self.bg_color = catppuccin_egui::LATTE.base;
}
Catppuccin::Macchiato => {
catppuccin_egui::set_theme(ctx, catppuccin_egui::MACCHIATO);
self.bg_color = catppuccin_egui::MACCHIATO.base;
}
Catppuccin::Mocha => {
catppuccin_egui::set_theme(ctx, catppuccin_egui::MOCHA);
self.bg_color = catppuccin_egui::MOCHA.base;
}
},
Theme::Base16 { name: base16 } => {
ctx.set_style(base16.style());
self.bg_color = base16.background();
}
},
}
let mut komorebi_widget = None;
@@ -139,6 +154,7 @@ impl Komobar {
right_widgets: vec![],
rx_gui,
rx_config,
bg_color: Style::default().visuals.panel_fill,
};
komobar.apply_config(&cc.egui_ctx, &config, None);
@@ -199,12 +215,14 @@ impl eframe::App for Komobar {
}
let frame = if let Some(frame) = &self.config.frame {
Frame::none().outer_margin(Margin::symmetric(
frame.outer_margin.x,
frame.outer_margin.y,
))
} else {
Frame::none()
.inner_margin(Margin::symmetric(
frame.inner_margin.x,
frame.inner_margin.y,
))
.fill(self.bg_color)
} else {
Frame::none().fill(self.bg_color)
};
CentralPanel::default().frame(frame).show(ctx, |ui| {
+17 -11
View File
@@ -1,4 +1,5 @@
use crate::widget::WidgetConfig;
use base16_egui_themes::Base16;
use eframe::egui::Pos2;
use eframe::egui::TextBuffer;
use eframe::egui::Vec2;
@@ -36,8 +37,8 @@ pub struct ViewportConfig {
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct FrameConfig {
/// Margin outside the painted frame
pub outer_margin: Position,
/// Margin inside the painted frame
pub inner_margin: Position,
}
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
@@ -59,7 +60,7 @@ impl KomobarConfig {
if value.frame.is_none() {
value.frame = Some(FrameConfig {
outer_margin: Position { x: 10.0, y: 10.0 },
inner_margin: Position { x: 10.0, y: 10.0 },
});
}
@@ -94,13 +95,18 @@ impl From<Position> for Pos2 {
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
#[serde(tag = "type")]
pub enum Theme {
/// Default egui theme
Default,
/// Catpuccin Frappe
CatppuccinFrappe,
/// Catpuccin Macchiato
CatppuccinMacchiato,
/// Catpuccin Mocha
CatppuccinMocha,
/// A theme from catppuccin-egui
Catppuccin { name: Catppuccin },
/// A theme from base16-egui-themes
Base16 { name: Base16 },
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub enum Catppuccin {
Frappe,
Latte,
Macchiato,
Mocha,
}
+7 -6
View File
@@ -184,13 +184,14 @@ fn main() -> color_eyre::Result<()> {
hotwatch.watch(config_path, move |event| match event.kind {
EventKind::Modify(_) | EventKind::Remove(_) => {
let updated = KomobarConfig::read(&config_path_cl).unwrap();
tx_config.send(updated).unwrap();
if let Ok(updated) = KomobarConfig::read(&config_path_cl) {
tx_config.send(updated).unwrap();
tracing::info!(
"configuration file updated: {}",
config_path_cl.as_path().to_string_lossy()
);
tracing::info!(
"configuration file updated: {}",
config_path_cl.as_path().to_string_lossy()
);
}
}
_ => {}
})?;