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        .font_active(Some(crate::font::semibold()))
34}
35
36/// A selection of multiple choices appearing as a conjoined button.
37///
38/// The data for the widget comes from a model that is maintained the application.
39///
40/// For details on the model, see the [`segmented_button`] module for more details.
41pub fn vertical<SelectionMode, Message>(
42    model: &Model<SelectionMode>,
43) -> VerticalSegmentedButton<SelectionMode, Message>
44where
45    Model<SelectionMode>: Selectable,
46    SelectionMode: Default,
47{
48    let space_s = crate::theme::spacing().space_s;
49    let space_xxs = crate::theme::spacing().space_xxs;
50
51    segmented_button::vertical(model)
52        .button_alignment(iced::Alignment::Center)
53        .dividers(true)
54        .button_height(32)
55        .button_padding([space_s, 0, space_s, 0])
56        .button_spacing(space_xxs)
57        .style(crate::theme::SegmentedButton::Control)
58        .font_active(Some(crate::font::semibold()))
59}