Skip to content

Commit

Permalink
fix(widget): allow None for button text color to inherit from conta…
Browse files Browse the repository at this point in the history
…iner
  • Loading branch information
mmstick committed Sep 18, 2023
1 parent 6acdba2 commit b404497
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 28 deletions.
27 changes: 12 additions & 15 deletions src/theme/style/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub enum Button {
Destructive,
Link,
Icon,
IconInheritColors,
IconVertical,
#[default]
Standard,
Expand All @@ -32,7 +31,7 @@ pub fn appearance(
theme: &crate::Theme,
focused: bool,
style: &Button,
color: impl Fn(&Component<Alpha<Rgb, f32>>) -> (Color, Color, Option<Color>),
color: impl Fn(&Component<Alpha<Rgb, f32>>) -> (Color, Option<Color>, Option<Color>),
) -> Appearance {
let cosmic = theme.cosmic();
let mut corner_radii = &cosmic.corner_radii.radius_xl;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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()),
)
})
Expand All @@ -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()),
)
})
Expand All @@ -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()),
)
})
Expand All @@ -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()),
)
})
Expand Down
5 changes: 0 additions & 5 deletions src/widget/button/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 2 additions & 6 deletions src/widget/button/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -36,7 +33,7 @@ pub struct Appearance {
pub icon_color: Option<Color>,

/// The text [`Color`] of the button.
pub text_color: Color,
pub text_color: Option<Color>,
}

impl Appearance {
Expand All @@ -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,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/widget/button/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/widget/header_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};

Expand Down

0 comments on commit b404497

Please sign in to comment.