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

11
Cargo.lock generated
View File

@@ -596,6 +596,16 @@ dependencies = [
"backtrace", "backtrace",
] ]
[[package]]
name = "base16-egui-themes"
version = "0.1.0"
source = "git+https://github.com/LGUG2Z/base16-egui-themes#b4afb9aa0104b6100d6be52b9fb2abb349a5de1e"
dependencies = [
"egui",
"schemars",
"serde",
]
[[package]] [[package]]
name = "base64" name = "base64"
version = "0.22.1" version = "0.22.1"
@@ -2677,6 +2687,7 @@ dependencies = [
name = "komorebi-bar" name = "komorebi-bar"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"base16-egui-themes",
"catppuccin-egui", "catppuccin-egui",
"chrono", "chrono",
"clap", "clap",

View File

@@ -8,6 +8,7 @@ edition = "2021"
[dependencies] [dependencies]
komorebi-client = { path = "../komorebi-client" } komorebi-client = { path = "../komorebi-client" }
base16-egui-themes = { git = "https://github.com/LGUG2Z/base16-egui-themes" }
catppuccin-egui = { version = "5.1", default-features = false, features = ["egui28"] } catppuccin-egui = { version = "5.1", default-features = false, features = ["egui28"] }
chrono = "0.4" chrono = "0.4"
clap = { version = "4", features = ["derive", "wrap_help"] } clap = { version = "4", features = ["derive", "wrap_help"] }
@@ -33,4 +34,4 @@ tracing = "0.1"
tracing-appender = "0.2" tracing-appender = "0.2"
tracing-subscriber = { version = "0.3", features = ["env-filter"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] }
windows = { workspace = true } windows = { workspace = true }
windows-icons = "0.1" windows-icons = "0.1"

View File

@@ -1,3 +1,4 @@
use crate::config::Catppuccin;
use crate::config::KomobarConfig; use crate::config::KomobarConfig;
use crate::config::Theme; use crate::config::Theme;
use crate::komorebi::Komorebi; use crate::komorebi::Komorebi;
@@ -7,6 +8,7 @@ use crate::widget::WidgetConfig;
use crossbeam_channel::Receiver; use crossbeam_channel::Receiver;
use eframe::egui::Align; use eframe::egui::Align;
use eframe::egui::CentralPanel; use eframe::egui::CentralPanel;
use eframe::egui::Color32;
use eframe::egui::Context; use eframe::egui::Context;
use eframe::egui::FontData; use eframe::egui::FontData;
use eframe::egui::FontDefinitions; use eframe::egui::FontDefinitions;
@@ -28,6 +30,7 @@ pub struct Komobar {
pub right_widgets: Vec<Box<dyn BarWidget>>, pub right_widgets: Vec<Box<dyn BarWidget>>,
pub rx_gui: Receiver<komorebi_client::Notification>, pub rx_gui: Receiver<komorebi_client::Notification>,
pub rx_config: Receiver<KomobarConfig>, pub rx_config: Receiver<KomobarConfig>,
pub bg_color: Color32,
} }
impl Komobar { impl Komobar {
@@ -43,22 +46,34 @@ impl Komobar {
} }
match config.theme { match config.theme {
Some(Theme::CatppuccinFrappe) => { None => {
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 => {
ctx.set_style(Style::default()); 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; let mut komorebi_widget = None;
@@ -139,6 +154,7 @@ impl Komobar {
right_widgets: vec![], right_widgets: vec![],
rx_gui, rx_gui,
rx_config, rx_config,
bg_color: Style::default().visuals.panel_fill,
}; };
komobar.apply_config(&cc.egui_ctx, &config, None); 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 { 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() 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| { CentralPanel::default().frame(frame).show(ctx, |ui| {

View File

@@ -1,4 +1,5 @@
use crate::widget::WidgetConfig; use crate::widget::WidgetConfig;
use base16_egui_themes::Base16;
use eframe::egui::Pos2; use eframe::egui::Pos2;
use eframe::egui::TextBuffer; use eframe::egui::TextBuffer;
use eframe::egui::Vec2; use eframe::egui::Vec2;
@@ -36,8 +37,8 @@ pub struct ViewportConfig {
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct FrameConfig { pub struct FrameConfig {
/// Margin outside the painted frame /// Margin inside the painted frame
pub outer_margin: Position, pub inner_margin: Position,
} }
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
@@ -59,7 +60,7 @@ impl KomobarConfig {
if value.frame.is_none() { if value.frame.is_none() {
value.frame = Some(FrameConfig { 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)] #[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
#[serde(tag = "type")]
pub enum Theme { pub enum Theme {
/// Default egui theme /// A theme from catppuccin-egui
Default, Catppuccin { name: Catppuccin },
/// Catpuccin Frappe /// A theme from base16-egui-themes
CatppuccinFrappe, Base16 { name: Base16 },
/// Catpuccin Macchiato }
CatppuccinMacchiato,
/// Catpuccin Mocha #[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
CatppuccinMocha, pub enum Catppuccin {
Frappe,
Latte,
Macchiato,
Mocha,
} }

View File

@@ -184,13 +184,14 @@ fn main() -> color_eyre::Result<()> {
hotwatch.watch(config_path, move |event| match event.kind { hotwatch.watch(config_path, move |event| match event.kind {
EventKind::Modify(_) | EventKind::Remove(_) => { EventKind::Modify(_) | EventKind::Remove(_) => {
let updated = KomobarConfig::read(&config_path_cl).unwrap(); if let Ok(updated) = KomobarConfig::read(&config_path_cl) {
tx_config.send(updated).unwrap(); tx_config.send(updated).unwrap();
tracing::info!( tracing::info!(
"configuration file updated: {}", "configuration file updated: {}",
config_path_cl.as_path().to_string_lossy() config_path_cl.as_path().to_string_lossy()
); );
}
} }
_ => {} _ => {}
})?; })?;

View File

@@ -16,11 +16,11 @@
"description": "Frame options (see: https://docs.rs/egui/latest/egui/containers/struct.Frame.html)", "description": "Frame options (see: https://docs.rs/egui/latest/egui/containers/struct.Frame.html)",
"type": "object", "type": "object",
"required": [ "required": [
"outer_margin" "inner_margin"
], ],
"properties": { "properties": {
"outer_margin": { "inner_margin": {
"description": "Margin outside the painted frame", "description": "Margin inside the painted frame",
"type": "object", "type": "object",
"required": [ "required": [
"x", "x",
@@ -778,32 +778,319 @@
"description": "Theme", "description": "Theme",
"oneOf": [ "oneOf": [
{ {
"description": "Default egui theme", "description": "A theme from catppuccin-egui",
"type": "string", "type": "object",
"enum": [ "required": [
"Default" "name",
] "type"
],
"properties": {
"name": {
"type": "string",
"enum": [
"Frappe",
"Latte",
"Macchiato",
"Mocha"
]
},
"type": {
"type": "string",
"enum": [
"Catppuccin"
]
}
}
}, },
{ {
"description": "Catpuccin Frappe", "description": "A theme from base16-egui-themes",
"type": "string", "type": "object",
"enum": [ "required": [
"CatppuccinFrappe" "name",
] "type"
}, ],
{ "properties": {
"description": "Catpuccin Macchiato", "name": {
"type": "string", "type": "string",
"enum": [ "enum": [
"CatppuccinMacchiato" "3024",
] "Apathy",
}, "Apprentice",
{ "Ashes",
"description": "Catpuccin Mocha", "AtelierCaveLight",
"type": "string", "AtelierCave",
"enum": [ "AtelierDuneLight",
"CatppuccinMocha" "AtelierDune",
] "AtelierEstuaryLight",
"AtelierEstuary",
"AtelierForestLight",
"AtelierForest",
"AtelierHeathLight",
"AtelierHeath",
"AtelierLakesideLight",
"AtelierLakeside",
"AtelierPlateauLight",
"AtelierPlateau",
"AtelierSavannaLight",
"AtelierSavanna",
"AtelierSeasideLight",
"AtelierSeaside",
"AtelierSulphurpoolLight",
"AtelierSulphurpool",
"Atlas",
"AyuDark",
"AyuLight",
"AyuMirage",
"Aztec",
"Bespin",
"BlackMetalBathory",
"BlackMetalBurzum",
"BlackMetalDarkFuneral",
"BlackMetalGorgoroth",
"BlackMetalImmortal",
"BlackMetalKhold",
"BlackMetalMarduk",
"BlackMetalMayhem",
"BlackMetalNile",
"BlackMetalVenom",
"BlackMetal",
"Blueforest",
"Blueish",
"Brewer",
"Bright",
"Brogrammer",
"BrushtreesDark",
"Brushtrees",
"Caroline",
"CatppuccinFrappe",
"CatppuccinLatte",
"CatppuccinMacchiato",
"CatppuccinMocha",
"Chalk",
"Circus",
"ClassicDark",
"ClassicLight",
"Codeschool",
"Colors",
"Cupcake",
"Cupertino",
"DaOneBlack",
"DaOneGray",
"DaOneOcean",
"DaOnePaper",
"DaOneSea",
"DaOneWhite",
"DanqingLight",
"Danqing",
"Darcula",
"Darkmoss",
"Darktooth",
"Darkviolet",
"Decaf",
"DefaultDark",
"DefaultLight",
"Dirtysea",
"Dracula",
"EdgeDark",
"EdgeLight",
"Eighties",
"EmbersLight",
"Embers",
"Emil",
"EquilibriumDark",
"EquilibriumGrayDark",
"EquilibriumGrayLight",
"EquilibriumLight",
"Eris",
"Espresso",
"EvaDim",
"Eva",
"EvenokDark",
"EverforestDarkHard",
"Everforest",
"Flat",
"Framer",
"FruitSoda",
"Gigavolt",
"Github",
"GoogleDark",
"GoogleLight",
"Gotham",
"GrayscaleDark",
"GrayscaleLight",
"Greenscreen",
"Gruber",
"GruvboxDarkHard",
"GruvboxDarkMedium",
"GruvboxDarkPale",
"GruvboxDarkSoft",
"GruvboxLightHard",
"GruvboxLightMedium",
"GruvboxLightSoft",
"GruvboxMaterialDarkHard",
"GruvboxMaterialDarkMedium",
"GruvboxMaterialDarkSoft",
"GruvboxMaterialLightHard",
"GruvboxMaterialLightMedium",
"GruvboxMaterialLightSoft",
"Hardcore",
"Harmonic16Dark",
"Harmonic16Light",
"HeetchLight",
"Heetch",
"Helios",
"Hopscotch",
"HorizonDark",
"HorizonLight",
"HorizonTerminalDark",
"HorizonTerminalLight",
"HumanoidDark",
"HumanoidLight",
"IaDark",
"IaLight",
"Icy",
"Irblack",
"Isotope",
"Jabuti",
"Kanagawa",
"Katy",
"Kimber",
"Lime",
"Macintosh",
"Marrakesh",
"Materia",
"MaterialDarker",
"MaterialLighter",
"MaterialPalenight",
"MaterialVivid",
"Material",
"MeasuredDark",
"MeasuredLight",
"MellowPurple",
"MexicoLight",
"Mocha",
"Monokai",
"Moonlight",
"Mountain",
"Nebula",
"NordLight",
"Nord",
"Nova",
"Ocean",
"Oceanicnext",
"OneLight",
"OnedarkDark",
"Onedark",
"OutrunDark",
"OxocarbonDark",
"OxocarbonLight",
"Pandora",
"PapercolorDark",
"PapercolorLight",
"Paraiso",
"Pasque",
"Phd",
"Pico",
"Pinky",
"Pop",
"Porple",
"PreciousDarkEleven",
"PreciousDarkFifteen",
"PreciousLightWarm",
"PreciousLightWhite",
"PrimerDarkDimmed",
"PrimerDark",
"PrimerLight",
"Purpledream",
"Qualia",
"Railscasts",
"Rebecca",
"RosePineDawn",
"RosePineMoon",
"RosePine",
"Saga",
"Sagelight",
"Sakura",
"Sandcastle",
"SelenizedBlack",
"SelenizedDark",
"SelenizedLight",
"SelenizedWhite",
"Seti",
"ShadesOfPurple",
"ShadesmearDark",
"ShadesmearLight",
"Shapeshifter",
"SilkDark",
"SilkLight",
"Snazzy",
"SolarflareLight",
"Solarflare",
"SolarizedDark",
"SolarizedLight",
"Spaceduck",
"Spacemacs",
"Sparky",
"StandardizedDark",
"StandardizedLight",
"Stella",
"StillAlive",
"Summercamp",
"SummerfruitDark",
"SummerfruitLight",
"SynthMidnightDark",
"SynthMidnightLight",
"Tango",
"Tarot",
"Tender",
"TerracottaDark",
"Terracotta",
"TokyoCityDark",
"TokyoCityLight",
"TokyoCityTerminalDark",
"TokyoCityTerminalLight",
"TokyoNightDark",
"TokyoNightLight",
"TokyoNightMoon",
"TokyoNightStorm",
"TokyoNightTerminalDark",
"TokyoNightTerminalLight",
"TokyoNightTerminalStorm",
"TokyodarkTerminal",
"Tokyodark",
"TomorrowNightEighties",
"TomorrowNight",
"Tomorrow",
"Tube",
"Twilight",
"UnikittyDark",
"UnikittyLight",
"UnikittyReversible",
"Uwunicorn",
"Vesper",
"Vice",
"Vulcan",
"Windows10Light",
"Windows10",
"Windows95Light",
"Windows95",
"WindowsHighcontrastLight",
"WindowsHighcontrast",
"WindowsNtLight",
"WindowsNt",
"Woodland",
"XcodeDusk",
"Zenbones",
"Zenburn"
]
},
"type": {
"type": "string",
"enum": [
"Base16"
]
}
}
} }
] ]
}, },