Skip to main content

uzor_core/widgets/container/
theme.rs

1//! Container theme trait - Contract/Connector for scrollbar colors and dimensions
2//!
3//! # Architecture Role
4//!
5//! **ContainerTheme is a CONTRACT/CONNECTOR trait** that connects:
6//! - Factory rendering functions (`factory/render.rs`)
7//! - System theme managers (e.g., `AppTheme`, etc.)
8//!
9//! # How It Works
10//!
11//! ```text
12//! ┌─────────────────────────────────────────────────────────────┐
13//! │ 1. System Theme Manager (e.g., AppTheme)                   │
14//! │    - Stores actual color values                             │
15//! │    - Implements ContainerTheme trait (mapping)              │
16//! └─────────────────────────────────────────────────────────────┘
17//!                           ↓
18//! ┌─────────────────────────────────────────────────────────────┐
19//! │ 2. ContainerTheme 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 ContainerTheme                             │
27//! │    - Call trait methods to get colors/dimensions            │
28//! └─────────────────────────────────────────────────────────────┘
29//! ```
30//!
31//! # Implementation Example
32//!
33//! Each system theme manager implements ContainerTheme with proper color mapping:
34//!
35//! ```rust,ignore
36//! // In ui/render/theme.rs (or your theme module)
37//! impl ContainerTheme for AppTheme {
38//!     fn scrollbar_width(&self) -> f64 {
39//!         12.0
40//!     }
41//!
42//!     fn scrollbar_track_color(&self) -> [u8; 4] {
43//!         [30, 30, 30, 255]  // ← Map to your theme's scrollbar track color
44//!     }
45//!
46//!     fn scrollbar_thumb_color(&self) -> [u8; 4] {
47//!         [80, 80, 80, 255]  // ← Map to your theme's scrollbar thumb color
48//!     }
49//!     // ... rest of methods
50//! }
51//! ```
52//!
53//! # Usage in Factory
54//!
55//! ```rust,ignore
56//! use container::factory::render_default;
57//!
58//! let app_theme = AppTheme::default();
59//!
60//! // AppTheme automatically converts to &dyn ContainerTheme
61//! render_default(ctx, &container, &app_theme, &state, &input_handler, rect);
62//! //                               ↑ Any theme implementing ContainerTheme
63//! ```
64//!
65//! # Notes
66//!
67//! - **Not used in production inline rendering** - Terminal uses direct color access
68//! - **Used by factory for prototyping** - Enables factory to work with any theme
69//! - **Each project implements its own mapping** - No hardcoded theme assumptions
70
71/// Theme trait for container scrollbar colors and dimensions
72///
73/// This trait defines the color and dimension contract that any system theme
74/// must implement to work with factory rendering functions.
75///
76/// # Responsibility
77///
78/// **System theme managers** (e.g., AppTheme) implement this trait by:
79/// - Mapping their internal color fields to ContainerTheme methods
80/// - Providing appropriate colors for scrollbar states
81/// - Providing dimensions for scrollbar sizing
82///
83/// **Factory rendering** uses this trait by:
84/// - Accepting `&dyn ContainerTheme` parameter
85/// - Calling trait methods to get colors and dimensions
86/// - Working with ANY theme that implements this contract
87///
88/// # Default Theme
89///
90/// If you don't have a system theme yet, use `DefaultContainerTheme`:
91///
92/// ```rust,ignore
93/// use container::factory::render_default;
94/// use container::theme::DefaultContainerTheme;
95///
96/// let theme = DefaultContainerTheme::new();
97/// render_default(ctx, &container, &theme, &state, &input_handler, rect);
98/// ```
99///
100/// # Implementation Location
101///
102/// Implement this trait in the **same module as your system theme**:
103///
104/// ```rust,ignore
105/// // In ui/render/theme.rs (example for Terminal)
106/// pub struct AppTheme {
107///     pub scrollbar_track: [u8; 4],
108///     pub scrollbar_thumb: [u8; 4],
109///     pub scrollbar_hover: [u8; 4],
110///     // ... other theme fields
111/// }
112///
113/// impl ContainerTheme for AppTheme {
114///     fn scrollbar_width(&self) -> f64 { 12.0 }
115///     fn scrollbar_track_color(&self) -> [u8; 4] { self.scrollbar_track }
116///     fn scrollbar_thumb_color(&self) -> [u8; 4] { self.scrollbar_thumb }
117///     // ... map all methods to your theme fields
118/// }
119/// ```
120pub trait ContainerTheme {
121    // =========================================================================
122    // Scrollbar Dimensions
123    // =========================================================================
124
125    /// Scrollbar width in pixels
126    /// Typical: 12.0
127    fn scrollbar_width(&self) -> f64;
128
129    /// Minimum scrollbar thumb height in pixels
130    /// Typical: 20.0
131    fn min_thumb_height(&self) -> f64;
132
133    /// Container padding in pixels
134    /// Typical: 0.0
135    fn container_padding(&self) -> f64;
136
137    // =========================================================================
138    // Scrollbar Colors (RGBA)
139    // =========================================================================
140
141    /// Scrollbar track background color
142    /// Typical: rgba(30, 30, 30, 255) - dark grey
143    fn scrollbar_track_color(&self) -> [u8; 4];
144
145    /// Scrollbar thumb normal color
146    /// Typical: rgba(80, 80, 80, 255) - medium grey
147    fn scrollbar_thumb_color(&self) -> [u8; 4];
148
149    /// Scrollbar thumb hover color
150    /// Typical: rgba(100, 100, 100, 255) - lighter grey
151    fn scrollbar_hover_color(&self) -> [u8; 4];
152}
153
154// =============================================================================
155// Default Theme Implementation
156// =============================================================================
157
158/// Default container theme using inline spec colors
159///
160/// This theme provides the exact colors and dimensions from the inline specs
161/// (layout/render_ui.rs:246) for quick prototyping.
162///
163/// # Colors
164///
165/// - Track: rgba(30, 30, 30, 255)
166/// - Thumb: rgba(80, 80, 80, 255)
167/// - Hover: rgba(100, 100, 100, 255)
168///
169/// # Dimensions
170///
171/// - Scrollbar width: 12.0px
172/// - Min thumb height: 20.0px
173/// - Container padding: 0.0px
174///
175/// # Usage
176///
177/// ```rust,ignore
178/// use container::factory::render_default;
179/// use container::theme::DefaultContainerTheme;
180///
181/// let theme = DefaultContainerTheme::new();
182/// render_default(ctx, &container, &theme, &state, &input_handler, rect);
183/// ```
184///
185/// For production, implement ContainerTheme for your system theme instead.
186pub struct DefaultContainerTheme;
187
188impl DefaultContainerTheme {
189    pub fn new() -> Self {
190        Self
191    }
192}
193
194impl Default for DefaultContainerTheme {
195    fn default() -> Self {
196        Self::new()
197    }
198}
199
200impl ContainerTheme for DefaultContainerTheme {
201    // Dimensions (from inline specs)
202    fn scrollbar_width(&self) -> f64 {
203        12.0
204    }
205
206    fn min_thumb_height(&self) -> f64 {
207        20.0
208    }
209
210    fn container_padding(&self) -> f64 {
211        0.0
212    }
213
214    // Colors (from inline specs: layout/render_ui.rs:246)
215    fn scrollbar_track_color(&self) -> [u8; 4] {
216        [30, 30, 30, 255] // rgba(30, 30, 30, 255)
217    }
218
219    fn scrollbar_thumb_color(&self) -> [u8; 4] {
220        [80, 80, 80, 255] // rgba(80, 80, 80, 255)
221    }
222
223    fn scrollbar_hover_color(&self) -> [u8; 4] {
224        [100, 100, 100, 255] // rgba(100, 100, 100, 255)
225    }
226}