1use crate::colors::Color;
6#[cfg(feature = "complex_color")]
7use crate::colors::ColorLayer;
8use crate::element_configs::image_config::ImageConfig;
9use crate::element_configs::style::types::{
10 Alignment, ClipElementConfig, FloatingAttachPointType, LayoutAlignmentX, LayoutAlignmentY,
11 LayoutDirection, Padding, PointerCaptureMode,
12};
13use crate::element_configs::style::{
14 BorderElementStyle, BorderWidthStyle, CornerRadiiStyle, CotisStyle, FloatingElementStyle,
15 LayoutStyle,
16};
17use cotis::utils::ElementIdConfig;
18use cotis::utils::OwnedOrRef;
19
20pub mod image_config;
22pub mod premade_configs;
24pub mod style;
26pub mod text_config;
28
29#[derive(Debug, Clone)]
38#[cfg_attr(
39 feature = "serialization",
40 derive(serde::Serialize, serde::Deserialize)
41)]
42#[cfg_attr(
43 feature = "serialization",
44 serde(bound(deserialize = "
45 Sizing: serde::de::DeserializeOwned,
46 ImageElementData: serde::de::DeserializeOwned,
47 CustomElementData: serde::de::DeserializeOwned,
48 ExtraData: serde::de::DeserializeOwned
49"))
50)]
51pub struct ElementConfig<
52 'render,
53 Sizing: 'render,
54 ImageElementData: 'render,
55 CustomElementData: 'render,
56 ExtraData: 'render,
57> {
58 pub id_config: ElementIdConfig<'render>,
60 pub style: CotisStyle<Sizing>,
62 pub image: Option<ImageConfig<'render, ImageElementData>>,
64 pub custom: Option<OwnedOrRef<'render, CustomElementData>>,
66 pub extra_data: Option<OwnedOrRef<'render, ExtraData>>,
68}
69
70impl<
71 'render,
72 Sizing: 'render,
73 ImageElementData: 'render,
74 CustomElementData: 'render,
75 ExtraData: 'render,
76> Default for ElementConfig<'render, Sizing, ImageElementData, CustomElementData, ExtraData>
77where
78 Sizing: Default,
79{
80 fn default() -> Self {
81 Self {
82 id_config: ElementIdConfig::new_empty(),
83 style: Default::default(),
84 image: None,
85 custom: None,
86 extra_data: None,
87 }
88 }
89}
90
91impl<Sizing: Default> Default for CotisStyle<Sizing> {
92 fn default() -> Self {
95 Self {
96 sizing: Sizing::default(),
97 layout: Default::default(),
98 #[cfg(not(feature = "complex_color"))]
99 background_color: Color {
100 r: 0.0,
101 g: 0.0,
102 b: 0.0,
103 a: 0.0,
104 },
105 #[cfg(feature = "complex_color")]
106 background_color: ColorLayer::Solid(Color {
107 r: 0.0,
108 g: 0.0,
109 b: 0.0,
110 a: 0.0,
111 }),
112 corner_radius: CornerRadiiStyle {
113 top_left: 0.0,
114 top_right: 0.0,
115 bottom_left: 0.0,
116 bottom_right: 0.0,
117 },
118 floating: Default::default(),
119 clip: ClipElementConfig {
120 horizontal: false,
121 vertical: false,
122 child_offset: Default::default(),
123 },
124 border: BorderElementStyle {
125 color: Color {
126 r: 0.0,
127 g: 0.0,
128 b: 0.0,
129 a: 255.0,
130 },
131 width: BorderWidthStyle {
132 left: 0.0,
133 right: 0.0,
134 top: 0.0,
135 bottom: 0.0,
136 between_children: 0.0,
137 },
138 },
139 }
140 }
141}
142
143impl Default for LayoutStyle {
144 fn default() -> Self {
146 Self {
147 padding: Padding {
148 top: 0.0,
149 bottom: 0.0,
150 right: 0.0,
151 left: 0.0,
152 },
153 child_gap: 0.0,
154 child_alignment: Alignment {
155 x: LayoutAlignmentX::Left,
156 y: LayoutAlignmentY::Top,
157 },
158 layout_direction: LayoutDirection::LeftToRight,
159 #[cfg(feature = "child_wrapping")]
160 child_wrapping: false,
161 }
162 }
163}
164
165impl Default for FloatingElementStyle {
166 fn default() -> Self {
168 Self {
169 offset: Default::default(),
170 expand: Default::default(),
171 z_index: 0,
172 attach_point: FloatingAttachPointType::LeftTop,
173 pointer_capture_mode: PointerCaptureMode::Capture,
174 }
175 }
176}