clay_layout/layout/
alignment.rs1use crate::bindings::*;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4#[repr(u8)]
5pub enum LayoutAlignmentX {
6 Left = Clay_LayoutAlignmentX_CLAY_ALIGN_X_LEFT,
7 Center = Clay_LayoutAlignmentX_CLAY_ALIGN_X_CENTER,
8 Right = Clay_LayoutAlignmentX_CLAY_ALIGN_X_RIGHT,
9}
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12#[repr(u8)]
13pub enum LayoutAlignmentY {
14 Top = Clay_LayoutAlignmentY_CLAY_ALIGN_Y_TOP,
15 Center = Clay_LayoutAlignmentY_CLAY_ALIGN_Y_CENTER,
16 Bottom = Clay_LayoutAlignmentY_CLAY_ALIGN_Y_BOTTOM,
17}
18
19#[derive(Debug, Copy, Clone)]
21pub struct Alignment {
22 pub x: LayoutAlignmentX,
23 pub y: LayoutAlignmentY,
24}
25
26impl Alignment {
27 pub fn new(x: LayoutAlignmentX, y: LayoutAlignmentY) -> Self {
28 Self { x, y }
29 }
30}
31
32impl From<Clay_ChildAlignment> for Alignment {
33 fn from(value: Clay_ChildAlignment) -> Self {
34 Self {
35 x: unsafe { core::mem::transmute::<u8, LayoutAlignmentX>(value.x) },
36 y: unsafe { core::mem::transmute::<u8, LayoutAlignmentY>(value.y) },
37 }
38 }
39}
40impl From<Alignment> for Clay_ChildAlignment {
41 fn from(value: Alignment) -> Self {
42 Self {
43 x: value.x as _,
44 y: value.y as _,
45 }
46 }
47}
48
49impl From<(LayoutAlignmentX, LayoutAlignmentY)> for Alignment {
50 fn from(other: (LayoutAlignmentX, LayoutAlignmentY)) -> Self {
51 Self::new(other.0, other.1)
52 }
53}