Skip to main content

cotis_defaults/element_configs/
style.rs

1//! Style structs used by [`crate::element_configs::ElementConfig`].
2use crate::colors::Color;
3#[cfg(feature = "complex_color")]
4use crate::colors::ColorLayer;
5use cotis_utils::math::{Dimensions, Vector2};
6#[cfg(feature = "serde")]
7use serde::{Deserialize, Serialize};
8
9/// Core style helper types such as alignment, padding and clip settings.
10pub mod types;
11use types::*;
12
13/// Sizing enums used by layout integrations.
14pub mod sizing;
15use sizing::*;
16
17/// Full style payload attached to each configured element.
18#[derive(Debug, Clone)]
19#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
20#[cfg_attr(not(feature = "complex_color"), derive(Copy))]
21pub struct CotisStyle<Sizing> {
22    /// Element sizing behavior used by the layout engine.
23    pub sizing: Sizing,
24    /// Child layout settings (direction, gap, padding, alignment).
25    pub layout: LayoutStyle,
26    /// Element background color.
27    #[cfg(not(feature = "complex_color"))]
28    pub background_color: Color,
29    /// Element background paint (solid/gradient/layered).
30    #[cfg(feature = "complex_color")]
31    pub background_color: ColorLayer,
32    /// Per-corner radius for rounded corners.
33    pub corner_radius: CornerRadiiStyle,
34    /// Optional floating behavior relative to parent bounds.
35    pub floating: Option<FloatingElementStyle>,
36    /// Clip behavior for element content.
37    pub clip: ClipElementConfig,
38    /// Border styling.
39    pub border: BorderElementStyle,
40}
41
42impl Default for CotisStyle<Sizing> {
43    /// Default style for `Sizing` enum-based integrations.
44    fn default() -> Self {
45        Self {
46            sizing: Sizing::DoubleAxis(DoubleAxisSizing {
47                width: AxisSizing::Fit(0.0, f32::MAX),
48                height: AxisSizing::Fit(0.0, f32::MAX),
49            }),
50            layout: Default::default(),
51            #[cfg(not(feature = "complex_color"))]
52            background_color: Color::rgba(0.0, 0.0, 0.0, 0.0),
53            #[cfg(feature = "complex_color")]
54            background_color: ColorLayer::Solid(Color::rgba(0.0, 0.0, 0.0, 0.0)),
55            corner_radius: CornerRadiiStyle {
56                top_left: 0.0,
57                top_right: 0.0,
58                bottom_left: 0.0,
59                bottom_right: 0.0,
60            },
61            floating: None,
62            clip: ClipElementConfig {
63                horizontal: false,
64                vertical: false,
65                child_offset: Default::default(),
66            },
67            border: BorderElementStyle {
68                color: Color::rgba(0.0, 0.0, 0.0, 0.0),
69                width: BorderWidthStyle {
70                    left: 0.0,
71                    right: 0.0,
72                    top: 0.0,
73                    bottom: 0.0,
74                    between_children: 0.0,
75                },
76            },
77        }
78    }
79}
80
81impl Default for CotisStyle<DoubleAxisSizing> {
82    /// Default style for direct `DoubleAxisSizing` integrations.
83    fn default() -> Self {
84        Self {
85            sizing: DoubleAxisSizing {
86                width: AxisSizing::Fit(0.0, f32::MAX),
87                height: AxisSizing::Fit(0.0, f32::MAX),
88            },
89            layout: Default::default(),
90            #[cfg(not(feature = "complex_color"))]
91            background_color: Color::rgba(0.0, 0.0, 0.0, 0.0),
92            #[cfg(feature = "complex_color")]
93            background_color: ColorLayer::Solid(Color::rgba(0.0, 0.0, 0.0, 0.0)),
94            corner_radius: CornerRadiiStyle {
95                top_left: 0.0,
96                top_right: 0.0,
97                bottom_left: 0.0,
98                bottom_right: 0.0,
99            },
100            floating: None,
101            clip: ClipElementConfig {
102                horizontal: false,
103                vertical: false,
104                child_offset: Default::default(),
105            },
106            border: BorderElementStyle {
107                color: Color::rgba(0.0, 0.0, 0.0, 0.0),
108                width: BorderWidthStyle {
109                    left: 0.0,
110                    right: 0.0,
111                    top: 0.0,
112                    bottom: 0.0,
113                    between_children: 0.0,
114                },
115            },
116        }
117    }
118}
119
120/// Defines individual corner radii for an element.
121#[derive(Debug, Clone, Copy, PartialEq)]
122#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
123pub struct CornerRadiiStyle {
124    /// The radius for the top-left corner.
125    pub top_left: f32,
126    /// The radius for the top-right corner.
127    pub top_right: f32,
128    /// The radius for the bottom-left corner.
129    pub bottom_left: f32,
130    /// The radius for the bottom-right corner.
131    pub bottom_right: f32,
132}
133
134/// Border style payload.
135#[derive(Debug, Copy, Clone, PartialEq)]
136#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
137pub struct BorderElementStyle {
138    /// Border color.
139    pub color: Color,
140    /// Per-side border widths.
141    pub width: BorderWidthStyle,
142}
143
144/// Border width values for each side.
145#[derive(Debug, Copy, Clone, PartialEq)]
146#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
147pub struct BorderWidthStyle {
148    /// Left border width.
149    pub left: f32,
150    /// Right border width.
151    pub right: f32,
152    /// Top border width.
153    pub top: f32,
154    /// Bottom border width.
155    pub bottom: f32,
156    /// Width used between sibling children.
157    pub between_children: f32,
158}
159
160/// Floating behavior for overlays/tooltips/popups.
161#[derive(Debug, Clone, Copy, PartialEq)]
162#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
163pub struct FloatingElementStyle {
164    /// Position offset relative to attachment point.
165    pub offset: Vector2,
166    /// Additional expansion of floating bounds.
167    pub expand: Dimensions,
168    /// Z-order offset used during rendering.
169    pub z_index: i16,
170    /// Anchor point on the parent.
171    pub attach_point: FloatingAttachPointType,
172    /// Pointer capture behavior.
173    pub pointer_capture_mode: PointerCaptureMode,
174}
175
176/// Layout styling for children.
177#[derive(Debug, Copy, Clone)]
178#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
179pub struct LayoutStyle {
180    /// Inner padding around child layout area.
181    pub padding: Padding,
182    /// Gap inserted between children.
183    pub child_gap: f32,
184    /// Child alignment along X and Y.
185    pub child_alignment: Alignment,
186    /// Primary direction used to place children.
187    pub layout_direction: LayoutDirection,
188    /// Experimental child-wrapping toggle.
189    ///
190    /// This field is feature-gated and currently not fully wired in all layout
191    /// integrations.
192    #[cfg(feature = "child_wrapping")]
193    pub child_wrapping: bool,
194}