clay_layout/
math.rs

1use crate::bindings::*;
2
3#[derive(Debug, Clone, Copy, PartialEq, Default)]
4#[repr(C)]
5pub struct Vector2 {
6    pub x: f32,
7    pub y: f32,
8}
9
10impl Vector2 {
11    pub fn new(x: f32, y: f32) -> Self {
12        Self { x, y }
13    }
14}
15
16impl From<Clay_Vector2> for Vector2 {
17    fn from(value: Clay_Vector2) -> Self {
18        unsafe { core::mem::transmute(value) }
19    }
20}
21impl From<Vector2> for Clay_Vector2 {
22    fn from(value: Vector2) -> Self {
23        unsafe { core::mem::transmute(value) }
24    }
25}
26
27impl From<(f32, f32)> for Vector2 {
28    fn from(value: (f32, f32)) -> Self {
29        Self::new(value.0, value.1)
30    }
31}
32
33#[derive(Debug, Clone, Copy, PartialEq, Default)]
34#[repr(C)]
35pub struct Dimensions {
36    pub width: f32,
37    pub height: f32,
38}
39
40impl Dimensions {
41    pub fn new(width: f32, height: f32) -> Self {
42        Self { width, height }
43    }
44}
45
46impl From<Clay_Dimensions> for Dimensions {
47    fn from(value: Clay_Dimensions) -> Self {
48        unsafe { core::mem::transmute(value) }
49    }
50}
51impl From<Dimensions> for Clay_Dimensions {
52    fn from(value: Dimensions) -> Self {
53        unsafe { core::mem::transmute(value) }
54    }
55}
56
57impl From<(f32, f32)> for Dimensions {
58    fn from(value: (f32, f32)) -> Self {
59        Self::new(value.0, value.1)
60    }
61}
62
63#[derive(Debug, Clone, Copy, PartialEq, Default)]
64#[repr(C)]
65pub struct BoundingBox {
66    pub x: f32,
67    pub y: f32,
68    pub width: f32,
69    pub height: f32,
70}
71
72impl BoundingBox {
73    pub fn new(x: f32, y: f32, width: f32, height: f32) -> Self {
74        Self {
75            x,
76            y,
77            width,
78            height,
79        }
80    }
81}
82
83impl From<Clay_BoundingBox> for BoundingBox {
84    fn from(value: Clay_BoundingBox) -> Self {
85        unsafe { core::mem::transmute(value) }
86    }
87}
88impl From<BoundingBox> for Clay_BoundingBox {
89    fn from(value: BoundingBox) -> Self {
90        unsafe { core::mem::transmute(value) }
91    }
92}