fix(button): icon style variant to inherit colors from container
This commit is contained in:
parent
2e11d62de5
commit
c2d62bad52
3 changed files with 13 additions and 3 deletions
|
|
@ -20,6 +20,7 @@ pub enum Button {
|
||||||
Destructive,
|
Destructive,
|
||||||
Link,
|
Link,
|
||||||
Icon,
|
Icon,
|
||||||
|
IconInheritColors,
|
||||||
IconVertical,
|
IconVertical,
|
||||||
#[default]
|
#[default]
|
||||||
Standard,
|
Standard,
|
||||||
|
|
@ -53,14 +54,16 @@ pub fn appearance(
|
||||||
appearance.icon_color = icon;
|
appearance.icon_color = icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
Button::Icon | Button::IconVertical => {
|
Button::Icon | Button::IconInheritColors | 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));
|
||||||
if focused {
|
|
||||||
|
if let Button::IconInheritColors = style {
|
||||||
|
} else if focused {
|
||||||
appearance.text_color = 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 {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,11 @@ 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;
|
||||||
|
|
@ -162,6 +167,8 @@ impl<'a, Message: Clone + 'static> From<Button<'a, Message>> for Element<'a, Mes
|
||||||
let button = if builder.variant.vertical {
|
let button = if builder.variant.vertical {
|
||||||
crate::widget::column::with_children(content)
|
crate::widget::column::with_children(content)
|
||||||
.padding(builder.padding)
|
.padding(builder.padding)
|
||||||
|
// .width(builder.width)
|
||||||
|
// .height(builder.height)
|
||||||
.spacing(builder.spacing)
|
.spacing(builder.spacing)
|
||||||
.align_items(Alignment::Center)
|
.align_items(Alignment::Center)
|
||||||
.apply(button)
|
.apply(button)
|
||||||
|
|
|
||||||
|
|
@ -167,8 +167,8 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
|
||||||
let icon = |name, size, on_press| {
|
let icon = |name, size, on_press| {
|
||||||
widget::icon::from_name(name)
|
widget::icon::from_name(name)
|
||||||
.size(size)
|
.size(size)
|
||||||
.handle()
|
|
||||||
.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