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.
This commit is contained in:
alex-ds13
2024-12-14 12:47:27 +00:00
committed by جاد
parent c3769e7881
commit d393f8fe77
2 changed files with 27 additions and 5 deletions

View File

@@ -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,
}

View File

@@ -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();
@@ -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()
@@ -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()
@@ -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);