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,
|
Destructive,
|
||||||
Link,
|
Link,
|
||||||
Icon,
|
Icon,
|
||||||
IconInheritColors,
|
|
||||||
IconVertical,
|
IconVertical,
|
||||||
#[default]
|
#[default]
|
||||||
Standard,
|
Standard,
|
||||||
|
|
@ -32,7 +31,7 @@ pub fn appearance(
|
||||||
theme: &crate::Theme,
|
theme: &crate::Theme,
|
||||||
focused: bool,
|
focused: bool,
|
||||||
style: &Button,
|
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 {
|
) -> Appearance {
|
||||||
let cosmic = theme.cosmic();
|
let cosmic = theme.cosmic();
|
||||||
let mut corner_radii = &cosmic.corner_radii.radius_xl;
|
let mut corner_radii = &cosmic.corner_radii.radius_xl;
|
||||||
|
|
@ -54,28 +53,26 @@ pub fn appearance(
|
||||||
appearance.icon_color = icon;
|
appearance.icon_color = icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
Button::Icon | Button::IconInheritColors | Button::IconVertical => {
|
Button::Icon | Button::IconVertical => {
|
||||||
if let Button::IconVertical = style {
|
if let Button::IconVertical = style {
|
||||||
corner_radii = &cosmic.corner_radii.radius_m;
|
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.background = Some(Background::Color(background));
|
||||||
|
// appearance.text_color = text;
|
||||||
|
// appearance.icon_color = icon;
|
||||||
|
|
||||||
if let Button::IconInheritColors = style {
|
if focused {
|
||||||
} else if focused {
|
appearance.text_color = Some(cosmic.accent.on.into());
|
||||||
appearance.text_color = cosmic.accent.on.into();
|
|
||||||
appearance.icon_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 => {
|
Button::Link => {
|
||||||
appearance.background = None;
|
appearance.background = None;
|
||||||
appearance.icon_color = Some(cosmic.accent.base.into());
|
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;
|
corner_radii = &cosmic.corner_radii.radius_0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,7 +102,7 @@ impl StyleSheet for crate::Theme {
|
||||||
appearance(self, focused, style, |component| {
|
appearance(self, focused, style, |component| {
|
||||||
(
|
(
|
||||||
component.base.into(),
|
component.base.into(),
|
||||||
component.on.into(),
|
Some(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.a *= 0.5;
|
||||||
(
|
(
|
||||||
background,
|
background,
|
||||||
component.on_disabled.into(),
|
Some(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| {
|
appearance(self, focused, style, |component| {
|
||||||
(
|
(
|
||||||
component.hover.into(),
|
component.hover.into(),
|
||||||
component.on.into(),
|
Some(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| {
|
appearance(self, focused, style, |component| {
|
||||||
(
|
(
|
||||||
component.pressed.into(),
|
component.pressed.into(),
|
||||||
component.on.into(),
|
Some(component.on.into()),
|
||||||
Some(component.on.into()),
|
Some(component.on.into()),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -124,11 +124,6 @@ impl<'a, Message> Button<'a, Message> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn inherit_colors(mut self) -> Self {
|
|
||||||
self.style = Style::IconInheritColors;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn vertical(mut self, vertical: bool) -> Self {
|
pub fn vertical(mut self, vertical: bool) -> Self {
|
||||||
self.variant.vertical = vertical;
|
self.variant.vertical = vertical;
|
||||||
self.style = Style::IconVertical;
|
self.style = Style::IconVertical;
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,6 @@ pub struct Appearance {
|
||||||
/// The border [`Color`] of the button.
|
/// The border [`Color`] of the button.
|
||||||
pub border_color: Color,
|
pub border_color: Color,
|
||||||
|
|
||||||
/// Opacity of the button.
|
|
||||||
pub opacity: f32,
|
|
||||||
|
|
||||||
/// An outline placed around the border.
|
/// An outline placed around the border.
|
||||||
pub outline_width: f32,
|
pub outline_width: f32,
|
||||||
|
|
||||||
|
|
@ -36,7 +33,7 @@ pub struct Appearance {
|
||||||
pub icon_color: Option<Color>,
|
pub icon_color: Option<Color>,
|
||||||
|
|
||||||
/// The text [`Color`] of the button.
|
/// The text [`Color`] of the button.
|
||||||
pub text_color: Color,
|
pub text_color: Option<Color>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Appearance {
|
impl Appearance {
|
||||||
|
|
@ -48,11 +45,10 @@ impl Appearance {
|
||||||
border_radius: BorderRadius::from(0.0),
|
border_radius: BorderRadius::from(0.0),
|
||||||
border_width: 0.0,
|
border_width: 0.0,
|
||||||
border_color: Color::TRANSPARENT,
|
border_color: Color::TRANSPARENT,
|
||||||
opacity: 1.0,
|
|
||||||
outline_width: 0.0,
|
outline_width: 0.0,
|
||||||
outline_color: Color::TRANSPARENT,
|
outline_color: Color::TRANSPARENT,
|
||||||
icon_color: None,
|
icon_color: None,
|
||||||
text_color: Color::BLACK,
|
text_color: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -306,7 +306,7 @@ where
|
||||||
theme,
|
theme,
|
||||||
&renderer::Style {
|
&renderer::Style {
|
||||||
icon_color: styling.icon_color.unwrap_or(renderer_style.icon_color),
|
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,
|
scale_factor: renderer_style.scale_factor,
|
||||||
},
|
},
|
||||||
content_layout,
|
content_layout,
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,6 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
|
||||||
widget::icon::from_name(name)
|
widget::icon::from_name(name)
|
||||||
.size(size)
|
.size(size)
|
||||||
.apply(widget::button::icon)
|
.apply(widget::button::icon)
|
||||||
.inherit_colors()
|
|
||||||
.on_press(on_press)
|
.on_press(on_press)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue