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        .font_active(Some(crate::font::semibold()))
33}
34
35/// A collection of tabs for developing a tabbed interface.
36///
37/// The data for the widget comes from a model that is maintained the application.
38/// For details on the model, see the [`segmented_button`] module for more details.
39pub fn vertical<SelectionMode, Message>(
40    model: &Model<SelectionMode>,
41) -> VerticalSegmentedButton<SelectionMode, Message>
42where
43    Model<SelectionMode>: Selectable,
44    SelectionMode: Default,
45{
46    let space_s = crate::theme::spacing().space_s;
47    let space_xs = crate::theme::spacing().space_xs;
48
49    SegmentedButton::new(model)
50        .minimum_button_width(76)
51        .maximum_button_width(250)
52        .button_height(44)
53        .button_padding([space_s, space_xs, space_s, space_xs])
54        .style(crate::theme::SegmentedButton::TabBar)
55        .font_active(Some(crate::font::semibold()))
56}