refactor!: separate horizontal and vertical segmented button widgets

- Removes the orientation enum in favor of two separate widgets
- Implements the spacing attribute for both widgets
- Demo is updated to display spaced variants of the widgets
This commit is contained in:
Michael Aaron Murphy 2023-01-03 19:35:34 +01:00 committed by Michael Murphy
parent 3af1da6332
commit 444e389496
12 changed files with 969 additions and 547 deletions

View file

@ -1,16 +1,16 @@
// Copyright 2022 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0
use super::{SegmentedButton, State};
use super::{HorizontalSegmentedButton, State, VerticalSegmentedButton};
/// Appears as a collection of tabs for developing a tabbed interface.
///
/// The data for the widget comes from a [`State`] that is maintained the application.
#[must_use]
pub fn view_switcher<Message, Data>(
pub fn horizontal_view_switcher<Message, Data>(
state: &State<Data>,
) -> SegmentedButton<Message, crate::Renderer> {
SegmentedButton::new(&state.inner)
) -> HorizontalSegmentedButton<Message, crate::Renderer> {
HorizontalSegmentedButton::new(&state.inner)
.button_padding([16, 0, 16, 0])
.button_height(48)
.style(crate::theme::SegmentedButton::ViewSwitcher)
@ -21,12 +21,40 @@ pub fn view_switcher<Message, Data>(
///
/// The data for the widget comes from a [`State`] that is maintained the application.
#[must_use]
pub fn segmented_selection<Message, Data>(
pub fn horizontal_segmented_selection<Message, Data>(
state: &State<Data>,
) -> SegmentedButton<Message, crate::Renderer> {
SegmentedButton::new(&state.inner)
) -> HorizontalSegmentedButton<Message, crate::Renderer> {
HorizontalSegmentedButton::new(&state.inner)
.button_padding([16, 0, 16, 0])
.button_height(32)
.style(crate::theme::SegmentedButton::Selection)
.font_active(crate::font::FONT_SEMIBOLD)
}
/// Appears as a selection of choices for choosing between.
///
/// The data for the widget comes from a [`State`] that is maintained the application.
#[must_use]
pub fn vertical_segmented_selection<Message, Data>(
state: &State<Data>,
) -> VerticalSegmentedButton<Message, crate::Renderer> {
VerticalSegmentedButton::new(&state.inner)
.button_padding([16, 0, 16, 0])
.button_height(32)
.style(crate::theme::SegmentedButton::Selection)
.font_active(crate::font::FONT_SEMIBOLD)
}
/// Appears as a collection of tabs for developing a tabbed interface.
///
/// The data for the widget comes from a [`State`] that is maintained the application.
#[must_use]
pub fn vertical_view_switcher<Message, Data>(
state: &State<Data>,
) -> VerticalSegmentedButton<Message, crate::Renderer> {
VerticalSegmentedButton::new(&state.inner)
.button_padding([16, 0, 16, 0])
.button_height(48)
.style(crate::theme::SegmentedButton::ViewSwitcher)
.font_active(crate::font::FONT_SEMIBOLD)
}