cosmic/widget/button/
style.rs1use iced_core::{Background, Color, Vector, border::Radius};
6
7use crate::theme::THEME;
8
9#[must_use]
11#[derive(Debug, Clone, Copy)]
12pub struct Style {
13 pub shadow_offset: Vector,
15
16 pub background: Option<Background>,
18
19 pub overlay: Option<Background>,
21
22 pub border_radius: Radius,
24
25 pub border_width: f32,
27
28 pub border_color: Color,
30
31 pub outline_width: f32,
33
34 pub outline_color: Color,
36
37 pub icon_color: Option<Color>,
39
40 pub text_color: Option<Color>,
42}
43
44impl Style {
45 pub fn new() -> Self {
47 let rad_0 = THEME.lock().unwrap().cosmic().corner_radii.radius_0;
48 Self {
49 shadow_offset: Vector::new(0.0, 0.0),
50 background: None,
51 border_radius: Radius::from(rad_0),
52 border_width: 0.0,
53 border_color: Color::TRANSPARENT,
54 outline_width: 0.0,
55 outline_color: Color::TRANSPARENT,
56 icon_color: None,
57 text_color: None,
58 overlay: None,
59 }
60 }
61}
62
63impl std::default::Default for Style {
64 fn default() -> Self {
65 Self::new()
66 }
67}
68
69pub trait Catalog {
72 type Class: Default;
74
75 fn active(&self, focused: bool, selected: bool, style: &Self::Class) -> Style;
77
78 fn disabled(&self, style: &Self::Class) -> Style;
80
81 fn drop_target(&self, style: &Self::Class) -> Style {
83 self.hovered(false, false, style)
84 }
85
86 fn hovered(&self, focused: bool, selected: bool, style: &Self::Class) -> Style;
88
89 fn pressed(&self, focused: bool, selected: bool, style: &Self::Class) -> Style;
91
92 fn selection_background(&self) -> Background;
94}