Skip to content

Commit

Permalink
Fix style of menu folders
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Sep 27, 2024
1 parent cf6a354 commit 973018f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/theme/style/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub enum Button {
IconVertical,
Image,
Link,
MenuFolder,
MenuItem,
MenuRoot,
#[default]
Expand Down Expand Up @@ -125,10 +126,14 @@ pub fn appearance(
appearance.icon_color = Some(cosmic.background.on.into());
appearance.text_color = Some(cosmic.background.on.into());
}
Button::MenuRoot => {
appearance.background = None;
appearance.icon_color = None;
appearance.text_color = None;
Button::MenuFolder => {
// Menu folders cannot be disabled, ignore customized icon and text color
let component = &cosmic.background.component;
let (background, _, _) = color(component);
appearance.background = Some(Background::Color(background));
appearance.icon_color = Some(component.on.into());
appearance.text_color = Some(component.on.into());
corner_radii = &cosmic.corner_radii.radius_s;
}
Button::MenuItem => {
let (background, text, icon) = color(&cosmic.background.component);
Expand All @@ -137,6 +142,11 @@ pub fn appearance(
appearance.text_color = text;
corner_radii = &cosmic.corner_radii.radius_s;
}
Button::MenuRoot => {
appearance.background = None;
appearance.icon_color = None;
appearance.text_color = None;
}
}

appearance.border_radius = (*corner_radii).into();
Expand Down
12 changes: 11 additions & 1 deletion src/widget/menu/menu_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,17 @@ where
.size(16)
.icon()
.into(),
]),
])
.style(
// Menu folders have no on_press so they take on the disabled style by default
if children.is_empty() {
// This will make the folder use the disabled style if it has no children
theme::Button::MenuItem
} else {
// This will make the folder use the enabled style if it has children
theme::Button::MenuFolder
},
),
menu_items(key_binds, children),
));
}
Expand Down

0 comments on commit 973018f

Please sign in to comment.