mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-24 17:48:34 +02:00
feat(themes): add + integrate komorebi-themes lib
This commit abstracts the theme-related code from komorebi-bar into a separate library which is now also consumed by komorebi. The static configuration file for komorebi has been updated to allow users to specify themes and provide palette overrides for various border styles and stackbar configuration options. In the event that both a theme and border-specific and/or stackbar-specific colours have been specified, the theme will take priority to make it as easy as possible for users who have already spent time tweaking their colours to try out themes and quickly revert back if they prefer their existing colours. This change makes it easier for users to have unified themes between komorebi and the komorebi status bar.
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
use crate::config::Base16Value;
|
||||
use crate::config::Catppuccin;
|
||||
use crate::config::CatppuccinValue;
|
||||
use crate::config::KomobarConfig;
|
||||
use crate::config::Theme;
|
||||
use crate::config::KomobarTheme;
|
||||
use crate::komorebi::Komorebi;
|
||||
use crate::komorebi::KomorebiNotificationState;
|
||||
use crate::widget::BarWidget;
|
||||
@@ -21,6 +18,8 @@ use eframe::egui::Margin;
|
||||
use eframe::egui::Style;
|
||||
use font_loader::system_fonts;
|
||||
use font_loader::system_fonts::FontPropertyBuilder;
|
||||
use komorebi_themes::catppuccin_egui;
|
||||
use komorebi_themes::Catppuccin;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
@@ -53,42 +52,14 @@ impl Komobar {
|
||||
self.bg_color = Style::default().visuals.panel_fill;
|
||||
}
|
||||
Some(theme) => match theme {
|
||||
Theme::Catppuccin {
|
||||
KomobarTheme::Catppuccin {
|
||||
name: catppuccin,
|
||||
accent: catppuccin_value,
|
||||
} => match catppuccin {
|
||||
Catppuccin::Frappe => {
|
||||
catppuccin_egui::set_theme(ctx, catppuccin_egui::FRAPPE);
|
||||
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,
|
||||
};
|
||||
let accent = catppuccin_value.color32(catppuccin.as_theme());
|
||||
|
||||
ctx.style_mut(|style| {
|
||||
style.visuals.selection.stroke.color = accent;
|
||||
@@ -102,35 +73,7 @@ impl Komobar {
|
||||
Catppuccin::Latte => {
|
||||
catppuccin_egui::set_theme(ctx, catppuccin_egui::LATTE);
|
||||
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,
|
||||
};
|
||||
let accent = catppuccin_value.color32(catppuccin.as_theme());
|
||||
|
||||
ctx.style_mut(|style| {
|
||||
style.visuals.selection.stroke.color = accent;
|
||||
@@ -144,35 +87,7 @@ impl Komobar {
|
||||
Catppuccin::Macchiato => {
|
||||
catppuccin_egui::set_theme(ctx, catppuccin_egui::MACCHIATO);
|
||||
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,
|
||||
};
|
||||
let accent = catppuccin_value.color32(catppuccin.as_theme());
|
||||
|
||||
ctx.style_mut(|style| {
|
||||
style.visuals.selection.stroke.color = accent;
|
||||
@@ -186,35 +101,7 @@ impl Komobar {
|
||||
Catppuccin::Mocha => {
|
||||
catppuccin_egui::set_theme(ctx, catppuccin_egui::MOCHA);
|
||||
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,
|
||||
};
|
||||
let accent = catppuccin_value.color32(catppuccin.as_theme());
|
||||
|
||||
ctx.style_mut(|style| {
|
||||
style.visuals.selection.stroke.color = accent;
|
||||
@@ -226,31 +113,13 @@ impl Komobar {
|
||||
self.bg_color = catppuccin_egui::MOCHA.base;
|
||||
}
|
||||
},
|
||||
Theme::Base16 {
|
||||
KomobarTheme::Base16 {
|
||||
name: base16,
|
||||
accent: base16_value,
|
||||
} => {
|
||||
ctx.set_style(base16.style());
|
||||
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(),
|
||||
};
|
||||
let accent = base16_value.color32(base16);
|
||||
|
||||
ctx.style_mut(|style| {
|
||||
style.visuals.selection.stroke.color = accent;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use crate::widget::WidgetConfig;
|
||||
use base16_egui_themes::Base16;
|
||||
use eframe::egui::Pos2;
|
||||
use eframe::egui::TextBuffer;
|
||||
use eframe::egui::Vec2;
|
||||
@@ -20,7 +19,7 @@ pub struct KomobarConfig {
|
||||
/// Font family
|
||||
pub font_family: Option<String>,
|
||||
/// Theme
|
||||
pub theme: Option<Theme>,
|
||||
pub theme: Option<KomobarTheme>,
|
||||
/// Left side widgets (ordered left-to-right)
|
||||
pub left_widgets: Vec<WidgetConfig>,
|
||||
/// Right side widgets (ordered left-to-right)
|
||||
@@ -96,75 +95,15 @@ impl From<Position> for Pos2 {
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(tag = "type")]
|
||||
pub enum Theme {
|
||||
pub enum KomobarTheme {
|
||||
/// A theme from catppuccin-egui
|
||||
Catppuccin {
|
||||
name: Catppuccin,
|
||||
accent: Option<CatppuccinValue>,
|
||||
name: komorebi_themes::Catppuccin,
|
||||
accent: Option<komorebi_themes::CatppuccinValue>,
|
||||
},
|
||||
/// A theme from base16-egui-themes
|
||||
Base16 {
|
||||
name: Base16,
|
||||
accent: Option<Base16Value>,
|
||||
name: komorebi_themes::Base16,
|
||||
accent: Option<komorebi_themes::Base16Value>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
||||
pub enum Base16Value {
|
||||
Base00,
|
||||
Base01,
|
||||
Base02,
|
||||
Base03,
|
||||
Base04,
|
||||
Base05,
|
||||
#[default]
|
||||
Base06,
|
||||
Base07,
|
||||
Base08,
|
||||
Base09,
|
||||
Base0A,
|
||||
Base0B,
|
||||
Base0C,
|
||||
Base0D,
|
||||
Base0E,
|
||||
Base0F,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
||||
pub enum Catppuccin {
|
||||
Frappe,
|
||||
Latte,
|
||||
Macchiato,
|
||||
Mocha,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
||||
pub enum CatppuccinValue {
|
||||
Rosewater,
|
||||
Flamingo,
|
||||
Pink,
|
||||
Mauve,
|
||||
Red,
|
||||
Maroon,
|
||||
Peach,
|
||||
Yellow,
|
||||
Green,
|
||||
Teal,
|
||||
Sky,
|
||||
Sapphire,
|
||||
Blue,
|
||||
Lavender,
|
||||
#[default]
|
||||
Text,
|
||||
Subtext1,
|
||||
Subtext0,
|
||||
Overlay2,
|
||||
Overlay1,
|
||||
Overlay0,
|
||||
Surface2,
|
||||
Surface1,
|
||||
Surface0,
|
||||
Base,
|
||||
Mantle,
|
||||
Crust,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user