diff --git a/clay.h b/clay.h index 75afc20..71ba282 100644 --- a/clay.h +++ b/clay.h @@ -184,7 +184,7 @@ extern "C" { // Note: Clay_String is not guaranteed to be null terminated. It may be if created from a literal C string, // but it is also used to represent slices. -typedef struct { +typedef struct Clay_String { // Set this boolean to true if the char* data underlying this string will live for the entire lifetime of the program. // This will automatically be set for strings created with CLAY_STRING, as the macro requires a string literal. bool isStaticallyAllocated; @@ -195,7 +195,7 @@ typedef struct { // Clay_StringSlice is used to represent non owning string slices, and includes // a baseChars field which points to the string this slice is derived from. -typedef struct { +typedef struct Clay_StringSlice { int32_t length; const char *chars; const char *baseChars; // The source string / char* that this slice was derived from @@ -205,33 +205,33 @@ typedef struct Clay_Context Clay_Context; // Clay_Arena is a memory arena structure that is used by clay to manage its internal allocations. // Rather than creating it by hand, it's easier to use Clay_CreateArenaWithCapacityAndMemory() -typedef struct { +typedef struct Clay_Arena { uintptr_t nextAllocation; size_t capacity; char *memory; } Clay_Arena; -typedef struct { +typedef struct Clay_Dimensions { float width, height; } Clay_Dimensions; -typedef struct { +typedef struct Clay_Vector2 { float x, y; } Clay_Vector2; // Internally clay conventionally represents colors as 0-255, but interpretation is up to the renderer. -typedef struct { +typedef struct Clay_Color { float r, g, b, a; } Clay_Color; -typedef struct { +typedef struct Clay_BoundingBox { float x, y, width, height; } Clay_BoundingBox; // Primarily created via the CLAY_ID(), CLAY_IDI(), CLAY_ID_LOCAL() and CLAY_IDI_LOCAL() macros. // Represents a hashed string ID used for identifying and finding specific clay UI elements, required // by functions such as Clay_PointerOver() and Clay_GetElementData(). -typedef struct { +typedef struct Clay_ElementId { uint32_t id; // The resulting hash generated from the other fields. uint32_t offset; // A numerical offset applied after computing the hash from stringId. uint32_t baseId; // A base hash value to start from, for example the parent element ID is used when calculating CLAY_ID_LOCAL(). @@ -240,7 +240,7 @@ typedef struct { // Controls the "radius", or corner rounding of elements, including rectangles, borders and images. // The rounding is determined by drawing a circle inset into the element corner by (radius, radius) pixels. -typedef struct { +typedef struct Clay_CornerRadius { float topLeft; float topRight; float bottomLeft; @@ -290,20 +290,20 @@ typedef CLAY_PACKED_ENUM { } Clay__SizingType; // Controls how child elements are aligned on each axis. -typedef struct { +typedef struct Clay_ChildAlignment { Clay_LayoutAlignmentX x; // Controls alignment of children along the x axis. Clay_LayoutAlignmentY y; // Controls alignment of children along the y axis. } Clay_ChildAlignment; // Controls the minimum and maximum size in pixels that this element is allowed to grow or shrink to, // overriding sizing types such as FIT or GROW. -typedef struct { +typedef struct Clay_SizingMinMax { float min; // The smallest final size of the element on this axis will be this value in pixels. float max; // The largest final size of the element on this axis will be this value in pixels. } Clay_SizingMinMax; // Controls the sizing of this element along one axis inside its parent container. -typedef struct { +typedef struct Clay_SizingAxis { union { Clay_SizingMinMax minMax; // Controls the minimum and maximum size in pixels that this element is allowed to grow or shrink to, overriding sizing types such as FIT or GROW. float percent; // Expects 0-1 range. Clamps the axis size to a percent of the parent container's axis size minus padding and child gaps. @@ -312,14 +312,14 @@ typedef struct { } Clay_SizingAxis; // Controls the sizing of this element along one axis inside its parent container. -typedef struct { +typedef struct Clay_Sizing { Clay_SizingAxis width; // Controls the width sizing of the element, along the x axis. Clay_SizingAxis height; // Controls the height sizing of the element, along the y axis. } Clay_Sizing; // Controls "padding" in pixels, which is a gap between the bounding box of this element and where its children // will be placed. -typedef struct { +typedef struct Clay_Padding { uint16_t left; uint16_t right; uint16_t top; @@ -330,7 +330,7 @@ CLAY__WRAPPER_STRUCT(Clay_Padding); // Controls various settings that affect the size and position of an element, as well as the sizes and positions // of any child elements. -typedef struct { +typedef struct Clay_LayoutConfig { Clay_Sizing sizing; // Controls the sizing of this element inside it's parent container, including FIT, GROW, PERCENT and FIXED sizing. Clay_Padding padding; // Controls "padding" in pixels, which is a gap between the bounding box of this element and where its children will be placed. uint16_t childGap; // Controls the gap in pixels between child elements along the layout axis (horizontal gap for LEFT_TO_RIGHT, vertical gap for TOP_TO_BOTTOM). @@ -363,7 +363,7 @@ typedef CLAY_PACKED_ENUM { } Clay_TextAlignment; // Controls various functionality related to text elements. -typedef struct { +typedef struct Clay_TextElementConfig { // A pointer that will be transparently passed through to the resulting render command. void *userData; // The RGBA color of the font to render, conventionally specified as 0-255. @@ -418,7 +418,7 @@ typedef CLAY_PACKED_ENUM { } Clay_FloatingAttachPointType; // Controls where a floating element is offset relative to its parent element. -typedef struct { +typedef struct Clay_FloatingAttachPoints { Clay_FloatingAttachPointType element; // Controls the origin point on a floating element that attaches to its parent. Clay_FloatingAttachPointType parent; // Controls the origin point on the parent element that the floating element attaches to. } Clay_FloatingAttachPoints; @@ -447,7 +447,7 @@ typedef CLAY_PACKED_ENUM { // Controls various settings related to "floating" elements, which are elements that "float" above other elements, potentially overlapping their boundaries, // and not affecting the layout of sibling or parent elements. -typedef struct { +typedef struct Clay_FloatingElementConfig { // Offsets this floating element by the provided x,y coordinates from its attachPoints. Clay_Vector2 offset; // Expands the boundaries of the outer floating element without affecting its children. @@ -480,7 +480,7 @@ CLAY__WRAPPER_STRUCT(Clay_FloatingElementConfig); // Custom ----------------------------- // Controls various settings related to custom elements. -typedef struct { +typedef struct Clay_CustomElementConfig { // A transparent pointer through which you can pass custom data to the renderer. // Generates CUSTOM render commands. void* customData; @@ -491,7 +491,7 @@ CLAY__WRAPPER_STRUCT(Clay_CustomElementConfig); // Scroll ----------------------------- // Controls the axis on which an element switches to "scrolling", which clips the contents and allows scrolling in that direction. -typedef struct { +typedef struct Clay_ScrollElementConfig { bool horizontal; // Clip overflowing elements on the X axis and allow scrolling left and right. bool vertical; // Clip overflowing elements on the YU axis and allow scrolling up and down. } Clay_ScrollElementConfig; @@ -501,7 +501,7 @@ CLAY__WRAPPER_STRUCT(Clay_ScrollElementConfig); // Border ----------------------------- // Controls the widths of individual element borders. -typedef struct { +typedef struct Clay_BorderWidth { uint16_t left; uint16_t right; uint16_t top; @@ -513,7 +513,7 @@ typedef struct { } Clay_BorderWidth; // Controls settings related to element borders. -typedef struct { +typedef struct Clay_BorderElementConfig { Clay_Color color; // Controls the color of all borders with width > 0. Conventionally represented as 0-255, but interpretation is up to the renderer. Clay_BorderWidth width; // Controls the widths of individual borders. At least one of these should be > 0 for a BORDER render command to be generated. } Clay_BorderElementConfig; @@ -523,7 +523,7 @@ CLAY__WRAPPER_STRUCT(Clay_BorderElementConfig); // Render Command Data ----------------------------- // Render command data when commandType == CLAY_RENDER_COMMAND_TYPE_TEXT -typedef struct { +typedef struct Clay_TextRenderData { // A string slice containing the text to be rendered. // Note: this is not guaranteed to be null terminated. Clay_StringSlice stringContents; @@ -539,7 +539,7 @@ typedef struct { } Clay_TextRenderData; // Render command data when commandType == CLAY_RENDER_COMMAND_TYPE_RECTANGLE -typedef struct { +typedef struct Clay_RectangleRenderData { // The solid background color to fill this rectangle with. Conventionally represented as 0-255 for each channel, but interpretation is up to the renderer. Clay_Color backgroundColor; // Controls the "radius", or corner rounding of elements, including rectangles, borders and images. @@ -548,7 +548,7 @@ typedef struct { } Clay_RectangleRenderData; // Render command data when commandType == CLAY_RENDER_COMMAND_TYPE_IMAGE -typedef struct { +typedef struct Clay_ImageRenderData { // The tint color for this image. Note that the default value is 0,0,0,0 and should likely be interpreted // as "untinted". // Conventionally represented as 0-255 for each channel, but interpretation is up to the renderer. @@ -563,7 +563,7 @@ typedef struct { } Clay_ImageRenderData; // Render command data when commandType == CLAY_RENDER_COMMAND_TYPE_CUSTOM -typedef struct { +typedef struct Clay_CustomRenderData { // Passed through from .backgroundColor in the original element declaration. // Conventionally represented as 0-255 for each channel, but interpretation is up to the renderer. Clay_Color backgroundColor; @@ -575,13 +575,13 @@ typedef struct { } Clay_CustomRenderData; // Render command data when commandType == CLAY_RENDER_COMMAND_TYPE_SCISSOR_START || commandType == CLAY_RENDER_COMMAND_TYPE_SCISSOR_END -typedef struct { +typedef struct Clay_ScrollRenderData { bool horizontal; bool vertical; } Clay_ScrollRenderData; // Render command data when commandType == CLAY_RENDER_COMMAND_TYPE_BORDER -typedef struct { +typedef struct Clay_BorderRenderData { // Controls a shared color for all this element's borders. // Conventionally represented as 0-255 for each channel, but interpretation is up to the renderer. Clay_Color color; @@ -593,7 +593,7 @@ typedef struct { } Clay_BorderRenderData; // A struct union containing data specific to this command's .commandType -typedef union { +typedef union Clay_RenderData { // Render command data when commandType == CLAY_RENDER_COMMAND_TYPE_RECTANGLE Clay_RectangleRenderData rectangle; // Render command data when commandType == CLAY_RENDER_COMMAND_TYPE_TEXT @@ -611,7 +611,7 @@ typedef union { // Miscellaneous Structs & Enums --------------------------------- // Data representing the current internal state of a scrolling element. -typedef struct { +typedef struct Clay_ScrollContainerData { // Note: This is a pointer to the real internal scroll position, mutating it may cause a change in final layout. // Intended for use with external functionality that modifies scroll position, such as scroll bars or auto scrolling. Clay_Vector2 *scrollPosition; @@ -626,7 +626,7 @@ typedef struct { } Clay_ScrollContainerData; // Bounding box and other data for a specific UI element. -typedef struct { +typedef struct Clay_ElementData { // The rectangle that encloses this UI element, with the position relative to the root of the layout. Clay_BoundingBox boundingBox; // Indicates whether an actual Element matched the provided ID or if the default struct was returned. @@ -653,7 +653,7 @@ typedef CLAY_PACKED_ENUM { CLAY_RENDER_COMMAND_TYPE_CUSTOM, } Clay_RenderCommandType; -typedef struct { +typedef struct Clay_RenderCommand { // A rectangular box that fully encloses this UI element, with the position relative to the root of the layout. Clay_BoundingBox boundingBox; // A struct union containing data specific to this command's commandType. @@ -678,7 +678,7 @@ typedef struct { } Clay_RenderCommand; // A sized array of render commands. -typedef struct { +typedef struct Clay_RenderCommandArray { // The underlying max capacity of the array, not necessarily all initialized. int32_t capacity; // The number of initialized elements in this array. Used for loops and iteration. @@ -700,7 +700,7 @@ typedef CLAY_PACKED_ENUM { } Clay_PointerDataInteractionState; // Information on the current state of pointer interactions this frame. -typedef struct { +typedef struct Clay_PointerData { // The position of the mouse / touch / pointer relative to the root of the layout. Clay_Vector2 position; // Represents the current state of interaction with clay this frame. @@ -711,7 +711,7 @@ typedef struct { Clay_PointerDataInteractionState state; } Clay_PointerData; -typedef struct { +typedef struct Clay_ElementDeclaration { // Primarily created via the CLAY_ID(), CLAY_IDI(), CLAY_ID_LOCAL() and CLAY_IDI_LOCAL() macros. // Represents a hashed string ID used for identifying and finding specific clay UI elements, required by functions such as Clay_PointerOver() and Clay_GetElementData(). Clay_ElementId id; @@ -762,7 +762,7 @@ typedef CLAY_PACKED_ENUM { } Clay_ErrorType; // Data to identify the error that clay has encountered. -typedef struct { +typedef struct Clay_ErrorData { // Represents the type of error clay encountered while computing layout. // CLAY_ERROR_TYPE_TEXT_MEASUREMENT_FUNCTION_NOT_PROVIDED - A text measurement function wasn't provided using Clay_SetMeasureTextFunction(), or the provided function was null. // CLAY_ERROR_TYPE_ARENA_CAPACITY_EXCEEDED - Clay attempted to allocate its internal data structures but ran out of space. The arena passed to Clay_Initialize was created with a capacity smaller than that required by Clay_MinMemorySize().