clay_layout/elements/
rectangle.rs

1use crate::{bindings::*, color::Color, mem, TypedConfig};
2
3use super::{CornerRadius, ElementConfigType};
4
5#[derive(Debug, Copy, Clone)]
6pub struct Rectangle {
7    pub color: Color,
8    pub corner_radius: CornerRadius,
9}
10
11impl Rectangle {
12    pub fn new() -> Self {
13        Self::default()
14    }
15
16    pub fn color(&mut self, color: Color) -> &mut Self {
17        self.color = color;
18        self
19    }
20
21    pub fn corner_radius(&mut self, corner_radius: CornerRadius) -> &mut Self {
22        self.corner_radius = corner_radius;
23        self
24    }
25
26    pub fn end(&self) -> TypedConfig {
27        let memory = unsafe { Clay__StoreRectangleElementConfig((*self).into()) };
28
29        TypedConfig {
30            config_memory: memory as _,
31            id: mem::zeroed_init(),
32            config_type: ElementConfigType::Rectangle as _,
33        }
34    }
35}
36
37impl Default for Rectangle {
38    fn default() -> Self {
39        Self {
40            color: Color::rgba(0., 0., 0., 0.),
41            corner_radius: CornerRadius::All(0.),
42        }
43    }
44}
45
46impl From<Clay_RectangleElementConfig> for Rectangle {
47    fn from(value: Clay_RectangleElementConfig) -> Self {
48        Self {
49            color: value.color.into(),
50            corner_radius: value.cornerRadius.into(),
51        }
52    }
53}
54impl From<Rectangle> for Clay_RectangleElementConfig {
55    fn from(value: Rectangle) -> Self {
56        Self {
57            color: value.color.into(),
58            cornerRadius: value.corner_radius.into(),
59        }
60    }
61}