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:
- `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.
  • Loading branch information
alex-ds13 committed Dec 17, 2024
1 parent 53c74a2 commit abe5871
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 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,
}
26 changes: 22 additions & 4 deletions komorebi-bar/src/komorebi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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);
Expand Down

0 comments on commit abe5871

Please sign in to comment.