feat(segmented-button): Vertical orientation functionality

This commit is contained in:
Michael Aaron Murphy 2022-12-30 17:39:35 +01:00 committed by Ashley Wulber
parent de580ffefc
commit ad0443af3f
6 changed files with 166 additions and 49 deletions

View file

@ -27,6 +27,7 @@ use iced_style::svg;
use iced_style::text;
use iced_style::text_input;
use iced_style::toggler;
use crate::widget::Orientation;
use crate::widget::segmented_button;
use iced_core::{Background, Color};
@ -880,7 +881,7 @@ pub enum SegmentedButton {
impl segmented_button::StyleSheet for Theme {
type Style = SegmentedButton;
fn appearance(&self, style: &Self::Style) -> segmented_button::Appearance {
fn appearance(&self, style: &Self::Style, orientation: Orientation) -> segmented_button::Appearance {
match style {
SegmentedButton::ViewSwitcher => {
let cosmic = self.cosmic();
@ -915,7 +916,7 @@ impl segmented_button::StyleSheet for Theme {
}
}
}
SegmentedButton::Selection => {
SegmentedButton::Selection if orientation == Orientation::Horizontal => {
let cosmic = self.cosmic();
segmented_button::Appearance {
background: None,
@ -948,6 +949,39 @@ impl segmented_button::StyleSheet for Theme {
}
}
}
SegmentedButton::Selection => {
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.secondary.component.divider.into())),
border_bottom: None,
border_radius_first: BorderRadius::from([24.0, 24.0, 0.0, 0.0]),
border_radius_last: BorderRadius::from([0.0, 0.0, 24.0, 24.0]),
border_radius_middle: BorderRadius::from(0.0),
text_color: cosmic.accent.base.into(),
},
button_inactive: segmented_button::ButtonAppearance {
background: Some(Background::Color(cosmic.secondary.component.base.into())),
border_bottom: None,
border_radius_first: BorderRadius::from([24.0, 24.0, 0.0, 0.0]),
border_radius_last: BorderRadius::from([0.0, 0.0, 24.0, 24.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: None,
border_radius_first: BorderRadius::from([24.0, 24.0, 0.0, 0.0]),
border_radius_last: BorderRadius::from([0.0, 0.0, 24.0, 24.0]),
border_radius_middle: BorderRadius::from(0.0),
text_color: cosmic.accent.base.into(),
}
}
}
SegmentedButton::Custom(func) => func(self)
}
}