fix(widget): allow None for button text color to inherit from container
This commit is contained in:
parent
6acdba28aa
commit
b404497e76
5 changed files with 15 additions and 28 deletions
|
|
@ -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<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;
|
||||
|
|
@ -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()),
|
||||
)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<Color>,
|
||||
|
||||
/// The text [`Color`] of the button.
|
||||
pub text_color: Color,
|
||||
pub text_color: Option<Color>,
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue