cosmic/widget/
tab_bar.rs

1// Copyright 2023 System76 <info@system76.com>
2// SPDX-License-Identifier: MPL-2.0
3
4//! A collection of tabs for developing a tabbed interface.
5//!
6//! See the [`segmented_button`] module for more details.
7
8use super::segmented_button::{
9    self, HorizontalSegmentedButton, Model, SegmentedButton, Selectable, VerticalSegmentedButton,
10};
11
12/// A collection of tabs for developing a tabbed interface.
13///
14/// The data for the widget comes from a model supplied by 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_xs = crate::theme::spacing().space_xs;
25
26    segmented_button::horizontal(model)
27        .minimum_button_width(76)
28        .maximum_button_width(250)
29        .button_height(44)
30        .button_padding([space_s, space_xs, space_s, space_xs])
31        .style(crate::theme::SegmentedButton::TabBar)
32}
33
34/// A collection of tabs for developing a tabbed interface.
35///
36/// The data for the widget comes from a model that is maintained the application.
37/// For details on the model, see the [`segmented_button`] module for more details.
38pub fn vertical<SelectionMode, Message>(
39    model: &Model<SelectionMode>,
40) -> VerticalSegmentedButton<SelectionMode, Message>
41where
42    Model<SelectionMode>: Selectable,
43    SelectionMode: Default,
44{
45    let space_s = crate::theme::spacing().space_s;
46    let space_xs = crate::theme::spacing().space_xs;
47
48    SegmentedButton::new(model)
49        .minimum_button_width(76)
50        .maximum_button_width(250)
51        .button_height(44)
52        .button_padding([space_s, space_xs, space_s, space_xs])
53        .style(crate::theme::SegmentedButton::TabBar)
54}