1use crate::colors::Color;
2#[cfg(any(feature = "complex_color", feature = "complex_colored_text"))]
3use crate::colors::ColorLayer;
4use cotis::utils::OwnedOrRef;
5use cotis_utils::math::BoundingBox;
6use std::fmt::Debug;
7
8#[derive(Debug, Clone)]
11#[cfg_attr(
12 feature = "serialization",
13 derive(serde::Serialize, serde::Deserialize)
14)]
15#[cfg_attr(
16 feature = "serialization",
17 serde(bound(deserialize = "
18 ExtraData: serde::de::DeserializeOwned
19"))
20)]
21pub struct Rectangle<'a, ExtraData> {
22 pub info: RenderCommandInfo<'a, ExtraData>,
24 #[cfg(not(feature = "complex_color"))]
26 pub color: Color,
27 #[cfg(feature = "complex_color")]
28 pub color: ColorLayer,
29 pub corner_radii: CornerRadii,
31}
32
33#[derive(Debug, Clone)]
35#[cfg_attr(
36 feature = "serialization",
37 derive(serde::Serialize, serde::Deserialize)
38)]
39#[cfg_attr(
40 feature = "serialization",
41 serde(bound(deserialize = "
42 ExtraData: serde::de::DeserializeOwned
43"))
44)]
45pub struct Text<'a, ExtraData> {
46 pub info: RenderCommandInfo<'a, ExtraData>,
48 pub text: OwnedOrRef<'a, str>,
50 #[cfg(not(feature = "complex_colored_text"))]
52 pub color: Color,
53 #[cfg(feature = "complex_colored_text")]
54 pub color: ColorLayer,
55 pub font_id: u16,
57 pub font_size: f32,
59 pub letter_spacing: f32,
61 pub line_height: f32,
63}
64
65#[derive(Debug, Clone)]
67#[cfg_attr(
68 feature = "serialization",
69 derive(serde::Serialize, serde::Deserialize)
70)]
71pub struct CornerRadii {
72 pub top_left: f32,
74 pub top_right: f32,
76 pub bottom_left: f32,
78 pub bottom_right: f32,
80}
81
82#[derive(Debug, Clone)]
84#[cfg_attr(
85 feature = "serialization",
86 derive(serde::Serialize, serde::Deserialize)
87)]
88pub struct BorderWidth {
89 pub left: f32,
91 pub right: f32,
93 pub top: f32,
95 pub bottom: f32,
97 pub between_children: f32,
99}
100
101#[derive(Debug, Clone)]
103#[cfg_attr(
104 feature = "serialization",
105 derive(serde::Serialize, serde::Deserialize)
106)]
107#[cfg_attr(
108 feature = "serialization",
109 serde(bound(deserialize = "
110 ExtraData: serde::de::DeserializeOwned
111"))
112)]
113pub struct Border<'a, ExtraData> {
114 pub info: RenderCommandInfo<'a, ExtraData>,
116 pub color: Color,
118 pub corner_radii: CornerRadii,
120 pub width: BorderWidth,
122}
123
124#[derive(Debug, Clone)]
126#[cfg_attr(
127 feature = "serialization",
128 derive(serde::Serialize, serde::Deserialize)
129)]
130#[cfg_attr(
131 feature = "serialization",
132 serde(bound(deserialize = "
133 ImageElementData: serde::de::DeserializeOwned,
134 ExtraData: serde::de::DeserializeOwned
135"))
136)]
137pub struct Image<'a, ImageElementData, ExtraData> {
138 pub info: RenderCommandInfo<'a, ExtraData>,
140 #[cfg(not(feature = "complex_color"))]
142 pub background_color: Color,
143 #[cfg(feature = "complex_color")]
144 pub background_color: ColorLayer,
145 pub corner_radii: CornerRadii,
147 pub data: OwnedOrRef<'a, ImageElementData>,
149}
150
151#[derive(Debug, Clone)]
153#[cfg_attr(
154 feature = "serialization",
155 derive(serde::Serialize, serde::Deserialize)
156)]
157#[cfg_attr(
158 feature = "serialization",
159 serde(bound(deserialize = "
160 ExtraData: serde::de::DeserializeOwned
161"))
162)]
163pub struct ClipStart<'a, ExtraData> {
164 pub info: RenderCommandInfo<'a, ExtraData>,
166 pub horizontal: bool,
168 pub vertical: bool,
170 pub corner_radii: CornerRadii,
172}
173
174#[derive(Debug, Clone)]
176#[cfg_attr(
177 feature = "serialization",
178 derive(serde::Serialize, serde::Deserialize)
179)]
180pub struct ClipEnd;
181
182#[derive(Debug, Clone)]
184#[cfg_attr(
185 feature = "serialization",
186 derive(serde::Serialize, serde::Deserialize)
187)]
188#[cfg_attr(
189 feature = "serialization",
190 serde(bound(deserialize = "
191 ExtraData: serde::de::DeserializeOwned
192"))
193)]
194pub struct RenderCommandInfo<'a, ExtraData> {
195 pub bounding_box: BoundingBox,
197 pub id: u32,
199 pub z_index: i16,
202 pub extra_data: Option<OwnedOrRef<'a, ExtraData>>,
204}
205
206pub mod render_t_list;
208
209#[cfg(test)]
210mod test {
211 use cotis::utils::OwnedOrRef;
212 use std::sync::Arc;
213
214 fn is_send<T: Send>() {}
215 #[test]
216 fn test_render_command() {
217 is_send::<OwnedOrRef<()>>();
218 }
219
220 fn str_owned_ref(_: OwnedOrRef<str>) {
221 }
223
224 #[test]
225 fn test_owned_ref() {
226 let res: String = String::new();
227 let res: &String = &res;
228 str_owned_ref(OwnedOrRef::Ref(res));
229
230 let s = Arc::new(String::from("hello"));
231
232 let by_ref: OwnedOrRef<'_, str> = OwnedOrRef::Ref("hello");
233 let by_arc: OwnedOrRef<'_, str> = OwnedOrRef::AsOwnedRef(s);
234 assert_eq!(by_ref.as_ref(), by_arc.as_ref());
235 }
236}