use crate::{bindings::*, color::Color};
#[derive(Debug, Clone, Copy)]
#[repr(u8)]
pub enum TextElementConfigWrapMode {
Words = Clay_TextElementConfigWrapMode_CLAY_TEXT_WRAP_WORDS,
Newline = Clay_TextElementConfigWrapMode_CLAY_TEXT_WRAP_NEWLINES,
None = Clay_TextElementConfigWrapMode_CLAY_TEXT_WRAP_NONE,
}
#[derive(Debug, Clone, Copy)]
#[repr(u8)]
pub enum TextAlignment {
Left = Clay_TextAlignment_CLAY_TEXT_ALIGN_LEFT,
Center = Clay_TextAlignment_CLAY_TEXT_ALIGN_CENTER,
Right = Clay_TextAlignment_CLAY_TEXT_ALIGN_RIGHT,
}
pub struct TextElementConfig {
inner: *mut Clay_TextElementConfig,
}
impl From<TextElementConfig> for *mut Clay_TextElementConfig {
fn from(value: TextElementConfig) -> Self {
value.inner
}
}
#[derive(Debug, Clone, Copy)]
pub struct TextConfig {
pub color: Color,
pub font_id: u16,
pub font_size: u16,
pub letter_spacing: u16,
pub line_height: u16,
pub wrap_mode: TextElementConfigWrapMode,
pub alignment: TextAlignment,
}
impl TextConfig {
pub fn new() -> Self {
Self::default()
}
#[inline]
pub fn color(&mut self, color: Color) -> &mut Self {
self.color = color;
self
}
#[inline]
pub fn font_id(&mut self, id: u16) -> &mut Self {
self.font_id = id;
self
}
#[inline]
pub fn font_size(&mut self, size: u16) -> &mut Self {
self.font_size = size;
self
}
#[inline]
pub fn letter_spacing(&mut self, spacing: u16) -> &mut Self {
self.letter_spacing = spacing;
self
}
#[inline]
pub fn line_height(&mut self, height: u16) -> &mut Self {
self.line_height = height;
self
}
#[inline]
pub fn wrap_mode(&mut self, mode: TextElementConfigWrapMode) -> &mut Self {
self.wrap_mode = mode;
self
}
#[inline]
pub fn alignment(&mut self, alignment: TextAlignment) -> &mut Self {
self.alignment = alignment;
self
}
#[inline]
pub fn end(&self) -> TextElementConfig {
let memory = unsafe { Clay__StoreTextElementConfig((*self).into()) };
TextElementConfig { inner: memory }
}
}
impl Default for TextConfig {
fn default() -> Self {
Self {
color: Color::rgba(0., 0., 0., 0.),
font_id: 0,
font_size: 0,
letter_spacing: 0,
line_height: 0,
wrap_mode: TextElementConfigWrapMode::Words,
alignment: TextAlignment::Left,
}
}
}
impl From<TextConfig> for Clay_TextElementConfig {
fn from(value: TextConfig) -> Self {
Self {
userData: core::ptr::null_mut(),
textColor: value.color.into(),
fontId: value.font_id,
fontSize: value.font_size,
letterSpacing: value.letter_spacing,
lineHeight: value.line_height,
wrapMode: value.wrap_mode as _,
textAlignment: value.alignment as _,
}
}
}
impl From<Clay_TextElementConfig> for TextConfig {
fn from(value: Clay_TextElementConfig) -> Self {
Self {
color: value.textColor.into(),
font_id: value.fontId,
font_size: value.fontSize,
letter_spacing: value.letterSpacing,
line_height: value.lineHeight,
wrap_mode: unsafe {
core::mem::transmute::<u8, TextElementConfigWrapMode>(value.wrapMode)
},
alignment: unsafe { core::mem::transmute::<u8, TextAlignment>(value.textAlignment) },
}
}
}