cosmic/widget/
segmented_control.rs

1// Copyright 2023 System76 <info@system76.com>
2// SPDX-License-Identifier: MPL-2.0
3
4//! A selection of multiple choices appearing as a conjoined button.
5//!
6//! See the [`segmented_button`] module for more details.
7
8use super::segmented_button::{
9    self, HorizontalSegmentedButton, Model, Selectable, VerticalSegmentedButton,
10};
11
12/// A selection of multiple choices appearing as a conjoined button.
13///
14/// The data for the widget comes from a model that is maintained the application.
15///
16/// For details on the model, see the [`segmented_button`] module for more details.
17pub fn horizontal<SelectionMode: Default, Message>(
18    model: &Model<SelectionMode>,
19) -> HorizontalSegmentedButton<SelectionMode, Message>
20where
21    Model<SelectionMode>: Selectable,
22{
23    let space_s = crate::theme::spacing().space_s;
24    let space_xxs = crate::theme::spacing().space_xxs;
25
26    segmented_button::horizontal(model)
27        .button_alignment(iced::Alignment::Center)
28        .dividers(true)
29        .button_height(32)
30        .button_padding([space_s, 0, space_s, 0])
31        .button_spacing(space_xxs)
32        .style(crate::theme::SegmentedButton::Control)
33}
34
35/// A selection of multiple choices appearing as a conjoined button.
36///
37/// The data for the widget comes from a model that is maintained the application.
38///
39/// For details on the model, see the [`segmented_button`] module for more details.
40pub fn vertical<SelectionMode, Message>(
41    model: &Model<SelectionMode>,
42) -> VerticalSegmentedButton<SelectionMode, Message>
43where
44    Model<SelectionMode>: Selectable,
45    SelectionMode: Default,
46{
47    let space_s = crate::theme::spacing().space_s;
48    let space_xxs = crate::theme::spacing().space_xxs;
49
50    segmented_button::vertical(model)
51        .button_alignment(iced::Alignment::Center)
52        .dividers(true)
53        .button_height(32)
54        .button_padding([space_s, 0, space_s, 0])
55        .button_spacing(space_xxs)
56        .style(crate::theme::SegmentedButton::Control)
57}