cotis_defaults/element_configs/
style.rs1use 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
9pub mod types;
11use types::*;
12
13pub mod sizing;
15use sizing::*;
16
17#[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 pub sizing: Sizing,
24 pub layout: LayoutStyle,
26 #[cfg(not(feature = "complex_color"))]
28 pub background_color: Color,
29 #[cfg(feature = "complex_color")]
31 pub background_color: ColorLayer,
32 pub corner_radius: CornerRadiiStyle,
34 pub floating: Option<FloatingElementStyle>,
36 pub clip: ClipElementConfig,
38 pub border: BorderElementStyle,
40}
41
42impl Default for CotisStyle<Sizing> {
43 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 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#[derive(Debug, Clone, Copy, PartialEq)]
122#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
123pub struct CornerRadiiStyle {
124 pub top_left: f32,
126 pub top_right: f32,
128 pub bottom_left: f32,
130 pub bottom_right: f32,
132}
133
134#[derive(Debug, Copy, Clone, PartialEq)]
136#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
137pub struct BorderElementStyle {
138 pub color: Color,
140 pub width: BorderWidthStyle,
142}
143
144#[derive(Debug, Copy, Clone, PartialEq)]
146#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
147pub struct BorderWidthStyle {
148 pub left: f32,
150 pub right: f32,
152 pub top: f32,
154 pub bottom: f32,
156 pub between_children: f32,
158}
159
160#[derive(Debug, Clone, Copy, PartialEq)]
162#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
163pub struct FloatingElementStyle {
164 pub offset: Vector2,
166 pub expand: Dimensions,
168 pub z_index: i16,
170 pub attach_point: FloatingAttachPointType,
172 pub pointer_capture_mode: PointerCaptureMode,
174}
175
176#[derive(Debug, Copy, Clone)]
178#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
179pub struct LayoutStyle {
180 pub padding: Padding,
182 pub child_gap: f32,
184 pub child_alignment: Alignment,
186 pub layout_direction: LayoutDirection,
188 #[cfg(feature = "child_wrapping")]
193 pub child_wrapping: bool,
194}