Skip to content

Commit e4c7350

Browse files
committed
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.
1 parent 10539a4 commit e4c7350

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 focused one, and text on the rest
198+
TextAndIconOnFocused,
197199
/// Show both icon and text
198200
IconAndText,
201+
/// Show an icon and text for the focused one, and icons on the rest
202+
IconAndTextOnFocused,
199203
}

komorebi-bar/src/komorebi.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,12 @@ impl BarWidget for Komorebi {
158158
.show(ui, |ui| {
159159
let mut has_icon = false;
160160

161-
if let DisplayFormat::Icon | DisplayFormat::IconAndText = format {
161+
if format == DisplayFormat::Icon
162+
|| format == DisplayFormat::IconAndText
163+
|| format == DisplayFormat::IconAndTextOnFocused
164+
|| (format == DisplayFormat::TextAndIconOnFocused
165+
&& komorebi_notification_state.selected_workspace.eq(ws))
166+
{
162167
let icons: Vec<_> =
163168
container_information.icons.iter().flatten().collect();
164169

@@ -213,8 +218,13 @@ impl BarWidget for Komorebi {
213218
_ => false,
214219
} {
215220
ui.response().on_hover_text(ws.to_string())
216-
} else {
221+
} else if format != DisplayFormat::IconAndTextOnFocused
222+
|| (format == DisplayFormat::IconAndTextOnFocused
223+
&& komorebi_notification_state.selected_workspace.eq(ws))
224+
{
217225
ui.add(Label::new(ws.to_string()).selectable(false))
226+
} else {
227+
ui.response()
218228
}
219229
})
220230
.clicked()
@@ -377,7 +387,11 @@ impl BarWidget for Komorebi {
377387
},
378388
);
379389

380-
if let DisplayFormat::Icon | DisplayFormat::IconAndText = format
390+
if format == DisplayFormat::Icon
391+
|| format == DisplayFormat::IconAndText
392+
|| format == DisplayFormat::IconAndTextOnFocused
393+
|| (format == DisplayFormat::TextAndIconOnFocused
394+
&& i == focused_window_idx)
381395
{
382396
if let Some(img) = icon {
383397
Frame::none()
@@ -398,7 +412,11 @@ impl BarWidget for Komorebi {
398412
}
399413
}
400414

401-
if let DisplayFormat::Text | DisplayFormat::IconAndText = format
415+
if format == DisplayFormat::Text
416+
|| format == DisplayFormat::IconAndText
417+
|| format == DisplayFormat::TextAndIconOnFocused
418+
|| (format == DisplayFormat::IconAndTextOnFocused
419+
&& i == focused_window_idx)
402420
{
403421
let available_height = ui.available_height();
404422
let mut custom_ui = CustomUi(ui);

0 commit comments

Comments
 (0)