From b404497e7636d44ba0fffa9b88e26f5b76d2b789 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Mon, 18 Sep 2023 08:28:51 +0200 Subject: [PATCH] fix(widget): allow `None` for button text color to inherit from container --- src/theme/style/button.rs | 27 ++++++++++++--------------- src/widget/button/icon.rs | 5 ----- src/widget/button/style.rs | 8 ++------ src/widget/button/widget.rs | 2 +- src/widget/header_bar.rs | 1 - 5 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/theme/style/button.rs b/src/theme/style/button.rs index d6718ba42be..b4ea8306c3e 100644 --- a/src/theme/style/button.rs +++ b/src/theme/style/button.rs @@ -20,7 +20,6 @@ pub enum Button { Destructive, Link, Icon, - IconInheritColors, IconVertical, #[default] Standard, @@ -32,7 +31,7 @@ pub fn appearance( theme: &crate::Theme, focused: bool, style: &Button, - color: impl Fn(&Component>) -> (Color, Color, Option), + color: impl Fn(&Component>) -> (Color, Option, Option), ) -> Appearance { let cosmic = theme.cosmic(); let mut corner_radii = &cosmic.corner_radii.radius_xl; @@ -54,28 +53,26 @@ pub fn appearance( appearance.icon_color = icon; } - Button::Icon | Button::IconInheritColors | Button::IconVertical => { + Button::Icon | Button::IconVertical => { if let Button::IconVertical = style { corner_radii = &cosmic.corner_radii.radius_m; } - let (background, text, icon) = color(&cosmic.icon_button); + let (background, _text, icon) = color(&cosmic.icon_button); appearance.background = Some(Background::Color(background)); + // appearance.text_color = text; + // appearance.icon_color = icon; - if let Button::IconInheritColors = style { - } else if focused { - appearance.text_color = cosmic.accent.on.into(); + if focused { + appearance.text_color = Some(cosmic.accent.on.into()); appearance.icon_color = Some(cosmic.accent.on.into()); - } else { - appearance.text_color = text; - appearance.icon_color = icon; } } Button::Link => { appearance.background = None; appearance.icon_color = Some(cosmic.accent.base.into()); - appearance.text_color = cosmic.accent.base.into(); + appearance.text_color = Some(cosmic.accent.base.into()); corner_radii = &cosmic.corner_radii.radius_0; } @@ -105,7 +102,7 @@ impl StyleSheet for crate::Theme { appearance(self, focused, style, |component| { ( component.base.into(), - component.on.into(), + Some(component.on.into()), Some(component.on.into()), ) }) @@ -121,7 +118,7 @@ impl StyleSheet for crate::Theme { background.a *= 0.5; ( background, - component.on_disabled.into(), + Some(component.on_disabled.into()), Some(component.on_disabled.into()), ) }) @@ -139,7 +136,7 @@ impl StyleSheet for crate::Theme { appearance(self, focused, style, |component| { ( component.hover.into(), - component.on.into(), + Some(component.on.into()), Some(component.on.into()), ) }) @@ -153,7 +150,7 @@ impl StyleSheet for crate::Theme { appearance(self, focused, style, |component| { ( component.pressed.into(), - component.on.into(), + Some(component.on.into()), Some(component.on.into()), ) }) diff --git a/src/widget/button/icon.rs b/src/widget/button/icon.rs index 1de2c84acdb..1fcd6455103 100644 --- a/src/widget/button/icon.rs +++ b/src/widget/button/icon.rs @@ -124,11 +124,6 @@ impl<'a, Message> Button<'a, Message> { self } - pub fn inherit_colors(mut self) -> Self { - self.style = Style::IconInheritColors; - self - } - pub fn vertical(mut self, vertical: bool) -> Self { self.variant.vertical = vertical; self.style = Style::IconVertical; diff --git a/src/widget/button/style.rs b/src/widget/button/style.rs index 5d105f31e03..8c4c998d748 100644 --- a/src/widget/button/style.rs +++ b/src/widget/button/style.rs @@ -23,9 +23,6 @@ pub struct Appearance { /// The border [`Color`] of the button. pub border_color: Color, - /// Opacity of the button. - pub opacity: f32, - /// An outline placed around the border. pub outline_width: f32, @@ -36,7 +33,7 @@ pub struct Appearance { pub icon_color: Option, /// The text [`Color`] of the button. - pub text_color: Color, + pub text_color: Option, } impl Appearance { @@ -48,11 +45,10 @@ impl Appearance { border_radius: BorderRadius::from(0.0), border_width: 0.0, border_color: Color::TRANSPARENT, - opacity: 1.0, outline_width: 0.0, outline_color: Color::TRANSPARENT, icon_color: None, - text_color: Color::BLACK, + text_color: None, } } } diff --git a/src/widget/button/widget.rs b/src/widget/button/widget.rs index 94691f7c0cb..7cd9fea4713 100644 --- a/src/widget/button/widget.rs +++ b/src/widget/button/widget.rs @@ -306,7 +306,7 @@ where theme, &renderer::Style { icon_color: styling.icon_color.unwrap_or(renderer_style.icon_color), - text_color: styling.text_color, + text_color: styling.text_color.unwrap_or(renderer_style.icon_color), scale_factor: renderer_style.scale_factor, }, content_layout, diff --git a/src/widget/header_bar.rs b/src/widget/header_bar.rs index 2152e6c06bc..ea0aeb297c4 100644 --- a/src/widget/header_bar.rs +++ b/src/widget/header_bar.rs @@ -168,7 +168,6 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> { widget::icon::from_name(name) .size(size) .apply(widget::button::icon) - .inherit_colors() .on_press(on_press) };