Only override icon button colors when it is disabled

This commit is contained in:
Jeremy Soller 2024-09-27 10:08:27 -06:00
parent 973018fdb7
commit 228eb4d70d
No known key found for this signature in database
GPG key ID: D02FD439211AF56F

View file

@ -41,6 +41,7 @@ pub fn appearance(
theme: &crate::Theme, theme: &crate::Theme,
focused: bool, focused: bool,
selected: bool, selected: bool,
disabled: bool,
style: &Button, style: &Button,
color: impl Fn(&Component) -> (Color, Option<Color>, Option<Color>), color: impl Fn(&Component) -> (Color, Option<Color>, Option<Color>),
) -> Appearance { ) -> Appearance {
@ -83,8 +84,9 @@ pub fn appearance(
let (background, text, icon) = color(&cosmic.icon_button); let (background, text, icon) = color(&cosmic.icon_button);
appearance.background = Some(Background::Color(background)); appearance.background = Some(Background::Color(background));
appearance.text_color = text; // Only override icon button colors when it is disabled
appearance.icon_color = icon; appearance.icon_color = if disabled { icon } else { None };
appearance.text_color = if disabled { text } else { None };
} }
Button::Image => { Button::Image => {
@ -169,7 +171,7 @@ impl StyleSheet for crate::Theme {
return active(focused, self); return active(focused, self);
} }
appearance(self, focused, selected, style, move |component| { appearance(self, focused, selected, false, style, move |component| {
let text_color = if matches!( let text_color = if matches!(
style, style,
Button::Icon | Button::IconVertical | Button::HeaderBar Button::Icon | Button::IconVertical | Button::HeaderBar
@ -189,7 +191,7 @@ impl StyleSheet for crate::Theme {
return disabled(self); return disabled(self);
} }
appearance(self, false, false, style, |component| { appearance(self, false, false, true, style, |component| {
let mut background = Color::from(component.base); let mut background = Color::from(component.base);
background.a *= 0.5; background.a *= 0.5;
( (
@ -213,6 +215,7 @@ impl StyleSheet for crate::Theme {
self, self,
focused || matches!(style, Button::Image), focused || matches!(style, Button::Image),
selected, selected,
false,
style, style,
|component| { |component| {
let text_color = if matches!( let text_color = if matches!(
@ -235,7 +238,7 @@ impl StyleSheet for crate::Theme {
return pressed(focused, self); return pressed(focused, self);
} }
appearance(self, focused, selected, style, |component| { appearance(self, focused, selected, false, style, |component| {
let text_color = if matches!( let text_color = if matches!(
style, style,
Button::Icon | Button::IconVertical | Button::HeaderBar Button::Icon | Button::IconVertical | Button::HeaderBar