feat(segmented-button): Configurable background and hover styling

This commit is contained in:
Michael Aaron Murphy 2022-12-28 19:27:05 +01:00 committed by Ashley Wulber
parent f84410608b
commit 3454483345
3 changed files with 93 additions and 24 deletions

View file

@ -868,8 +868,10 @@ impl text_input::StyleSheet for Theme {
#[derive(Clone, Copy, Default)]
pub enum SegmentedButton {
/// A tabbed widget for switching between views in an interface.
#[default]
Default,
ViewSwitcher,
/// Or implement any custom theme of your liking.
Custom(fn(&Theme) -> segmented_button::Appearance)
}
@ -877,25 +879,41 @@ impl segmented_button::StyleSheet for Theme {
type Style = SegmentedButton;
fn appearance(&self, style: &Self::Style) -> segmented_button::Appearance {
if let SegmentedButton::Custom(func) = style {
return func(self);
}
let cosmic = self.cosmic();
segmented_button::Appearance {
button_active: segmented_button::ButtonAppearance {
background: Some(Background::Color(cosmic.primary.component.base.into())),
border_bottom: Some((4.0, cosmic.accent.base.into())),
border_radius: BorderRadius::from([8.0, 8.0, 0.0, 0.0]),
text_color: cosmic.accent.base.into(),
},
button_inactive: segmented_button::ButtonAppearance {
background: None,
border_bottom: Some((2.0, cosmic.accent.base.into())),
text_color: cosmic.primary.on.into(),
border_radius: BorderRadius::from(0.0),
match style {
SegmentedButton::ViewSwitcher => {
let cosmic = self.cosmic();
segmented_button::Appearance {
background: None,
border_color: Color::TRANSPARENT,
border_radius: BorderRadius::from(0.0),
border_width: 0.0,
button_active: segmented_button::ButtonAppearance {
background: Some(Background::Color(cosmic.primary.component.base.into())),
border_bottom: Some((4.0, cosmic.accent.base.into())),
border_radius_first: BorderRadius::from([8.0, 8.0, 0.0, 0.0]),
border_radius_last: BorderRadius::from([8.0, 8.0, 0.0, 0.0]),
border_radius_middle: BorderRadius::from([8.0, 8.0, 0.0, 0.0]),
text_color: cosmic.accent.base.into(),
},
button_inactive: segmented_button::ButtonAppearance {
background: None,
border_bottom: Some((1.0, cosmic.accent.base.into())),
border_radius_first: BorderRadius::from(0.0),
border_radius_last: BorderRadius::from(0.0),
border_radius_middle: BorderRadius::from(0.0),
text_color: cosmic.primary.on.into(),
},
button_hover: segmented_button::ButtonAppearance {
background: Some(Background::Color(cosmic.primary.component.hover.into())),
border_bottom: Some((1.0, cosmic.accent.base.into())),
border_radius_first: BorderRadius::from([8.0, 8.0, 0.0, 0.0]),
border_radius_last: BorderRadius::from([8.0, 8.0, 0.0, 0.0]),
border_radius_middle: BorderRadius::from([8.0, 8.0, 0.0, 0.0]),
text_color: cosmic.accent.base.into(),
}
}
}
SegmentedButton::Custom(func) => func(self)
}
}
}