cosmic/widget/button/
style.rs1use iced_core::border::Radius;
6use iced_core::{Background, Color, Vector};
7
8use crate::theme::THEME;
9
10#[must_use]
12#[derive(Debug, Clone, Copy)]
13pub struct Style {
14 pub shadow_offset: Vector,
16
17 pub background: Option<Background>,
19
20 pub overlay: Option<Background>,
22
23 pub border_radius: Radius,
25
26 pub border_width: f32,
28
29 pub border_color: Color,
31
32 pub outline_width: f32,
34
35 pub outline_color: Color,
37
38 pub icon_color: Option<Color>,
40
41 pub text_color: Option<Color>,
43}
44
45impl Style {
46 pub fn new() -> Self {
48 let rad_0 = THEME.lock().unwrap().cosmic().corner_radii.radius_0;
49 Self {
50 shadow_offset: Vector::new(0.0, 0.0),
51 background: None,
52 border_radius: Radius::from(rad_0),
53 border_width: 0.0,
54 border_color: Color::TRANSPARENT,
55 outline_width: 0.0,
56 outline_color: Color::TRANSPARENT,
57 icon_color: None,
58 text_color: None,
59 overlay: None,
60 }
61 }
62}
63
64impl std::default::Default for Style {
65 fn default() -> Self {
66 Self::new()
67 }
68}
69
70pub trait Catalog {
73 type Class: Default;
75
76 fn active(&self, focused: bool, selected: bool, style: &Self::Class) -> Style;
78
79 fn disabled(&self, style: &Self::Class) -> Style;
81
82 fn drop_target(&self, style: &Self::Class) -> Style {
84 self.hovered(false, false, style)
85 }
86
87 fn hovered(&self, focused: bool, selected: bool, style: &Self::Class) -> Style;
89
90 fn pressed(&self, focused: bool, selected: bool, style: &Self::Class) -> Style;
92
93 fn selection_background(&self) -> Background;
95}