Skip to content

Commit 81d8638

Browse files
committed
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.
1 parent 57e5c02 commit 81d8638

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

komorebi-bar/src/config.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,16 @@ pub enum LabelPrefix {
188188
IconAndText,
189189
}
190190

191-
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
191+
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
192192
pub enum DisplayFormat {
193193
/// Show only icon
194194
Icon,
195195
/// Show only text
196196
Text,
197+
/// Show an icon and text for the selected element, and text on the rest
198+
TextAndIconOnSelected,
197199
/// Show both icon and text
198200
IconAndText,
201+
/// Show an icon and text for the selected element, and icons on the rest
202+
IconAndTextOnSelected,
199203
}

komorebi-bar/src/komorebi.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,12 @@ impl BarWidget for Komorebi {
161161
.show(ui, |ui| {
162162
let mut has_icon = false;
163163

164-
if let DisplayFormat::Icon | DisplayFormat::IconAndText = format {
164+
if format == DisplayFormat::Icon
165+
|| format == DisplayFormat::IconAndText
166+
|| format == DisplayFormat::IconAndTextOnSelected
167+
|| (format == DisplayFormat::TextAndIconOnSelected
168+
&& komorebi_notification_state.selected_workspace.eq(ws))
169+
{
165170
let icons: Vec<_> =
166171
container_information.icons.iter().flatten().collect();
167172

@@ -211,8 +216,13 @@ impl BarWidget for Komorebi {
211216
_ => false,
212217
} {
213218
ui.response().on_hover_text(ws.to_string())
214-
} else {
219+
} else if format != DisplayFormat::IconAndTextOnSelected
220+
|| (format == DisplayFormat::IconAndTextOnSelected
221+
&& komorebi_notification_state.selected_workspace.eq(ws))
222+
{
215223
ui.add(Label::new(ws.to_string()).selectable(false))
224+
} else {
225+
ui.response()
216226
}
217227
})
218228
.clicked()
@@ -376,7 +386,11 @@ impl BarWidget for Komorebi {
376386
},
377387
);
378388

379-
if let DisplayFormat::Icon | DisplayFormat::IconAndText = format
389+
if format == DisplayFormat::Icon
390+
|| format == DisplayFormat::IconAndText
391+
|| format == DisplayFormat::IconAndTextOnSelected
392+
|| (format == DisplayFormat::TextAndIconOnSelected
393+
&& i == focused_window_idx)
380394
{
381395
if let Some(img) = icon {
382396
Frame::none()
@@ -397,7 +411,11 @@ impl BarWidget for Komorebi {
397411
}
398412
}
399413

400-
if let DisplayFormat::Text | DisplayFormat::IconAndText = format
414+
if format == DisplayFormat::Text
415+
|| format == DisplayFormat::IconAndText
416+
|| format == DisplayFormat::TextAndIconOnSelected
417+
|| (format == DisplayFormat::IconAndTextOnSelected
418+
&& i == focused_window_idx)
401419
{
402420
let available_height = ui.available_height();
403421
let mut custom_ui = CustomUi(ui);

0 commit comments

Comments
 (0)