Skip to content

Commit 8950098

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 40c55de commit 8950098

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()
@@ -385,7 +395,11 @@ impl BarWidget for Komorebi {
385395
},
386396
);
387397

388-
if let DisplayFormat::Icon | DisplayFormat::IconAndText = format
398+
if format == DisplayFormat::Icon
399+
|| format == DisplayFormat::IconAndText
400+
|| format == DisplayFormat::IconAndTextOnFocused
401+
|| (format == DisplayFormat::TextAndIconOnFocused
402+
&& i == focused_window_idx)
389403
{
390404
if let Some(img) = icon {
391405
Frame::none()
@@ -406,7 +420,11 @@ impl BarWidget for Komorebi {
406420
}
407421
}
408422

409-
if let DisplayFormat::Text | DisplayFormat::IconAndText = format
423+
if format == DisplayFormat::Text
424+
|| format == DisplayFormat::IconAndText
425+
|| format == DisplayFormat::TextAndIconOnFocused
426+
|| (format == DisplayFormat::IconAndTextOnFocused
427+
&& i == focused_window_idx)
410428
{
411429
let available_height = ui.available_height();
412430
let mut custom_ui = CustomUi(ui);

0 commit comments

Comments
 (0)