uzor_core/widgets/button/theme.rs
1//! Button theme trait - Contract/Connector for button colors
2//!
3//! # Architecture Role
4//!
5//! **ButtonTheme is a CONTRACT/CONNECTOR trait** that connects:
6//! - Factory rendering functions (`factory/render.rs`)
7//! - System theme managers (e.g., `ToolbarTheme`, `AppTheme`, etc.)
8//!
9//! # How It Works
10//!
11//! ```text
12//! ┌─────────────────────────────────────────────────────────┐
13//! │ 1. System Theme Manager (e.g., ToolbarTheme) │
14//! │ - Stores actual color values │
15//! │ - Implements ButtonTheme trait (mapping) │
16//! └─────────────────────────────────────────────────────────┘
17//! ↓
18//! ┌─────────────────────────────────────────────────────────┐
19//! │ 2. ButtonTheme trait (THIS MODULE) │
20//! │ - Defines contract (which methods/colors needed) │
21//! │ - Acts as connector interface │
22//! └─────────────────────────────────────────────────────────┘
23//! ↓
24//! ┌─────────────────────────────────────────────────────────┐
25//! │ 3. Factory render functions (factory/render.rs) │
26//! │ - Accept &dyn ButtonTheme │
27//! │ - Call trait methods to get colors │
28//! └─────────────────────────────────────────────────────────┘
29//! ```
30
31/// Theme trait for button colors - Contract between system themes and factory rendering
32pub trait ButtonTheme {
33 // =========================================================================
34 // Background colors
35 // =========================================================================
36
37 /// Normal state background color
38 /// Typical: "transparent" or "#1e222d"
39 fn button_bg_normal(&self) -> &str;
40
41 /// Hover state background color
42 /// Typical: "#2a2a2a"
43 fn button_bg_hover(&self) -> &str;
44
45 /// Pressed state background color
46 /// Typical: "#1e3a5f"
47 fn button_bg_pressed(&self) -> &str;
48
49 /// Active/toggled state background color
50 /// Typical: "#1e3a5f"
51 fn button_bg_active(&self) -> &str;
52
53 /// Disabled state background color
54 /// Typical: "#3a3a3a"
55 fn button_bg_disabled(&self) -> &str;
56
57 // =========================================================================
58 // Text colors
59 // =========================================================================
60
61 /// Normal state text color
62 /// Typical: "#787b86"
63 fn button_text_normal(&self) -> &str;
64
65 /// Hover state text color
66 /// Typical: "#ffffff"
67 fn button_text_hover(&self) -> &str;
68
69 /// Active state text color
70 /// Typical: "#ffffff"
71 fn button_text_active(&self) -> &str;
72
73 /// Disabled state text color
74 /// Typical: "#4a4a4a"
75 fn button_text_disabled(&self) -> &str;
76
77 // =========================================================================
78 // Icon colors
79 // =========================================================================
80
81 /// Normal state icon color
82 /// Typical: "#787b86"
83 fn button_icon_normal(&self) -> &str;
84
85 /// Hover state icon color
86 /// Typical: "#ffffff"
87 fn button_icon_hover(&self) -> &str;
88
89 /// Active state icon color
90 /// Typical: "#ffffff"
91 fn button_icon_active(&self) -> &str;
92
93 /// Disabled state icon color
94 /// Typical: "#4a4a4a"
95 fn button_icon_disabled(&self) -> &str;
96
97 // =========================================================================
98 // Border colors
99 // =========================================================================
100
101 /// Normal state border color
102 /// Typical: "#3a3a3a"
103 fn button_border_normal(&self) -> &str;
104
105 /// Hover state border color
106 /// Typical: "#2a2a2a"
107 fn button_border_hover(&self) -> &str;
108
109 /// Focused state border color
110 /// Typical: "#1e3a5f"
111 fn button_border_focused(&self) -> &str;
112
113 // =========================================================================
114 // Semantic colors
115 // =========================================================================
116
117 /// Primary/accent color for primary actions and active state
118 /// Typical: "#2962ff"
119 fn button_accent(&self) -> &str;
120
121 /// Danger color for delete/remove actions
122 /// Typical: "#ef4444"
123 fn button_danger(&self) -> &str;
124
125 /// Success color for confirm/success actions
126 /// Typical: "#10b981"
127 fn button_success(&self) -> &str;
128
129 /// Warning color for warning actions
130 /// Typical: "#f59e0b"
131 fn button_warning(&self) -> &str;
132}
133
134// =============================================================================
135// Default Theme Implementation
136// =============================================================================
137
138/// Default button theme using prototype colors
139pub struct DefaultButtonTheme;
140
141impl DefaultButtonTheme {
142 pub fn new() -> Self {
143 Self
144 }
145}
146
147impl Default for DefaultButtonTheme {
148 fn default() -> Self {
149 Self::new()
150 }
151}
152
153impl ButtonTheme for DefaultButtonTheme {
154 // Background colors
155 fn button_bg_normal(&self) -> &str { "transparent" }
156 fn button_bg_hover(&self) -> &str { "#2a2a2a" }
157 fn button_bg_pressed(&self) -> &str { "#1e3a5f" }
158 fn button_bg_active(&self) -> &str { "#1e3a5f" }
159 fn button_bg_disabled(&self) -> &str { "#2a2a2a" }
160
161 // Text colors
162 fn button_text_normal(&self) -> &str { "#d1d5db" }
163 fn button_text_hover(&self) -> &str { "#ffffff" }
164 fn button_text_active(&self) -> &str { "#ffffff" }
165 fn button_text_disabled(&self) -> &str { "#4a4a4a" }
166
167 // Icon colors
168 fn button_icon_normal(&self) -> &str { "#787b86" }
169 fn button_icon_hover(&self) -> &str { "#e5e7eb" }
170 fn button_icon_active(&self) -> &str { "#ffffff" }
171 fn button_icon_disabled(&self) -> &str { "#4a4a4a" }
172
173 // Border colors
174 fn button_border_normal(&self) -> &str { "#3a3a3a" }
175 fn button_border_hover(&self) -> &str { "#e5e7eb" }
176 fn button_border_focused(&self) -> &str { "#2962ff" }
177
178 // Semantic colors
179 fn button_accent(&self) -> &str { "#2962ff" }
180 fn button_danger(&self) -> &str { "#ef5350" }
181 fn button_success(&self) -> &str { "#10b981" }
182 fn button_warning(&self) -> &str { "#f59e0b" }
183}