From d393f8fe77c7fee7bc96770a63d7f3c9b476520b 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: - `TextAndIconOnSelected`: which displays icon and text for the selected element and the other elements only have text. - `IconAndTextOnSelected`: which displays icon and text for the selected 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 2221a8bc..7a9ac9dc 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 selected element, and text on the rest + TextAndIconOnSelected, /// Show both icon and text IconAndText, + /// Show an icon and text for the selected element, and icons on the rest + IconAndTextOnSelected, } diff --git a/komorebi-bar/src/komorebi.rs b/komorebi-bar/src/komorebi.rs index bde2d434..535a82c7 100644 --- a/komorebi-bar/src/komorebi.rs +++ b/komorebi-bar/src/komorebi.rs @@ -161,7 +161,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::IconAndTextOnSelected + || (format == DisplayFormat::TextAndIconOnSelected + && komorebi_notification_state.selected_workspace.eq(ws)) + { let icons: Vec<_> = container_information.icons.iter().flatten().collect(); @@ -211,8 +216,13 @@ impl BarWidget for Komorebi { _ => false, } { ui.response().on_hover_text(ws.to_string()) - } else { + } else if format != DisplayFormat::IconAndTextOnSelected + || (format == DisplayFormat::IconAndTextOnSelected + && komorebi_notification_state.selected_workspace.eq(ws)) + { ui.add(Label::new(ws.to_string()).selectable(false)) + } else { + ui.response() } }) .clicked() @@ -376,7 +386,11 @@ impl BarWidget for Komorebi { }, ); - if let DisplayFormat::Icon | DisplayFormat::IconAndText = format + if format == DisplayFormat::Icon + || format == DisplayFormat::IconAndText + || format == DisplayFormat::IconAndTextOnSelected + || (format == DisplayFormat::TextAndIconOnSelected + && i == focused_window_idx) { if let Some(img) = icon { Frame::none() @@ -397,7 +411,11 @@ impl BarWidget for Komorebi { } } - if let DisplayFormat::Text | DisplayFormat::IconAndText = format + if format == DisplayFormat::Text + || format == DisplayFormat::IconAndText + || format == DisplayFormat::TextAndIconOnSelected + || (format == DisplayFormat::IconAndTextOnSelected + && i == focused_window_idx) { let available_height = ui.available_height(); let mut custom_ui = CustomUi(ui);