feat(bar): add accents to widget emojis

This commit is contained in:
LGUG2Z
2024-09-13 18:33:19 -07:00
parent 68244985e5
commit d9cca4a3d8
9 changed files with 415 additions and 246 deletions
+15 -10
View File
@@ -59,7 +59,8 @@ impl Komobar {
} => match catppuccin { } => match catppuccin {
Catppuccin::Frappe => { Catppuccin::Frappe => {
catppuccin_egui::set_theme(ctx, catppuccin_egui::FRAPPE); catppuccin_egui::set_theme(ctx, catppuccin_egui::FRAPPE);
if let Some(catppuccin_value) = catppuccin_value { let catppuccin_value = catppuccin_value.unwrap_or_default();
let accent = match catppuccin_value { let accent = match catppuccin_value {
CatppuccinValue::Rosewater => catppuccin_egui::FRAPPE.rosewater, CatppuccinValue::Rosewater => catppuccin_egui::FRAPPE.rosewater,
CatppuccinValue::Flamingo => catppuccin_egui::FRAPPE.flamingo, CatppuccinValue::Flamingo => catppuccin_egui::FRAPPE.flamingo,
@@ -95,12 +96,13 @@ impl Komobar {
style.visuals.widgets.active.fg_stroke.color = accent; style.visuals.widgets.active.fg_stroke.color = accent;
style.visuals.override_text_color = None; style.visuals.override_text_color = None;
}); });
}
self.bg_color = catppuccin_egui::FRAPPE.base; self.bg_color = catppuccin_egui::FRAPPE.base;
} }
Catppuccin::Latte => { Catppuccin::Latte => {
catppuccin_egui::set_theme(ctx, catppuccin_egui::LATTE); catppuccin_egui::set_theme(ctx, catppuccin_egui::LATTE);
if let Some(catppuccin_value) = catppuccin_value { let catppuccin_value = catppuccin_value.unwrap_or_default();
let accent = match catppuccin_value { let accent = match catppuccin_value {
CatppuccinValue::Rosewater => catppuccin_egui::LATTE.rosewater, CatppuccinValue::Rosewater => catppuccin_egui::LATTE.rosewater,
CatppuccinValue::Flamingo => catppuccin_egui::LATTE.flamingo, CatppuccinValue::Flamingo => catppuccin_egui::LATTE.flamingo,
@@ -136,12 +138,13 @@ impl Komobar {
style.visuals.widgets.active.fg_stroke.color = accent; style.visuals.widgets.active.fg_stroke.color = accent;
style.visuals.override_text_color = None; style.visuals.override_text_color = None;
}); });
}
self.bg_color = catppuccin_egui::LATTE.base; self.bg_color = catppuccin_egui::LATTE.base;
} }
Catppuccin::Macchiato => { Catppuccin::Macchiato => {
catppuccin_egui::set_theme(ctx, catppuccin_egui::MACCHIATO); catppuccin_egui::set_theme(ctx, catppuccin_egui::MACCHIATO);
if let Some(catppuccin_value) = catppuccin_value { let catppuccin_value = catppuccin_value.unwrap_or_default();
let accent = match catppuccin_value { let accent = match catppuccin_value {
CatppuccinValue::Rosewater => catppuccin_egui::MACCHIATO.rosewater, CatppuccinValue::Rosewater => catppuccin_egui::MACCHIATO.rosewater,
CatppuccinValue::Flamingo => catppuccin_egui::MACCHIATO.flamingo, CatppuccinValue::Flamingo => catppuccin_egui::MACCHIATO.flamingo,
@@ -177,12 +180,13 @@ impl Komobar {
style.visuals.widgets.active.fg_stroke.color = accent; style.visuals.widgets.active.fg_stroke.color = accent;
style.visuals.override_text_color = None; style.visuals.override_text_color = None;
}); });
}
self.bg_color = catppuccin_egui::MACCHIATO.base; self.bg_color = catppuccin_egui::MACCHIATO.base;
} }
Catppuccin::Mocha => { Catppuccin::Mocha => {
catppuccin_egui::set_theme(ctx, catppuccin_egui::MOCHA); catppuccin_egui::set_theme(ctx, catppuccin_egui::MOCHA);
if let Some(catppuccin_value) = catppuccin_value { let catppuccin_value = catppuccin_value.unwrap_or_default();
let accent = match catppuccin_value { let accent = match catppuccin_value {
CatppuccinValue::Rosewater => catppuccin_egui::MOCHA.rosewater, CatppuccinValue::Rosewater => catppuccin_egui::MOCHA.rosewater,
CatppuccinValue::Flamingo => catppuccin_egui::MOCHA.flamingo, CatppuccinValue::Flamingo => catppuccin_egui::MOCHA.flamingo,
@@ -218,7 +222,7 @@ impl Komobar {
style.visuals.widgets.active.fg_stroke.color = accent; style.visuals.widgets.active.fg_stroke.color = accent;
style.visuals.override_text_color = None; style.visuals.override_text_color = None;
}); });
}
self.bg_color = catppuccin_egui::MOCHA.base; self.bg_color = catppuccin_egui::MOCHA.base;
} }
}, },
@@ -227,7 +231,8 @@ impl Komobar {
accent: base16_value, accent: base16_value,
} => { } => {
ctx.set_style(base16.style()); ctx.set_style(base16.style());
if let Some(base16_value) = base16_value { let base16_value = base16_value.unwrap_or_default();
let accent = match base16_value { let accent = match base16_value {
Base16Value::Base00 => base16.base00(), Base16Value::Base00 => base16.base00(),
Base16Value::Base01 => base16.base01(), Base16Value::Base01 => base16.base01(),
@@ -252,7 +257,7 @@ impl Komobar {
style.visuals.widgets.hovered.fg_stroke.color = accent; style.visuals.widgets.hovered.fg_stroke.color = accent;
style.visuals.widgets.active.fg_stroke.color = accent; style.visuals.widgets.active.fg_stroke.color = accent;
}); });
}
self.bg_color = base16.background(); self.bg_color = base16.background();
} }
}, },
+36 -13
View File
@@ -1,8 +1,12 @@
use crate::widget::BarWidget; use crate::widget::BarWidget;
use crate::WIDGET_SPACING; use crate::WIDGET_SPACING;
use eframe::egui::text::LayoutJob;
use eframe::egui::Context; use eframe::egui::Context;
use eframe::egui::FontId;
use eframe::egui::Label; use eframe::egui::Label;
use eframe::egui::Sense; use eframe::egui::Sense;
use eframe::egui::TextFormat;
use eframe::egui::TextStyle;
use eframe::egui::Ui; use eframe::egui::Ui;
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::Deserialize; use serde::Deserialize;
@@ -24,7 +28,7 @@ pub struct BatteryConfig {
impl From<BatteryConfig> for Battery { impl From<BatteryConfig> for Battery {
fn from(value: BatteryConfig) -> Self { fn from(value: BatteryConfig) -> Self {
let manager = Manager::new().unwrap(); let manager = Manager::new().unwrap();
let mut last_state = vec![]; let mut last_state = String::new();
let mut state = None; let mut state = None;
if let Ok(mut batteries) = manager.batteries() { if let Ok(mut batteries) = manager.batteries() {
@@ -35,7 +39,8 @@ impl From<BatteryConfig> for Battery {
State::Discharging => state = Some(BatteryState::Discharging), State::Discharging => state = Some(BatteryState::Discharging),
_ => {} _ => {}
} }
last_state.push(format!("{percentage}%"));
last_state = format!("{percentage}%");
} }
} }
@@ -60,17 +65,17 @@ pub struct Battery {
manager: Manager, manager: Manager,
pub state: BatteryState, pub state: BatteryState,
data_refresh_interval: u64, data_refresh_interval: u64,
last_state: Vec<String>, last_state: String,
last_updated: Instant, last_updated: Instant,
} }
impl Battery { impl Battery {
fn output(&mut self) -> Vec<String> { fn output(&mut self) -> String {
let mut outputs = self.last_state.clone(); let mut output = self.last_state.clone();
let now = Instant::now(); let now = Instant::now();
if now.duration_since(self.last_updated) > Duration::from_secs(self.data_refresh_interval) { if now.duration_since(self.last_updated) > Duration::from_secs(self.data_refresh_interval) {
outputs.clear(); output.clear();
if let Ok(mut batteries) = self.manager.batteries() { if let Ok(mut batteries) = self.manager.batteries() {
if let Some(Ok(first)) = batteries.nth(0) { if let Some(Ok(first)) = batteries.nth(0) {
@@ -81,31 +86,50 @@ impl Battery {
_ => {} _ => {}
} }
outputs.push(format!("{percentage}%")); output = format!("{percentage}%");
} }
} }
self.last_state.clone_from(&outputs); self.last_state.clone_from(&output);
self.last_updated = now; self.last_updated = now;
} }
outputs output
} }
} }
impl BarWidget for Battery { impl BarWidget for Battery {
fn render(&mut self, _ctx: &Context, ui: &mut Ui) { fn render(&mut self, ctx: &Context, ui: &mut Ui) {
if self.enable { if self.enable {
let output = self.output(); let output = self.output();
if !output.is_empty() { if !output.is_empty() {
for battery in output {
let emoji = match self.state { let emoji = match self.state {
BatteryState::Charging => egui_phosphor::regular::BATTERY_CHARGING, BatteryState::Charging => egui_phosphor::regular::BATTERY_CHARGING,
BatteryState::Discharging => egui_phosphor::regular::BATTERY_FULL, BatteryState::Discharging => egui_phosphor::regular::BATTERY_FULL,
}; };
let font_id = ctx
.style()
.text_styles
.get(&TextStyle::Body)
.cloned()
.unwrap_or_else(FontId::default);
let mut layout_job = LayoutJob::simple(
emoji.to_string(),
font_id.clone(),
ctx.style().visuals.selection.stroke.color,
100.0,
);
layout_job.append(
&output,
10.0,
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
);
ui.add( ui.add(
Label::new(format!("{emoji} {battery}")) Label::new(layout_job)
.selectable(false) .selectable(false)
.sense(Sense::click()), .sense(Sense::click()),
); );
@@ -115,4 +139,3 @@ impl BarWidget for Battery {
} }
} }
} }
}
+32 -10
View File
@@ -1,9 +1,14 @@
use crate::widget::BarWidget; use crate::widget::BarWidget;
use crate::WIDGET_SPACING; use crate::WIDGET_SPACING;
use eframe::egui::text::LayoutJob;
use eframe::egui::Context; use eframe::egui::Context;
use eframe::egui::FontId;
use eframe::egui::Label; use eframe::egui::Label;
use eframe::egui::Sense; use eframe::egui::Sense;
use eframe::egui::TextFormat;
use eframe::egui::TextStyle;
use eframe::egui::Ui; use eframe::egui::Ui;
use eframe::egui::WidgetText;
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::Deserialize; use serde::Deserialize;
use serde::Serialize; use serde::Serialize;
@@ -68,24 +73,41 @@ pub struct Date {
} }
impl Date { impl Date {
fn output(&mut self) -> Vec<String> { fn output(&mut self) -> String {
vec![chrono::Local::now() chrono::Local::now()
.format(&self.format.fmt_string()) .format(&self.format.fmt_string())
.to_string()] .to_string()
} }
} }
impl BarWidget for Date { impl BarWidget for Date {
fn render(&mut self, _ctx: &Context, ui: &mut Ui) { fn render(&mut self, ctx: &Context, ui: &mut Ui) {
if self.enable { if self.enable {
for output in self.output() { let output = self.output();
if !output.is_empty() {
let font_id = ctx
.style()
.text_styles
.get(&TextStyle::Body)
.cloned()
.unwrap_or_else(FontId::default);
let mut layout_job = LayoutJob::simple(
egui_phosphor::regular::CALENDAR_DOTS.to_string(),
font_id.clone(),
ctx.style().visuals.selection.stroke.color,
100.0,
);
layout_job.append(
&output,
10.0,
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
);
if ui if ui
.add( .add(
Label::new(format!( Label::new(WidgetText::LayoutJob(layout_job.clone()))
"{} {}",
egui_phosphor::regular::CALENDAR_DOTS,
output
))
.selectable(false) .selectable(false)
.sense(Sense::click()), .sense(Sense::click()),
) )
+5 -2
View File
@@ -183,8 +183,8 @@ fn main() -> color_eyre::Result<()> {
let config_path_cl = config_path.clone(); let config_path_cl = config_path.clone();
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(_) => match KomobarConfig::read(&config_path_cl) {
if let Ok(updated) = KomobarConfig::read(&config_path_cl) { Ok(updated) => {
tx_config.send(updated).unwrap(); tx_config.send(updated).unwrap();
tracing::info!( tracing::info!(
@@ -192,7 +192,10 @@ fn main() -> color_eyre::Result<()> {
config_path_cl.as_path().to_string_lossy() config_path_cl.as_path().to_string_lossy()
); );
} }
Err(error) => {
tracing::error!("{error}");
} }
},
_ => {} _ => {}
})?; })?;
+33 -8
View File
@@ -1,8 +1,12 @@
use crate::widget::BarWidget; use crate::widget::BarWidget;
use crate::WIDGET_SPACING; use crate::WIDGET_SPACING;
use eframe::egui::text::LayoutJob;
use eframe::egui::Context; use eframe::egui::Context;
use eframe::egui::FontId;
use eframe::egui::Label; use eframe::egui::Label;
use eframe::egui::Sense; use eframe::egui::Sense;
use eframe::egui::TextFormat;
use eframe::egui::TextStyle;
use eframe::egui::Ui; use eframe::egui::Ui;
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::Deserialize; use serde::Deserialize;
@@ -46,36 +50,57 @@ impl Media {
} }
} }
fn output(&mut self) -> Vec<String> { fn output(&mut self) -> String {
if let Ok(session) = self.session_manager.GetCurrentSession() { if let Ok(session) = self.session_manager.GetCurrentSession() {
if let Ok(operation) = session.TryGetMediaPropertiesAsync() { if let Ok(operation) = session.TryGetMediaPropertiesAsync() {
if let Ok(properties) = operation.get() { if let Ok(properties) = operation.get() {
if let (Ok(artist), Ok(title)) = (properties.Artist(), properties.Title()) { if let (Ok(artist), Ok(title)) = (properties.Artist(), properties.Title()) {
if artist.is_empty() { if artist.is_empty() {
return vec![format!("{title}")]; return format!("{title}");
} }
if title.is_empty() { if title.is_empty() {
return vec![format!("{artist}")]; return format!("{artist}");
} }
return vec![format!("{artist} - {title}")]; return format!("{artist} - {title}");
} }
} }
} }
} }
vec![] String::new()
} }
} }
impl BarWidget for Media { impl BarWidget for Media {
fn render(&mut self, _ctx: &Context, ui: &mut Ui) { fn render(&mut self, ctx: &Context, ui: &mut Ui) {
if self.enable { if self.enable {
for output in self.output() { let output = self.output();
if !output.is_empty() {
let font_id = ctx
.style()
.text_styles
.get(&TextStyle::Body)
.cloned()
.unwrap_or_else(FontId::default);
let mut layout_job = LayoutJob::simple(
egui_phosphor::regular::HEADPHONES.to_string(),
font_id.clone(),
ctx.style().visuals.selection.stroke.color,
100.0,
);
layout_job.append(
&output,
10.0,
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
);
if ui if ui
.add( .add(
Label::new(format!("{} {output}", egui_phosphor::regular::HEADPHONES)) Label::new(layout_job)
.selectable(false) .selectable(false)
.sense(Sense::click()), .sense(Sense::click()),
) )
+30 -5
View File
@@ -1,8 +1,12 @@
use crate::widget::BarWidget; use crate::widget::BarWidget;
use crate::WIDGET_SPACING; use crate::WIDGET_SPACING;
use eframe::egui::text::LayoutJob;
use eframe::egui::Context; use eframe::egui::Context;
use eframe::egui::FontId;
use eframe::egui::Label; use eframe::egui::Label;
use eframe::egui::Sense; use eframe::egui::Sense;
use eframe::egui::TextFormat;
use eframe::egui::TextStyle;
use eframe::egui::Ui; use eframe::egui::Ui;
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::Deserialize; use serde::Deserialize;
@@ -45,7 +49,7 @@ pub struct Memory {
} }
impl Memory { impl Memory {
fn output(&mut self) -> Vec<String> { fn output(&mut self) -> String {
let now = Instant::now(); let now = Instant::now();
if now.duration_since(self.last_updated) > Duration::from_secs(self.data_refresh_interval) { if now.duration_since(self.last_updated) > Duration::from_secs(self.data_refresh_interval) {
self.system.refresh_memory(); self.system.refresh_memory();
@@ -54,17 +58,38 @@ impl Memory {
let used = self.system.used_memory(); let used = self.system.used_memory();
let total = self.system.total_memory(); let total = self.system.total_memory();
vec![format!("RAM: {}%", (used * 100) / total)] format!("RAM: {}%", (used * 100) / total)
} }
} }
impl BarWidget for Memory { impl BarWidget for Memory {
fn render(&mut self, _ctx: &Context, ui: &mut Ui) { fn render(&mut self, ctx: &Context, ui: &mut Ui) {
if self.enable { if self.enable {
for output in self.output() { let output = self.output();
if !output.is_empty() {
let font_id = ctx
.style()
.text_styles
.get(&TextStyle::Body)
.cloned()
.unwrap_or_else(FontId::default);
let mut layout_job = LayoutJob::simple(
egui_phosphor::regular::MEMORY.to_string(),
font_id.clone(),
ctx.style().visuals.selection.stroke.color,
100.0,
);
layout_job.append(
&output,
10.0,
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
);
if ui if ui
.add( .add(
Label::new(format!("{} {}", egui_phosphor::regular::MEMORY, output)) Label::new(layout_job)
.selectable(false) .selectable(false)
.sense(Sense::click()), .sense(Sense::click()),
) )
+29 -8
View File
@@ -1,8 +1,12 @@
use crate::widget::BarWidget; use crate::widget::BarWidget;
use crate::WIDGET_SPACING; use crate::WIDGET_SPACING;
use eframe::egui::text::LayoutJob;
use eframe::egui::Context; use eframe::egui::Context;
use eframe::egui::FontId;
use eframe::egui::Label; use eframe::egui::Label;
use eframe::egui::Sense; use eframe::egui::Sense;
use eframe::egui::TextFormat;
use eframe::egui::TextStyle;
use eframe::egui::Ui; use eframe::egui::Ui;
use num_derive::FromPrimitive; use num_derive::FromPrimitive;
use schemars::JsonSchema; use schemars::JsonSchema;
@@ -194,7 +198,7 @@ impl Network {
} }
impl BarWidget for Network { impl BarWidget for Network {
fn render(&mut self, _ctx: &Context, ui: &mut Ui) { fn render(&mut self, ctx: &Context, ui: &mut Ui) {
if self.show_total_data_transmitted { if self.show_total_data_transmitted {
for output in self.total_data_transmitted() { for output in self.total_data_transmitted() {
ui.add(Label::new(output).selectable(false)); ui.add(Label::new(output).selectable(false));
@@ -214,14 +218,30 @@ impl BarWidget for Network {
if self.enable { if self.enable {
self.default_interface(); self.default_interface();
if !self.default_interface.is_empty() if !self.default_interface.is_empty() {
&& ui let font_id = ctx
.style()
.text_styles
.get(&TextStyle::Body)
.cloned()
.unwrap_or_else(FontId::default);
let mut layout_job = LayoutJob::simple(
egui_phosphor::regular::WIFI_HIGH.to_string(),
font_id.clone(),
ctx.style().visuals.selection.stroke.color,
100.0,
);
layout_job.append(
&self.default_interface,
10.0,
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
);
if ui
.add( .add(
Label::new(format!( Label::new(layout_job)
"{} {}",
egui_phosphor::regular::WIFI_HIGH,
self.default_interface
))
.selectable(false) .selectable(false)
.sense(Sense::click()), .sense(Sense::click()),
) )
@@ -231,6 +251,7 @@ impl BarWidget for Network {
eprintln!("{}", error) eprintln!("{}", error)
} }
} }
}
ui.add_space(WIDGET_SPACING); ui.add_space(WIDGET_SPACING);
} }
+26 -6
View File
@@ -1,8 +1,12 @@
use crate::widget::BarWidget; use crate::widget::BarWidget;
use crate::WIDGET_SPACING; use crate::WIDGET_SPACING;
use eframe::egui::text::LayoutJob;
use eframe::egui::Context; use eframe::egui::Context;
use eframe::egui::FontId;
use eframe::egui::Label; use eframe::egui::Label;
use eframe::egui::Sense; use eframe::egui::Sense;
use eframe::egui::TextFormat;
use eframe::egui::TextStyle;
use eframe::egui::Ui; use eframe::egui::Ui;
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::Deserialize; use serde::Deserialize;
@@ -69,16 +73,32 @@ impl Storage {
} }
impl BarWidget for Storage { impl BarWidget for Storage {
fn render(&mut self, _ctx: &Context, ui: &mut Ui) { fn render(&mut self, ctx: &Context, ui: &mut Ui) {
if self.enable { if self.enable {
let font_id = ctx
.style()
.text_styles
.get(&TextStyle::Body)
.cloned()
.unwrap_or_else(FontId::default);
for output in self.output() { for output in self.output() {
let mut layout_job = LayoutJob::simple(
egui_phosphor::regular::HARD_DRIVES.to_string(),
font_id.clone(),
ctx.style().visuals.selection.stroke.color,
100.0,
);
layout_job.append(
&output,
10.0,
TextFormat::simple(font_id.clone(), ctx.style().visuals.text_color()),
);
if ui if ui
.add( .add(
Label::new(format!( Label::new(layout_job)
"{} {}",
egui_phosphor::regular::HARD_DRIVES,
output
))
.selectable(false) .selectable(false)
.sense(Sense::click()), .sense(Sense::click()),
) )
+31 -6
View File
@@ -1,8 +1,12 @@
use crate::widget::BarWidget; use crate::widget::BarWidget;
use crate::WIDGET_SPACING; use crate::WIDGET_SPACING;
use eframe::egui::text::LayoutJob;
use eframe::egui::Context; use eframe::egui::Context;
use eframe::egui::FontId;
use eframe::egui::Label; use eframe::egui::Label;
use eframe::egui::Sense; use eframe::egui::Sense;
use eframe::egui::TextFormat;
use eframe::egui::TextStyle;
use eframe::egui::Ui; use eframe::egui::Ui;
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::Deserialize; use serde::Deserialize;
@@ -60,20 +64,41 @@ pub struct Time {
} }
impl Time { impl Time {
fn output(&mut self) -> Vec<String> { fn output(&mut self) -> String {
vec![chrono::Local::now() chrono::Local::now()
.format(&self.format.fmt_string()) .format(&self.format.fmt_string())
.to_string()] .to_string()
} }
} }
impl BarWidget for Time { impl BarWidget for Time {
fn render(&mut self, _ctx: &Context, ui: &mut Ui) { fn render(&mut self, ctx: &Context, ui: &mut Ui) {
if self.enable { if self.enable {
for output in self.output() { let output = self.output();
if !output.is_empty() {
let font_id = ctx
.style()
.text_styles
.get(&TextStyle::Body)
.cloned()
.unwrap_or_else(FontId::default);
let mut layout_job = LayoutJob::simple(
egui_phosphor::regular::CLOCK.to_string(),
font_id.clone(),
ctx.style().visuals.selection.stroke.color,
100.0,
);
layout_job.append(
&output,
10.0,
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
);
if ui if ui
.add( .add(
Label::new(format!("{} {}", egui_phosphor::regular::CLOCK, output)) Label::new(layout_job)
.selectable(false) .selectable(false)
.sense(Sense::click()), .sense(Sense::click()),
) )