cosmic/widget/segmented_button/
style.rs

1// Copyright 2022 System76 <info@system76.com>
2// SPDX-License-Identifier: MPL-2.0
3
4use iced_core::{Background, Color, border::Radius};
5
6/// Appearance of the segmented button.
7#[derive(Default, Clone, Copy)]
8pub struct Appearance {
9    pub background: Option<Background>,
10    pub border_radius: Radius,
11    pub border_bottom: Option<(f32, Color)>,
12    pub border_end: Option<(f32, Color)>,
13    pub border_start: Option<(f32, Color)>,
14    pub border_top: Option<(f32, Color)>,
15    pub active: ItemStatusAppearance,
16    pub inactive: ItemStatusAppearance,
17    pub hover: ItemStatusAppearance,
18    pub focus: ItemStatusAppearance,
19}
20
21/// Appearance of an item in the segmented button.
22#[derive(Default, Clone, Copy)]
23pub struct ItemAppearance {
24    pub border_radius: Radius,
25    pub border_bottom: Option<(f32, Color)>,
26    pub border_end: Option<(f32, Color)>,
27    pub border_start: Option<(f32, Color)>,
28    pub border_top: Option<(f32, Color)>,
29}
30
31/// Appearance of an item based on its status.
32#[derive(Default, Clone, Copy)]
33pub struct ItemStatusAppearance {
34    pub background: Option<Background>,
35    pub first: ItemAppearance,
36    pub middle: ItemAppearance,
37    pub last: ItemAppearance,
38    pub text_color: Color,
39}
40
41/// Defines the [`Appearance`] of a segmented button.
42pub trait StyleSheet {
43    /// The supported style of the [`StyleSheet`].
44    type Style: Default;
45
46    /// The horizontal [`Appearance`] of the segmented button.
47    fn horizontal(&self, style: &Self::Style) -> Appearance;
48
49    /// The vertical [`Appearance`] of the segmented button.
50    fn vertical(&self, style: &Self::Style) -> Appearance;
51}