Skip to content

Commit

Permalink
feat(bar): add two new display format types
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alex-ds13 committed Dec 14, 2024
1 parent 10539a4 commit e4c7350
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
6 changes: 5 additions & 1 deletion komorebi-bar/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
26 changes: 22 additions & 4 deletions komorebi-bar/src/komorebi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -377,7 +387,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
&& i == focused_window_idx)
{
if let Some(img) = icon {
Frame::none()
Expand All @@ -398,7 +412,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
&& i == focused_window_idx)
{
let available_height = ui.available_height();
let mut custom_ui = CustomUi(ui);
Expand Down

0 comments on commit e4c7350

Please sign in to comment.