From 82ab5018ca04bdc3632a9c749449bf1a40bc58cd Mon Sep 17 00:00:00 2001 From: alex-ds13 <145657253+alex-ds13@users.noreply.github.com> Date: Sat, 14 Dec 2024 12:47:27 +0000 Subject: [PATCH] feat(bar): add two new display format types This commit adds two new `DisplayFormat` types: - `TextAndIconOnFocused`: which displays icon and text for the focused element and the other elements only have text. - `IconAndTextOnFocused`: which displays icon and text for the focused element and the other elements only have icon. --- komorebi-bar/src/config.rs | 6 +++++- komorebi-bar/src/komorebi.rs | 26 ++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/komorebi-bar/src/config.rs b/komorebi-bar/src/config.rs index 74838fb45..1eb6edb5f 100644 --- a/komorebi-bar/src/config.rs +++ b/komorebi-bar/src/config.rs @@ -188,12 +188,16 @@ pub enum LabelPrefix { IconAndText, } -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] pub enum DisplayFormat { /// Show only icon Icon, /// Show only text Text, + /// Show an icon and text for the focused one, and text on the rest + TextAndIconOnFocused, /// Show both icon and text IconAndText, + /// Show an icon and text for the focused one, and icons on the rest + IconAndTextOnFocused, } diff --git a/komorebi-bar/src/komorebi.rs b/komorebi-bar/src/komorebi.rs index 99e82836c..a8daa23ec 100644 --- a/komorebi-bar/src/komorebi.rs +++ b/komorebi-bar/src/komorebi.rs @@ -158,7 +158,12 @@ impl BarWidget for Komorebi { .show(ui, |ui| { let mut has_icon = false; - if let DisplayFormat::Icon | DisplayFormat::IconAndText = format { + if format == DisplayFormat::Icon + || format == DisplayFormat::IconAndText + || format == DisplayFormat::IconAndTextOnFocused + || (format == DisplayFormat::TextAndIconOnFocused + && komorebi_notification_state.selected_workspace.eq(ws)) + { let icons: Vec<_> = container_information.icons.iter().flatten().collect(); @@ -213,8 +218,13 @@ impl BarWidget for Komorebi { _ => false, } { ui.response().on_hover_text(ws.to_string()) - } else { + } else if format != DisplayFormat::IconAndTextOnFocused + || (format == DisplayFormat::IconAndTextOnFocused + && komorebi_notification_state.selected_workspace.eq(ws)) + { ui.add(Label::new(ws.to_string()).selectable(false)) + } else { + ui.response() } }) .clicked() @@ -385,7 +395,11 @@ impl BarWidget for Komorebi { }, ); - if let DisplayFormat::Icon | DisplayFormat::IconAndText = format + if format == DisplayFormat::Icon + || format == DisplayFormat::IconAndText + || format == DisplayFormat::IconAndTextOnFocused + || (format == DisplayFormat::TextAndIconOnFocused + && selected) { if let Some(img) = icon { Frame::none() @@ -406,7 +420,11 @@ impl BarWidget for Komorebi { } } - if let DisplayFormat::Text | DisplayFormat::IconAndText = format + if format == DisplayFormat::Text + || format == DisplayFormat::IconAndText + || format == DisplayFormat::TextAndIconOnFocused + || (format == DisplayFormat::IconAndTextOnFocused + && selected) { let available_height = ui.available_height(); let mut custom_ui = CustomUi(ui);