clay_layout/
errors.rs

1use crate::bindings::*;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4#[repr(u8)]
5pub enum ErrorType {
6    /// Thrown if the text measurement function is never provided to clay and you try using
7    /// `Clay::text`
8    TextMeasurementFunctionNotProvided =
9        Clay_ErrorType_CLAY_ERROR_TYPE_TEXT_MEASUREMENT_FUNCTION_NOT_PROVIDED,
10    ArenaCapacityExceeded = Clay_ErrorType_CLAY_ERROR_TYPE_ARENA_CAPACITY_EXCEEDED,
11    ElementsCapacityExceeded = Clay_ErrorType_CLAY_ERROR_TYPE_ELEMENTS_CAPACITY_EXCEEDED,
12    TextMeasurementCapacityExceeded =
13        Clay_ErrorType_CLAY_ERROR_TYPE_TEXT_MEASUREMENT_CAPACITY_EXCEEDED,
14    /// Thrown if you are trying to use an id that's already used by some other element
15    DuplicateId = Clay_ErrorType_CLAY_ERROR_TYPE_DUPLICATE_ID,
16    /// Floating container require a parent, the following error is thrown if the parent is not
17    /// found
18    FloatingContainerParentNotFound =
19        Clay_ErrorType_CLAY_ERROR_TYPE_FLOATING_CONTAINER_PARENT_NOT_FOUND,
20    InternalError = Clay_ErrorType_CLAY_ERROR_TYPE_INTERNAL_ERROR,
21}
22
23#[derive(Debug, Clone, Copy)]
24pub struct Error<'a> {
25    pub type_: ErrorType,
26    pub text: &'a str,
27}
28
29impl From<Clay_ErrorData> for Error<'_> {
30    fn from(value: Clay_ErrorData) -> Self {
31        Self {
32            type_: unsafe { core::mem::transmute::<u8, ErrorType>(value.errorType) },
33            text: value.errorText.into(),
34        }
35    }
36}