1use crate::{bindings::*, color::Color};
2
3#[derive(Debug, Clone, Copy)]
4#[repr(u8)]
5pub enum TextElementConfigWrapMode {
6 Words = Clay_TextElementConfigWrapMode_CLAY_TEXT_WRAP_WORDS,
8 Newline = Clay_TextElementConfigWrapMode_CLAY_TEXT_WRAP_NEWLINES,
10 None = Clay_TextElementConfigWrapMode_CLAY_TEXT_WRAP_NONE,
12}
13
14#[derive(Debug, Clone, Copy)]
15#[repr(u8)]
16pub enum TextAlignment {
17 Left = Clay_TextAlignment_CLAY_TEXT_ALIGN_LEFT,
19 Center = Clay_TextAlignment_CLAY_TEXT_ALIGN_CENTER,
21 Right = Clay_TextAlignment_CLAY_TEXT_ALIGN_RIGHT,
23}
24
25pub struct TextElementConfig {
26 inner: *mut Clay_TextElementConfig,
27}
28
29impl From<TextElementConfig> for *mut Clay_TextElementConfig {
30 fn from(value: TextElementConfig) -> Self {
31 value.inner
32 }
33}
34
35#[derive(Debug, Clone, Copy)]
37pub struct TextConfig {
38 pub color: Color,
40 pub font_id: u16,
43 pub font_size: u16,
45 pub letter_spacing: u16,
47 pub line_height: u16,
49 pub wrap_mode: TextElementConfigWrapMode,
51 pub alignment: TextAlignment,
53}
54
55impl TextConfig {
56 pub fn new() -> Self {
58 Self::default()
59 }
60
61 #[inline]
63 pub fn color(&mut self, color: Color) -> &mut Self {
64 self.color = color;
65 self
66 }
67
68 #[inline]
70 pub fn font_id(&mut self, id: u16) -> &mut Self {
71 self.font_id = id;
72 self
73 }
74
75 #[inline]
77 pub fn font_size(&mut self, size: u16) -> &mut Self {
78 self.font_size = size;
79 self
80 }
81
82 #[inline]
84 pub fn letter_spacing(&mut self, spacing: u16) -> &mut Self {
85 self.letter_spacing = spacing;
86 self
87 }
88
89 #[inline]
91 pub fn line_height(&mut self, height: u16) -> &mut Self {
92 self.line_height = height;
93 self
94 }
95
96 #[inline]
98 pub fn wrap_mode(&mut self, mode: TextElementConfigWrapMode) -> &mut Self {
99 self.wrap_mode = mode;
100 self
101 }
102
103 #[inline]
105 pub fn alignment(&mut self, alignment: TextAlignment) -> &mut Self {
106 self.alignment = alignment;
107 self
108 }
109
110 #[inline]
112 pub fn end(&self) -> TextElementConfig {
113 let memory = unsafe { Clay__StoreTextElementConfig((*self).into()) };
114 TextElementConfig { inner: memory }
115 }
116}
117
118impl Default for TextConfig {
119 fn default() -> Self {
120 Self {
121 color: Color::rgba(0., 0., 0., 0.),
122 font_id: 0,
123 font_size: 0,
124 letter_spacing: 0,
125 line_height: 0,
126 wrap_mode: TextElementConfigWrapMode::Words,
127 alignment: TextAlignment::Left,
128 }
129 }
130}
131
132impl From<TextConfig> for Clay_TextElementConfig {
133 fn from(value: TextConfig) -> Self {
134 Self {
135 userData: core::ptr::null_mut(),
136 textColor: value.color.into(),
137 fontId: value.font_id,
138 fontSize: value.font_size,
139 letterSpacing: value.letter_spacing,
140 lineHeight: value.line_height,
141 wrapMode: value.wrap_mode as _,
142 textAlignment: value.alignment as _,
143 }
144 }
145}
146
147impl From<Clay_TextElementConfig> for TextConfig {
148 fn from(value: Clay_TextElementConfig) -> Self {
149 Self {
150 color: value.textColor.into(),
151 font_id: value.fontId,
152 font_size: value.fontSize,
153 letter_spacing: value.letterSpacing,
154 line_height: value.lineHeight,
155 wrap_mode: unsafe {
156 core::mem::transmute::<u8, TextElementConfigWrapMode>(value.wrapMode)
157 },
158 alignment: unsafe { core::mem::transmute::<u8, TextAlignment>(value.textAlignment) },
159 }
160 }
161}