cotis_defaults/element_configs/
style.rs1use crate::colors::{Color, ColorLayer};
3use cotis_utils::math::{Dimensions, Vector2};
4#[cfg(feature = "serde")]
5use serde::{Deserialize, Serialize};
6
7pub mod types;
9use types::*;
10
11pub mod sizing;
13use sizing::*;
14
15#[cfg(feature = "complex_color")]
21pub const TRANSPARENT_BACKGROUND: ColorLayer = ColorLayer::Solid(Color::rgba(0.0, 0.0, 0.0, 0.0));
22#[cfg(not(feature = "complex_color"))]
23pub const TRANSPARENT_BACKGROUND: ColorLayer = ColorLayer::Solid(Color::rgba(0.0, 0.0, 0.0, 0.0));
24
25#[cfg(feature = "complex_color")]
30pub const BLACK_BACKGROUND: ColorLayer = ColorLayer::Solid(Color::rgba(0.0, 0.0, 0.0, 255.0));
31#[cfg(not(feature = "complex_color"))]
32pub const BLACK_BACKGROUND: ColorLayer = ColorLayer::Solid(Color::rgba(0.0, 0.0, 0.0, 255.0));
33
34#[derive(Debug, Clone)]
36#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
37#[cfg_attr(not(feature = "complex_color"), derive(Copy))]
38pub struct CotisStyle<Sizing> {
39 pub sizing: Sizing,
41 pub layout: LayoutStyle,
43 #[cfg(not(feature = "complex_color"))]
45 pub background_color: Color,
46 #[cfg(feature = "complex_color")]
48 pub background_color: ColorLayer,
49 pub corner_radius: CornerRadiiStyle,
51 pub floating: Option<FloatingElementStyle>,
53 pub clip: ClipElementConfig,
55 pub border: BorderElementStyle,
57}
58
59impl Default for CotisStyle<Sizing> {
60 fn default() -> Self {
62 Self {
63 sizing: Sizing::DoubleAxis(DoubleAxisSizing {
64 width: AxisSizing::Fit(0.0, f32::MAX),
65 height: AxisSizing::Fit(0.0, f32::MAX),
66 }),
67 layout: Default::default(),
68 #[cfg(not(feature = "complex_color"))]
69 background_color: Color::rgba(0.0, 0.0, 0.0, 0.0),
70 #[cfg(feature = "complex_color")]
71 background_color: ColorLayer::Solid(Color::rgba(0.0, 0.0, 0.0, 0.0)),
72 corner_radius: CornerRadiiStyle {
73 top_left: 0.0,
74 top_right: 0.0,
75 bottom_left: 0.0,
76 bottom_right: 0.0,
77 },
78 floating: None,
79 clip: ClipElementConfig {
80 horizontal: false,
81 vertical: false,
82 child_offset: Default::default(),
83 },
84 border: BorderElementStyle {
85 color: Color::rgba(0.0, 0.0, 0.0, 0.0),
86 width: BorderWidthStyle {
87 left: 0.0,
88 right: 0.0,
89 top: 0.0,
90 bottom: 0.0,
91 between_children: 0.0,
92 },
93 },
94 }
95 }
96}
97
98impl Default for CotisStyle<DoubleAxisSizing> {
99 fn default() -> Self {
101 Self {
102 sizing: DoubleAxisSizing {
103 width: AxisSizing::Fit(0.0, f32::MAX),
104 height: AxisSizing::Fit(0.0, f32::MAX),
105 },
106 layout: Default::default(),
107 #[cfg(not(feature = "complex_color"))]
108 background_color: Color::rgba(0.0, 0.0, 0.0, 0.0),
109 #[cfg(feature = "complex_color")]
110 background_color: ColorLayer::Solid(Color::rgba(0.0, 0.0, 0.0, 0.0)),
111 corner_radius: CornerRadiiStyle {
112 top_left: 0.0,
113 top_right: 0.0,
114 bottom_left: 0.0,
115 bottom_right: 0.0,
116 },
117 floating: None,
118 clip: ClipElementConfig {
119 horizontal: false,
120 vertical: false,
121 child_offset: Default::default(),
122 },
123 border: BorderElementStyle {
124 color: Color::rgba(0.0, 0.0, 0.0, 0.0),
125 width: BorderWidthStyle {
126 left: 0.0,
127 right: 0.0,
128 top: 0.0,
129 bottom: 0.0,
130 between_children: 0.0,
131 },
132 },
133 }
134 }
135}
136
137#[derive(Debug, Clone, Copy, PartialEq)]
139#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
140pub struct CornerRadiiStyle {
141 pub top_left: f32,
143 pub top_right: f32,
145 pub bottom_left: f32,
147 pub bottom_right: f32,
149}
150
151#[derive(Debug, Copy, Clone, PartialEq)]
153#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
154pub struct BorderElementStyle {
155 pub color: Color,
157 pub width: BorderWidthStyle,
159}
160
161#[derive(Debug, Copy, Clone, PartialEq)]
163#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
164pub struct BorderWidthStyle {
165 pub left: f32,
167 pub right: f32,
169 pub top: f32,
171 pub bottom: f32,
173 pub between_children: f32,
175}
176
177#[derive(Debug, Clone, Copy, PartialEq)]
179#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
180pub struct FloatingElementStyle {
181 pub offset: Vector2,
183 pub expand: Dimensions,
185 pub z_index: i16,
187 pub attach_point: FloatingAttachPointType,
189 pub pointer_capture_mode: PointerCaptureMode,
191}
192
193#[derive(Debug, Copy, Clone)]
195#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
196pub struct LayoutStyle {
197 pub padding: Padding,
199 pub child_gap: f32,
201 pub child_alignment: Alignment,
203 pub layout_direction: LayoutDirection,
205 #[cfg(feature = "child_wrapping")]
210 pub child_wrapping: bool,
211}