mirror of
https://github.com/nicbarker/clay.git
synced 2025-05-14 06:18:04 +00:00
Compare commits
7 Commits
8066eda535
...
ff3c4c54cb
Author | SHA1 | Date | |
---|---|---|---|
|
ff3c4c54cb | ||
|
3961720ef0 | ||
|
dd1f018444 | ||
|
d0d1e01a3f | ||
|
23ee491e37 | ||
|
ccb57787ce | ||
|
25e13b8bdb |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
477
clay.h
477
clay.h
@ -21,11 +21,6 @@
|
|||||||
#include <arm_neon.h>
|
#include <arm_neon.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __JETBRAINS_IDE__
|
|
||||||
// Help jetbrains IDEs like CLion and Rider with intellisense & debugging
|
|
||||||
#define CLAY_IMPLEMENTATION
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
// HEADER DECLARATIONS ---------------------
|
// HEADER DECLARATIONS ---------------------
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
@ -49,10 +44,6 @@
|
|||||||
|
|
||||||
// Public Macro API ------------------------
|
// Public Macro API ------------------------
|
||||||
|
|
||||||
#define CLAY__WRAPPER_TYPE(type) Clay__##type##Wrapper
|
|
||||||
#define CLAY__WRAPPER_STRUCT(type) typedef struct { type wrapped; } CLAY__WRAPPER_TYPE(type)
|
|
||||||
#define CLAY__CONFIG_WRAPPER(type, ...) (CLAY__INIT(CLAY__WRAPPER_TYPE(type)) { __VA_ARGS__ }).wrapped
|
|
||||||
|
|
||||||
#define CLAY__MAX(x, y) (((x) > (y)) ? (x) : (y))
|
#define CLAY__MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||||
#define CLAY__MIN(x, y) (((x) < (y)) ? (x) : (y))
|
#define CLAY__MIN(x, y) (((x) < (y)) ? (x) : (y))
|
||||||
|
|
||||||
@ -98,19 +89,20 @@ static uint8_t CLAY__ELEMENT_DEFINITION_LATCH;
|
|||||||
/* This macro looks scary on the surface, but is actually quite simple.
|
/* This macro looks scary on the surface, but is actually quite simple.
|
||||||
It turns a macro call like this:
|
It turns a macro call like this:
|
||||||
|
|
||||||
CLAY(
|
CLAY({
|
||||||
CLAY_RECTANGLE(),
|
.id = CLAY_ID("Container"),
|
||||||
CLAY_ID()
|
.backgroundColor = { 255, 200, 200, 255 }
|
||||||
) {
|
}) {
|
||||||
...children declared here
|
...children declared here
|
||||||
}
|
}
|
||||||
|
|
||||||
Into calls like this:
|
Into calls like this:
|
||||||
|
|
||||||
Clay_OpenElement();
|
Clay_OpenElement();
|
||||||
CLAY_RECTANGLE();
|
Clay_ConfigureOpenElement((Clay_ElementDeclaration) {
|
||||||
CLAY_ID();
|
.id = CLAY_ID("Container"),
|
||||||
Clay_ElementPostConfiguration();
|
.backgroundColor = { 255, 200, 200, 255 }
|
||||||
|
});
|
||||||
...children declared here
|
...children declared here
|
||||||
Clay_CloseElement();
|
Clay_CloseElement();
|
||||||
|
|
||||||
@ -125,6 +117,15 @@ static uint8_t CLAY__ELEMENT_DEFINITION_LATCH;
|
|||||||
++CLAY__ELEMENT_DEFINITION_LATCH, Clay__CloseElement() \
|
++CLAY__ELEMENT_DEFINITION_LATCH, Clay__CloseElement() \
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// These macros exist to allow the CLAY() macro to be called both with an inline struct definition, such as
|
||||||
|
// CLAY({ .id = something... });
|
||||||
|
// As well as by passing a predefined declaration struct
|
||||||
|
// Clay_ElementDeclaration declarationStruct = ...
|
||||||
|
// CLAY(declarationStruct);
|
||||||
|
#define CLAY__WRAPPER_TYPE(type) Clay__##type##Wrapper
|
||||||
|
#define CLAY__WRAPPER_STRUCT(type) typedef struct { type wrapped; } CLAY__WRAPPER_TYPE(type)
|
||||||
|
#define CLAY__CONFIG_WRAPPER(type, ...) (CLAY__INIT(CLAY__WRAPPER_TYPE(type)) { __VA_ARGS__ }).wrapped
|
||||||
|
|
||||||
#define CLAY_TEXT(text, textConfig) Clay__OpenTextElement(text, textConfig)
|
#define CLAY_TEXT(text, textConfig) Clay__OpenTextElement(text, textConfig)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -158,22 +159,27 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Utility Structs -------------------------
|
// Utility Structs -------------------------
|
||||||
|
|
||||||
// Note: Clay_String is not guaranteed to be null terminated. It may be if created from a literal C string,
|
// 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.
|
// but it is also used to represent slices.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t length;
|
int32_t length;
|
||||||
|
// The underlying character memory. Note: this will not be copied and will not extend the lifetime of the underlying memory.
|
||||||
const char *chars;
|
const char *chars;
|
||||||
} Clay_String;
|
} Clay_String;
|
||||||
|
|
||||||
|
// 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 {
|
||||||
int32_t length;
|
int32_t length;
|
||||||
const char *chars;
|
const char *chars;
|
||||||
// The source string / char* that this slice was derived from
|
const char *baseChars; // The source string / char* that this slice was derived from
|
||||||
const char *baseChars;
|
|
||||||
} Clay_StringSlice;
|
} Clay_StringSlice;
|
||||||
|
|
||||||
typedef struct Clay_Context Clay_Context;
|
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 {
|
||||||
uintptr_t nextAllocation;
|
uintptr_t nextAllocation;
|
||||||
size_t capacity;
|
size_t capacity;
|
||||||
@ -188,6 +194,7 @@ typedef struct {
|
|||||||
float x, y;
|
float x, y;
|
||||||
} Clay_Vector2;
|
} Clay_Vector2;
|
||||||
|
|
||||||
|
// Internally clay conventionally represents colors as 0-255, but interpretation is up to the renderer.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
float r, g, b, a;
|
float r, g, b, a;
|
||||||
} Clay_Color;
|
} Clay_Color;
|
||||||
@ -196,14 +203,18 @@ typedef struct {
|
|||||||
float x, y, width, height;
|
float x, y, width, height;
|
||||||
} Clay_BoundingBox;
|
} Clay_BoundingBox;
|
||||||
|
|
||||||
// baseId + offset = id
|
// 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 {
|
||||||
uint32_t id;
|
uint32_t id; // The resulting hash generated from the other fields.
|
||||||
uint32_t offset;
|
uint32_t offset; // A numerical offset applied after computing the hash from stringId.
|
||||||
uint32_t baseId;
|
uint32_t baseId; // A base hash value to start from, for example the parent element ID is used when calculating CLAY_ID_LOCAL().
|
||||||
Clay_String stringId;
|
Clay_String stringId; // The string id to hash.
|
||||||
} Clay_ElementId;
|
} Clay_ElementId;
|
||||||
|
|
||||||
|
// 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 {
|
||||||
float topLeft;
|
float topLeft;
|
||||||
float topRight;
|
float topRight;
|
||||||
@ -211,66 +222,78 @@ typedef struct {
|
|||||||
float bottomRight;
|
float bottomRight;
|
||||||
} Clay_CornerRadius;
|
} Clay_CornerRadius;
|
||||||
|
|
||||||
typedef CLAY_PACKED_ENUM {
|
|
||||||
CLAY__ELEMENT_CONFIG_TYPE_NONE,
|
|
||||||
CLAY__ELEMENT_CONFIG_TYPE_BORDER,
|
|
||||||
CLAY__ELEMENT_CONFIG_TYPE_FLOATING,
|
|
||||||
CLAY__ELEMENT_CONFIG_TYPE_SCROLL,
|
|
||||||
CLAY__ELEMENT_CONFIG_TYPE_IMAGE,
|
|
||||||
CLAY__ELEMENT_CONFIG_TYPE_TEXT,
|
|
||||||
CLAY__ELEMENT_CONFIG_TYPE_CUSTOM,
|
|
||||||
CLAY__ELEMENT_CONFIG_TYPE_SHARED,
|
|
||||||
} Clay__ElementConfigType;
|
|
||||||
|
|
||||||
// Element Configs ---------------------------
|
// Element Configs ---------------------------
|
||||||
// Layout
|
|
||||||
|
// Controls the direction in which child elements will be automatically laid out.
|
||||||
typedef CLAY_PACKED_ENUM {
|
typedef CLAY_PACKED_ENUM {
|
||||||
|
// (Default) Lays out child elements from left to right with increasing x.
|
||||||
CLAY_LEFT_TO_RIGHT,
|
CLAY_LEFT_TO_RIGHT,
|
||||||
|
// Lays out child elements from top to bottom with increasing y.
|
||||||
CLAY_TOP_TO_BOTTOM,
|
CLAY_TOP_TO_BOTTOM,
|
||||||
} Clay_LayoutDirection;
|
} Clay_LayoutDirection;
|
||||||
|
|
||||||
|
// Controls the alignment along the x axis (horizontal) of child elements.
|
||||||
typedef CLAY_PACKED_ENUM {
|
typedef CLAY_PACKED_ENUM {
|
||||||
|
// (Default) Aligns child elements to the left hand side of this element, offset by padding.width.left
|
||||||
CLAY_ALIGN_X_LEFT,
|
CLAY_ALIGN_X_LEFT,
|
||||||
|
// Aligns child elements to the right hand side of this element, offset by padding.width.right
|
||||||
CLAY_ALIGN_X_RIGHT,
|
CLAY_ALIGN_X_RIGHT,
|
||||||
|
// Aligns child elements horizontally to the center of this element
|
||||||
CLAY_ALIGN_X_CENTER,
|
CLAY_ALIGN_X_CENTER,
|
||||||
} Clay_LayoutAlignmentX;
|
} Clay_LayoutAlignmentX;
|
||||||
|
|
||||||
|
// Controls the alignment along the y axis (vertical) of child elements.
|
||||||
typedef CLAY_PACKED_ENUM {
|
typedef CLAY_PACKED_ENUM {
|
||||||
|
// (Default) Aligns child elements to the top of this element, offset by padding.width.top
|
||||||
CLAY_ALIGN_Y_TOP,
|
CLAY_ALIGN_Y_TOP,
|
||||||
|
// Aligns child elements to the bottom of this element, offset by padding.width.bottom
|
||||||
CLAY_ALIGN_Y_BOTTOM,
|
CLAY_ALIGN_Y_BOTTOM,
|
||||||
|
// Aligns child elements vertiically to the center of this element
|
||||||
CLAY_ALIGN_Y_CENTER,
|
CLAY_ALIGN_Y_CENTER,
|
||||||
} Clay_LayoutAlignmentY;
|
} Clay_LayoutAlignmentY;
|
||||||
|
|
||||||
|
// Controls how the element takes up space inside its parent container.
|
||||||
typedef CLAY_PACKED_ENUM {
|
typedef CLAY_PACKED_ENUM {
|
||||||
|
// (default) Wraps tightly to the size of the element's contents.
|
||||||
CLAY__SIZING_TYPE_FIT,
|
CLAY__SIZING_TYPE_FIT,
|
||||||
|
// Expands along this axis to fill available space in the parent element, sharing it with other GROW elements.
|
||||||
CLAY__SIZING_TYPE_GROW,
|
CLAY__SIZING_TYPE_GROW,
|
||||||
|
// Expects 0-1 range. Clamps the axis size to a percent of the parent container's axis size minus padding and child gaps.
|
||||||
CLAY__SIZING_TYPE_PERCENT,
|
CLAY__SIZING_TYPE_PERCENT,
|
||||||
|
// Clamps the axis size to an exact size in pixels.
|
||||||
CLAY__SIZING_TYPE_FIXED,
|
CLAY__SIZING_TYPE_FIXED,
|
||||||
} Clay__SizingType;
|
} Clay__SizingType;
|
||||||
|
|
||||||
|
// Controls how child elements are aligned on each axis.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Clay_LayoutAlignmentX x;
|
Clay_LayoutAlignmentX x; // Controls alignment of children along the x axis.
|
||||||
Clay_LayoutAlignmentY y;
|
Clay_LayoutAlignmentY y; // Controls alignment of children along the y axis.
|
||||||
} Clay_ChildAlignment;
|
} 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 {
|
||||||
float min;
|
float min; // The smallest final size of the element on this axis will be this value in pixels.
|
||||||
float max;
|
float max; // The largest final size of the element on this axis will be this value in pixels.
|
||||||
} Clay_SizingMinMax;
|
} Clay_SizingMinMax;
|
||||||
|
|
||||||
|
// Controls the sizing of this element along one axis inside its parent container.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
union {
|
union {
|
||||||
Clay_SizingMinMax minMax;
|
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;
|
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.
|
||||||
} size;
|
} size;
|
||||||
Clay__SizingType type;
|
Clay__SizingType type; // Controls how the element takes up space inside its parent container.
|
||||||
} Clay_SizingAxis;
|
} Clay_SizingAxis;
|
||||||
|
|
||||||
|
// Controls the sizing of this element along one axis inside its parent container.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Clay_SizingAxis width;
|
Clay_SizingAxis width; // Controls the width sizing of the element, along the x axis.
|
||||||
Clay_SizingAxis height;
|
Clay_SizingAxis height; // Controls the height sizing of the element, along the y axis.
|
||||||
} Clay_Sizing;
|
} 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 {
|
||||||
uint16_t left;
|
uint16_t left;
|
||||||
uint16_t right;
|
uint16_t right;
|
||||||
@ -280,46 +303,70 @@ typedef struct {
|
|||||||
|
|
||||||
CLAY__WRAPPER_STRUCT(Clay_Padding);
|
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_Sizing sizing;
|
Clay_Sizing sizing; // Controls the sizing of this element inside it's parent container, including FIT, GROW, PERCENT and FIXED sizing.
|
||||||
Clay_Padding padding;
|
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;
|
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).
|
||||||
Clay_ChildAlignment childAlignment;
|
Clay_ChildAlignment childAlignment; // Controls how child elements are aligned on each axis.
|
||||||
Clay_LayoutDirection layoutDirection;
|
Clay_LayoutDirection layoutDirection; // Controls the direction in which child elements will be automatically laid out.
|
||||||
} Clay_LayoutConfig;
|
} Clay_LayoutConfig;
|
||||||
|
|
||||||
CLAY__WRAPPER_STRUCT(Clay_LayoutConfig);
|
CLAY__WRAPPER_STRUCT(Clay_LayoutConfig);
|
||||||
|
|
||||||
extern Clay_LayoutConfig CLAY_LAYOUT_DEFAULT;
|
extern Clay_LayoutConfig CLAY_LAYOUT_DEFAULT;
|
||||||
|
|
||||||
// Text
|
// Controls how text "wraps", that is how it is broken into multiple lines when there is insufficient horizontal space.
|
||||||
typedef CLAY_PACKED_ENUM {
|
typedef CLAY_PACKED_ENUM {
|
||||||
|
// (default) breaks on whitespace characters.
|
||||||
CLAY_TEXT_WRAP_WORDS,
|
CLAY_TEXT_WRAP_WORDS,
|
||||||
|
// Don't break on space characters, only on newlines.
|
||||||
CLAY_TEXT_WRAP_NEWLINES,
|
CLAY_TEXT_WRAP_NEWLINES,
|
||||||
|
// Disable text wrapping entirely.
|
||||||
CLAY_TEXT_WRAP_NONE,
|
CLAY_TEXT_WRAP_NONE,
|
||||||
} Clay_TextElementConfigWrapMode;
|
} Clay_TextElementConfigWrapMode;
|
||||||
|
|
||||||
|
// Controls various functionality related to text elements.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
// The RGBA color of the font to render, conventionally specified as 0-255.
|
||||||
Clay_Color textColor;
|
Clay_Color textColor;
|
||||||
|
// An integer transparently passed to Clay_MeasureText to identify the font to use.
|
||||||
|
// The debug view will pass fontId = 0 for its internal text.
|
||||||
uint16_t fontId;
|
uint16_t fontId;
|
||||||
|
// Controls the size of the font. Handled by the function provided to Clay_MeasureText.
|
||||||
uint16_t fontSize;
|
uint16_t fontSize;
|
||||||
|
// Controls extra horizontal spacing between characters. Handled by the function provided to Clay_MeasureText.
|
||||||
uint16_t letterSpacing;
|
uint16_t letterSpacing;
|
||||||
|
// Controls additional vertical space between wrapped lines of text.
|
||||||
uint16_t lineHeight;
|
uint16_t lineHeight;
|
||||||
|
// Controls how text "wraps", that is how it is broken into multiple lines when there is insufficient horizontal space.
|
||||||
|
// CLAY_TEXT_WRAP_WORDS (default) breaks on whitespace characters.
|
||||||
|
// CLAY_TEXT_WRAP_NEWLINES doesn't break on space characters, only on newlines.
|
||||||
|
// CLAY_TEXT_WRAP_NONE disables wrapping entirely.
|
||||||
Clay_TextElementConfigWrapMode wrapMode;
|
Clay_TextElementConfigWrapMode wrapMode;
|
||||||
|
// When set to true, clay will hash the entire text contents of this string as an identifier for its internal
|
||||||
|
// text measurement cache, rather than just the pointer and length. This will incur significant performance cost for
|
||||||
|
// long bodies of text.
|
||||||
bool hashStringContents;
|
bool hashStringContents;
|
||||||
} Clay_TextElementConfig;
|
} Clay_TextElementConfig;
|
||||||
|
|
||||||
CLAY__WRAPPER_STRUCT(Clay_TextElementConfig);
|
CLAY__WRAPPER_STRUCT(Clay_TextElementConfig);
|
||||||
|
|
||||||
// Image
|
// Image --------------------------------
|
||||||
|
|
||||||
|
// Controls various settings related to image elements.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void* imageData;
|
void* imageData; // A transparent pointer used to pass image data through to the renderer.
|
||||||
Clay_Dimensions sourceDimensions;
|
Clay_Dimensions sourceDimensions; // The original dimensions of the source image, used to control aspect ratio.
|
||||||
} Clay_ImageElementConfig;
|
} Clay_ImageElementConfig;
|
||||||
|
|
||||||
CLAY__WRAPPER_STRUCT(Clay_ImageElementConfig);
|
CLAY__WRAPPER_STRUCT(Clay_ImageElementConfig);
|
||||||
|
|
||||||
// Floating
|
// Floating -----------------------------
|
||||||
|
|
||||||
|
// Controls where a floating element is offset relative to its parent element.
|
||||||
|
// Note: see https://github.com/user-attachments/assets/b8c6dfaa-c1b1-41a4-be55-013473e4a6ce for a visual explanation.
|
||||||
typedef CLAY_PACKED_ENUM {
|
typedef CLAY_PACKED_ENUM {
|
||||||
CLAY_ATTACH_POINT_LEFT_TOP,
|
CLAY_ATTACH_POINT_LEFT_TOP,
|
||||||
CLAY_ATTACH_POINT_LEFT_CENTER,
|
CLAY_ATTACH_POINT_LEFT_CENTER,
|
||||||
@ -332,190 +379,322 @@ typedef CLAY_PACKED_ENUM {
|
|||||||
CLAY_ATTACH_POINT_RIGHT_BOTTOM,
|
CLAY_ATTACH_POINT_RIGHT_BOTTOM,
|
||||||
} Clay_FloatingAttachPointType;
|
} Clay_FloatingAttachPointType;
|
||||||
|
|
||||||
|
// Controls where a floating element is offset relative to its parent element.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Clay_FloatingAttachPointType element;
|
Clay_FloatingAttachPointType element; // Controls the origin point on a floating element that attaches to its parent.
|
||||||
Clay_FloatingAttachPointType parent;
|
Clay_FloatingAttachPointType parent; // Controls the origin point on the parent element that the floating element attaches to.
|
||||||
} Clay_FloatingAttachPoints;
|
} Clay_FloatingAttachPoints;
|
||||||
|
|
||||||
|
// Controls how mouse pointer events like hover and click are captured or passed through to elements underneath a floating element.
|
||||||
typedef CLAY_PACKED_ENUM {
|
typedef CLAY_PACKED_ENUM {
|
||||||
|
// (default) "Capture" the pointer event and don't allow events like hover and click to pass through to elements underneath.
|
||||||
CLAY_POINTER_CAPTURE_MODE_CAPTURE,
|
CLAY_POINTER_CAPTURE_MODE_CAPTURE,
|
||||||
// CLAY_POINTER_CAPTURE_MODE_PARENT, TODO pass pointer through to attached parent
|
// CLAY_POINTER_CAPTURE_MODE_PARENT, TODO pass pointer through to attached parent
|
||||||
|
|
||||||
|
// Transparently pass through pointer events like hover and click to elements underneath the floating element.
|
||||||
CLAY_POINTER_CAPTURE_MODE_PASSTHROUGH,
|
CLAY_POINTER_CAPTURE_MODE_PASSTHROUGH,
|
||||||
} Clay_PointerCaptureMode;
|
} Clay_PointerCaptureMode;
|
||||||
|
|
||||||
|
// Controls which element a floating element is "attached" to (i.e. relative offset from).
|
||||||
typedef CLAY_PACKED_ENUM {
|
typedef CLAY_PACKED_ENUM {
|
||||||
|
// (default) Disables floating for this element.
|
||||||
CLAY_ATTACH_TO_NONE,
|
CLAY_ATTACH_TO_NONE,
|
||||||
|
// Attaches this floating element to its parent, positioned based on the .attachPoints and .offset fields.
|
||||||
CLAY_ATTACH_TO_PARENT,
|
CLAY_ATTACH_TO_PARENT,
|
||||||
|
// Attaches this floating element to an element with a specific ID, specified with the .parentId field. positioned based on the .attachPoints and .offset fields.
|
||||||
CLAY_ATTACH_TO_ELEMENT_WITH_ID,
|
CLAY_ATTACH_TO_ELEMENT_WITH_ID,
|
||||||
|
// Attaches this floating element to the root of the layout, which combined with the .offset field provides functionality similar to "absolute positioning".
|
||||||
CLAY_ATTACH_TO_ROOT,
|
CLAY_ATTACH_TO_ROOT,
|
||||||
} Clay_FloatingAttachToElement;
|
} Clay_FloatingAttachToElement;
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
// Offsets this floating element by the provided x,y coordinates from its attachPoints.
|
||||||
Clay_Vector2 offset;
|
Clay_Vector2 offset;
|
||||||
|
// Expands the boundaries of the outer floating element without affecting its children.
|
||||||
Clay_Dimensions expand;
|
Clay_Dimensions expand;
|
||||||
|
// When used in conjunction with .attachTo = CLAY_ATTACH_TO_ELEMENT_WITH_ID, attaches this floating element to the element in the hierarchy with the provided ID.
|
||||||
|
// Hint: attach the ID to the other element with .id = CLAY_ID("yourId"), and specify the id the same way, with .parentId = CLAY_ID("yourId").id
|
||||||
uint32_t parentId;
|
uint32_t parentId;
|
||||||
|
// Controls the z index of this floating element and all its children. Floating elements are sorted in ascending z order before output.
|
||||||
|
// zIndex is also passed to the renderer for all elements contained within this floating element.
|
||||||
int16_t zIndex;
|
int16_t zIndex;
|
||||||
|
// Controls how mouse pointer events like hover and click are captured or passed through to elements underneath / behind a floating element.
|
||||||
|
// Enum is of the form CLAY_ATTACH_POINT_foo_bar. See Clay_FloatingAttachPoints for more details.
|
||||||
|
// Note: see <img src="https://github.com/user-attachments/assets/b8c6dfaa-c1b1-41a4-be55-013473e4a6ce />
|
||||||
|
// and <img src="https://github.com/user-attachments/assets/ebe75e0d-1904-46b0-982d-418f929d1516 /> for a visual explanation.
|
||||||
Clay_FloatingAttachPoints attachPoints;
|
Clay_FloatingAttachPoints attachPoints;
|
||||||
|
// Controls how mouse pointer events like hover and click are captured or passed through to elements underneath a floating element.
|
||||||
|
// CLAY_POINTER_CAPTURE_MODE_CAPTURE (default) - "Capture" the pointer event and don't allow events like hover and click to pass through to elements underneath.
|
||||||
|
// CLAY_POINTER_CAPTURE_MODE_PASSTHROUGH - Transparently pass through pointer events like hover and click to elements underneath the floating element.
|
||||||
Clay_PointerCaptureMode pointerCaptureMode;
|
Clay_PointerCaptureMode pointerCaptureMode;
|
||||||
|
// Controls which element a floating element is "attached" to (i.e. relative offset from).
|
||||||
|
// CLAY_ATTACH_TO_NONE (default) - Disables floating for this element.
|
||||||
|
// CLAY_ATTACH_TO_PARENT - Attaches this floating element to its parent, positioned based on the .attachPoints and .offset fields.
|
||||||
|
// CLAY_ATTACH_TO_ELEMENT_WITH_ID - Attaches this floating element to an element with a specific ID, specified with the .parentId field. positioned based on the .attachPoints and .offset fields.
|
||||||
|
// CLAY_ATTACH_TO_ROOT - Attaches this floating element to the root of the layout, which combined with the .offset field provides functionality similar to "absolute positioning".
|
||||||
Clay_FloatingAttachToElement attachTo;
|
Clay_FloatingAttachToElement attachTo;
|
||||||
} Clay_FloatingElementConfig;
|
} Clay_FloatingElementConfig;
|
||||||
|
|
||||||
CLAY__WRAPPER_STRUCT(Clay_FloatingElementConfig);
|
CLAY__WRAPPER_STRUCT(Clay_FloatingElementConfig);
|
||||||
|
|
||||||
// Custom
|
// Custom -----------------------------
|
||||||
|
|
||||||
|
// Controls various settings related to custom elements.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
// A transparent pointer through which you can pass custom data to the renderer.
|
||||||
|
// Generates CUSTOM render commands.
|
||||||
void* customData;
|
void* customData;
|
||||||
} Clay_CustomElementConfig;
|
} Clay_CustomElementConfig;
|
||||||
|
|
||||||
CLAY__WRAPPER_STRUCT(Clay_CustomElementConfig);
|
CLAY__WRAPPER_STRUCT(Clay_CustomElementConfig);
|
||||||
|
|
||||||
// Scroll
|
// 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 {
|
||||||
bool horizontal;
|
bool horizontal; // Clip overflowing elements on the X axis and allow scrolling left and right.
|
||||||
bool vertical;
|
bool vertical; // Clip overflowing elements on the YU axis and allow scrolling up and down.
|
||||||
} Clay_ScrollElementConfig;
|
} Clay_ScrollElementConfig;
|
||||||
|
|
||||||
CLAY__WRAPPER_STRUCT(Clay_ScrollElementConfig);
|
CLAY__WRAPPER_STRUCT(Clay_ScrollElementConfig);
|
||||||
|
|
||||||
// Shared
|
// Border -----------------------------
|
||||||
typedef struct {
|
|
||||||
Clay_Color backgroundColor;
|
|
||||||
Clay_CornerRadius cornerRadius;
|
|
||||||
void* userData;
|
|
||||||
} Clay_SharedElementConfig;
|
|
||||||
|
|
||||||
CLAY__WRAPPER_STRUCT(Clay_SharedElementConfig);
|
// Controls the widths of individual element borders.
|
||||||
|
|
||||||
// Border
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t left;
|
uint16_t left;
|
||||||
uint16_t right;
|
uint16_t right;
|
||||||
uint16_t top;
|
uint16_t top;
|
||||||
uint16_t bottom;
|
uint16_t bottom;
|
||||||
|
// Creates borders between each child element, depending on the .layoutDirection.
|
||||||
|
// e.g. for LEFT_TO_RIGHT, borders will be vertical lines, and for TOP_TO_BOTTOM borders will be horizontal lines.
|
||||||
|
// .betweenChildren borders will result in individual RECTANGLE render commands being generated.
|
||||||
uint16_t betweenChildren;
|
uint16_t betweenChildren;
|
||||||
} Clay_BorderWidth;
|
} Clay_BorderWidth;
|
||||||
|
|
||||||
|
// Controls settings related to element borders.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Clay_Color color;
|
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;
|
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;
|
} Clay_BorderElementConfig;
|
||||||
|
|
||||||
CLAY__WRAPPER_STRUCT(Clay_BorderElementConfig);
|
CLAY__WRAPPER_STRUCT(Clay_BorderElementConfig);
|
||||||
|
|
||||||
|
// Render Command Data -----------------------------
|
||||||
|
|
||||||
|
// Render command data when commandType == CLAY_RENDER_COMMAND_TYPE_TEXT
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
// A string slice containing the text to be rendered.
|
||||||
|
// Note: this is not guaranteed to be null terminated.
|
||||||
Clay_StringSlice stringContents;
|
Clay_StringSlice stringContents;
|
||||||
|
// Conventionally represented as 0-255 for each channel, but interpretation is up to the renderer.
|
||||||
Clay_Color textColor;
|
Clay_Color textColor;
|
||||||
|
// An integer representing the font to use to render this text, transparently passed through from the text declaration.
|
||||||
uint16_t fontId;
|
uint16_t fontId;
|
||||||
uint16_t fontSize;
|
uint16_t fontSize;
|
||||||
|
// Specifies the extra whitespace gap in pixels between each character.
|
||||||
uint16_t letterSpacing;
|
uint16_t letterSpacing;
|
||||||
|
// The height of the bounding box for this line of text.
|
||||||
uint16_t lineHeight;
|
uint16_t lineHeight;
|
||||||
} Clay_TextRenderData;
|
} Clay_TextRenderData;
|
||||||
|
|
||||||
|
// Render command data when commandType == CLAY_RENDER_COMMAND_TYPE_RECTANGLE
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
// 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;
|
Clay_Color backgroundColor;
|
||||||
|
// 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.
|
||||||
Clay_CornerRadius cornerRadius;
|
Clay_CornerRadius cornerRadius;
|
||||||
} Clay_RectangleRenderData;
|
} Clay_RectangleRenderData;
|
||||||
|
|
||||||
|
// Render command data when commandType == CLAY_RENDER_COMMAND_TYPE_IMAGE
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
// 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.
|
||||||
Clay_Color backgroundColor;
|
Clay_Color backgroundColor;
|
||||||
|
// Controls the "radius", or corner rounding of this image.
|
||||||
|
// The rounding is determined by drawing a circle inset into the element corner by (radius, radius) pixels.
|
||||||
Clay_CornerRadius cornerRadius;
|
Clay_CornerRadius cornerRadius;
|
||||||
|
// The original dimensions of the source image, used to control aspect ratio.
|
||||||
Clay_Dimensions sourceDimensions;
|
Clay_Dimensions sourceDimensions;
|
||||||
|
// A pointer transparently passed through from the original element definition, typically used to represent image data.
|
||||||
void* imageData;
|
void* imageData;
|
||||||
} Clay_ImageRenderData;
|
} Clay_ImageRenderData;
|
||||||
|
|
||||||
|
// Render command data when commandType == CLAY_RENDER_COMMAND_TYPE_CUSTOM
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
// 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;
|
Clay_Color backgroundColor;
|
||||||
|
// Controls the "radius", or corner rounding of this custom element.
|
||||||
|
// The rounding is determined by drawing a circle inset into the element corner by (radius, radius) pixels.
|
||||||
Clay_CornerRadius cornerRadius;
|
Clay_CornerRadius cornerRadius;
|
||||||
|
// A pointer transparently passed through from the original element definition.
|
||||||
void* customData;
|
void* customData;
|
||||||
} Clay_CustomRenderData;
|
} Clay_CustomRenderData;
|
||||||
|
|
||||||
|
// Render command data when commandType == CLAY_RENDER_COMMAND_TYPE_SCISSOR_START || commandType == CLAY_RENDER_COMMAND_TYPE_SCISSOR_END
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool horizontal;
|
bool horizontal;
|
||||||
bool vertical;
|
bool vertical;
|
||||||
} Clay_ScrollRenderData;
|
} Clay_ScrollRenderData;
|
||||||
|
|
||||||
|
// Render command data when commandType == CLAY_RENDER_COMMAND_TYPE_BORDER
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
// 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;
|
Clay_Color color;
|
||||||
|
// Specifies the "radius", or corner rounding of this border element.
|
||||||
|
// The rounding is determined by drawing a circle inset into the element corner by (radius, radius) pixels.
|
||||||
Clay_CornerRadius cornerRadius;
|
Clay_CornerRadius cornerRadius;
|
||||||
|
// Controls individual border side widths.
|
||||||
Clay_BorderWidth width;
|
Clay_BorderWidth width;
|
||||||
} Clay_BorderRenderData;
|
} Clay_BorderRenderData;
|
||||||
|
|
||||||
|
// A struct union containing data specific to this command's .commandType
|
||||||
typedef union {
|
typedef union {
|
||||||
|
// Render command data when commandType == CLAY_RENDER_COMMAND_TYPE_RECTANGLE
|
||||||
Clay_RectangleRenderData rectangle;
|
Clay_RectangleRenderData rectangle;
|
||||||
|
// Render command data when commandType == CLAY_RENDER_COMMAND_TYPE_TEXT
|
||||||
Clay_TextRenderData text;
|
Clay_TextRenderData text;
|
||||||
|
// Render command data when commandType == CLAY_RENDER_COMMAND_TYPE_IMAGE
|
||||||
Clay_ImageRenderData image;
|
Clay_ImageRenderData image;
|
||||||
|
// Render command data when commandType == CLAY_RENDER_COMMAND_TYPE_CUSTOM
|
||||||
Clay_CustomRenderData custom;
|
Clay_CustomRenderData custom;
|
||||||
|
// Render command data when commandType == CLAY_RENDER_COMMAND_TYPE_BORDER
|
||||||
Clay_BorderRenderData border;
|
Clay_BorderRenderData border;
|
||||||
|
// Render command data when commandType == CLAY_RENDER_COMMAND_TYPE_SCROLL
|
||||||
Clay_ScrollRenderData scroll;
|
Clay_ScrollRenderData scroll;
|
||||||
} Clay_RenderData;
|
} Clay_RenderData;
|
||||||
|
|
||||||
// Miscellaneous Structs & Enums ---------------------------------
|
// Miscellaneous Structs & Enums ---------------------------------
|
||||||
|
|
||||||
|
// Data representing the current internal state of a scrolling element.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
// Note: This is a pointer to the real internal scroll position, mutating it may cause a change in final layout.
|
// 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.
|
// Intended for use with external functionality that modifies scroll position, such as scroll bars or auto scrolling.
|
||||||
Clay_Vector2 *scrollPosition;
|
Clay_Vector2 *scrollPosition;
|
||||||
|
// The bounding box of the scroll element.
|
||||||
Clay_Dimensions scrollContainerDimensions;
|
Clay_Dimensions scrollContainerDimensions;
|
||||||
|
// The outer dimensions of the inner scroll container content, including the padding of the parent scroll container.
|
||||||
Clay_Dimensions contentDimensions;
|
Clay_Dimensions contentDimensions;
|
||||||
|
// The config that was originally passed to the scroll element.
|
||||||
Clay_ScrollElementConfig config;
|
Clay_ScrollElementConfig config;
|
||||||
// Indicates whether an actual scroll container matched the provided ID or if the default struct was returned.
|
// Indicates whether an actual scroll container matched the provided ID or if the default struct was returned.
|
||||||
bool found;
|
bool found;
|
||||||
} Clay_ScrollContainerData;
|
} Clay_ScrollContainerData;
|
||||||
|
|
||||||
typedef struct
|
// Bounding box and other data for a specific UI element.
|
||||||
{
|
typedef struct {
|
||||||
|
// The rectangle that encloses this UI element, with the position relative to the root of the layout.
|
||||||
Clay_BoundingBox boundingBox;
|
Clay_BoundingBox boundingBox;
|
||||||
// Indicates whether an actual Element matched the provided ID or if the default struct was returned.
|
// Indicates whether an actual Element matched the provided ID or if the default struct was returned.
|
||||||
bool found;
|
bool found;
|
||||||
} Clay_ElementData;
|
} Clay_ElementData;
|
||||||
|
|
||||||
|
// Used by renderers to determine specific handling for each render command.
|
||||||
typedef CLAY_PACKED_ENUM {
|
typedef CLAY_PACKED_ENUM {
|
||||||
|
// This command type should be skipped.
|
||||||
CLAY_RENDER_COMMAND_TYPE_NONE,
|
CLAY_RENDER_COMMAND_TYPE_NONE,
|
||||||
|
// The renderer should draw a solid color rectangle.
|
||||||
CLAY_RENDER_COMMAND_TYPE_RECTANGLE,
|
CLAY_RENDER_COMMAND_TYPE_RECTANGLE,
|
||||||
|
// The renderer should draw a colored border inset into the bounding box.
|
||||||
CLAY_RENDER_COMMAND_TYPE_BORDER,
|
CLAY_RENDER_COMMAND_TYPE_BORDER,
|
||||||
|
// The renderer should draw text.
|
||||||
CLAY_RENDER_COMMAND_TYPE_TEXT,
|
CLAY_RENDER_COMMAND_TYPE_TEXT,
|
||||||
|
// The renderer should draw an image.
|
||||||
CLAY_RENDER_COMMAND_TYPE_IMAGE,
|
CLAY_RENDER_COMMAND_TYPE_IMAGE,
|
||||||
|
// The renderer should begin clipping all future draw commands, only rendering content that falls within the provided boundingBox.
|
||||||
CLAY_RENDER_COMMAND_TYPE_SCISSOR_START,
|
CLAY_RENDER_COMMAND_TYPE_SCISSOR_START,
|
||||||
|
// The renderer should finish any previously active clipping, and begin rendering elements in full again.
|
||||||
CLAY_RENDER_COMMAND_TYPE_SCISSOR_END,
|
CLAY_RENDER_COMMAND_TYPE_SCISSOR_END,
|
||||||
|
// The renderer should provide a custom implementation for handling this render command based on its .customData
|
||||||
CLAY_RENDER_COMMAND_TYPE_CUSTOM,
|
CLAY_RENDER_COMMAND_TYPE_CUSTOM,
|
||||||
} Clay_RenderCommandType;
|
} Clay_RenderCommandType;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
// A rectangular box that fully encloses this UI element, with the position relative to the root of the layout.
|
||||||
Clay_BoundingBox boundingBox;
|
Clay_BoundingBox boundingBox;
|
||||||
|
// A struct union containing data specific to this command's commandType.
|
||||||
Clay_RenderData renderData;
|
Clay_RenderData renderData;
|
||||||
// A pointer passed through from the element declaration
|
// A pointer transparently passed through from the original element declaration.
|
||||||
void *userData;
|
void *userData;
|
||||||
|
// The id of this element, transparently passed through from the original element declaration.
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
|
// The z order required for drawing this command correctly.
|
||||||
|
// Note: the render command array is already sorted in ascending order, and will produce correct results if drawn in naive order.
|
||||||
|
// This field is intended for use in batching renderers for improved performance.
|
||||||
int16_t zIndex;
|
int16_t zIndex;
|
||||||
|
// Specifies how to handle rendering of this command.
|
||||||
|
// CLAY_RENDER_COMMAND_TYPE_RECTANGLE - The renderer should draw a solid color rectangle.
|
||||||
|
// CLAY_RENDER_COMMAND_TYPE_BORDER - The renderer should draw a colored border inset into the bounding box.
|
||||||
|
// CLAY_RENDER_COMMAND_TYPE_TEXT - The renderer should draw text.
|
||||||
|
// CLAY_RENDER_COMMAND_TYPE_IMAGE - The renderer should draw an image.
|
||||||
|
// CLAY_RENDER_COMMAND_TYPE_SCISSOR_START - The renderer should begin clipping all future draw commands, only rendering content that falls within the provided boundingBox.
|
||||||
|
// CLAY_RENDER_COMMAND_TYPE_SCISSOR_END - The renderer should finish any previously active clipping, and begin rendering elements in full again.
|
||||||
|
// CLAY_RENDER_COMMAND_TYPE_CUSTOM - The renderer should provide a custom implementation for handling this render command based on its .customData
|
||||||
Clay_RenderCommandType commandType;
|
Clay_RenderCommandType commandType;
|
||||||
} Clay_RenderCommand;
|
} Clay_RenderCommand;
|
||||||
|
|
||||||
|
// A sized array of render commands.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
// The underlying max capacity of the array, not necessarily all initialized.
|
||||||
int32_t capacity;
|
int32_t capacity;
|
||||||
|
// The number of initialized elements in this array. Used for loops and iteration.
|
||||||
int32_t length;
|
int32_t length;
|
||||||
|
// A pointer to the first element in the internal array.
|
||||||
Clay_RenderCommand* internalArray;
|
Clay_RenderCommand* internalArray;
|
||||||
} Clay_RenderCommandArray;
|
} Clay_RenderCommandArray;
|
||||||
|
|
||||||
|
// Represents the current state of interaction with clay this frame.
|
||||||
typedef CLAY_PACKED_ENUM {
|
typedef CLAY_PACKED_ENUM {
|
||||||
|
// A left mouse click, or touch occurred this frame.
|
||||||
CLAY_POINTER_DATA_PRESSED_THIS_FRAME,
|
CLAY_POINTER_DATA_PRESSED_THIS_FRAME,
|
||||||
|
// The left mouse button click or touch happened at some point in the past, and is still currently held down this frame.
|
||||||
CLAY_POINTER_DATA_PRESSED,
|
CLAY_POINTER_DATA_PRESSED,
|
||||||
|
// The left mouse button click or touch was released this frame.
|
||||||
CLAY_POINTER_DATA_RELEASED_THIS_FRAME,
|
CLAY_POINTER_DATA_RELEASED_THIS_FRAME,
|
||||||
|
// The left mouse button click or touch is not currently down / was released at some point in the past.
|
||||||
CLAY_POINTER_DATA_RELEASED,
|
CLAY_POINTER_DATA_RELEASED,
|
||||||
} Clay_PointerDataInteractionState;
|
} Clay_PointerDataInteractionState;
|
||||||
|
|
||||||
|
// Information on the current state of pointer interactions this frame.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
// The position of the mouse / touch / pointer relative to the root of the layout.
|
||||||
Clay_Vector2 position;
|
Clay_Vector2 position;
|
||||||
|
// Represents the current state of interaction with clay this frame.
|
||||||
|
// CLAY_POINTER_DATA_PRESSED_THIS_FRAME - A left mouse click, or touch occurred this frame.
|
||||||
|
// CLAY_POINTER_DATA_PRESSED - The left mouse button click or touch happened at some point in the past, and is still currently held down this frame.
|
||||||
|
// CLAY_POINTER_DATA_RELEASED_THIS_FRAME - The left mouse button click or touch was released this frame.
|
||||||
|
// CLAY_POINTER_DATA_RELEASED - The left mouse button click or touch is not currently down / was released at some point in the past.
|
||||||
Clay_PointerDataInteractionState state;
|
Clay_PointerDataInteractionState state;
|
||||||
} Clay_PointerData;
|
} Clay_PointerData;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
// 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;
|
Clay_ElementId id;
|
||||||
|
// Controls various settings that affect the size and position of an element, as well as the sizes and positions of any child elements.
|
||||||
Clay_LayoutConfig layout;
|
Clay_LayoutConfig layout;
|
||||||
|
// Controls the background color of the resulting element.
|
||||||
|
// By convention specified as 0-255, but interpretation is up to the renderer.
|
||||||
|
// If no other config is specified, .backgroundColor will generate a RECTANGLE render command, otherwise it will be passed as a property to IMAGE or CUSTOM render commands.
|
||||||
Clay_Color backgroundColor;
|
Clay_Color backgroundColor;
|
||||||
|
// Controls the "radius", or corner rounding of elements, including rectangles, borders and images.
|
||||||
Clay_CornerRadius cornerRadius;
|
Clay_CornerRadius cornerRadius;
|
||||||
|
// Controls settings related to image elements.
|
||||||
Clay_ImageElementConfig image;
|
Clay_ImageElementConfig image;
|
||||||
|
// Controls whether and how an element "floats", which means it layers over the top of other elements in z order, and doesn't affect the position and size of siblings or parent elements.
|
||||||
|
// Note: in order to activate floating, .floating.attachTo must be set to something other than the default value.
|
||||||
Clay_FloatingElementConfig floating;
|
Clay_FloatingElementConfig floating;
|
||||||
|
// Used to create CUSTOM render commands, usually to render element types not supported by Clay.
|
||||||
Clay_CustomElementConfig custom;
|
Clay_CustomElementConfig custom;
|
||||||
|
// Controls whether an element should clip its contents and allow scrolling rather than expanding to contain them.
|
||||||
Clay_ScrollElementConfig scroll;
|
Clay_ScrollElementConfig scroll;
|
||||||
|
// Controls settings related to element borders, and will generate BORDER render commands.
|
||||||
Clay_BorderElementConfig border;
|
Clay_BorderElementConfig border;
|
||||||
// A pointer that will be transparently passed through to resulting render commands.
|
// A pointer that will be transparently passed through to resulting render commands.
|
||||||
void *userData;
|
void *userData;
|
||||||
@ -523,68 +702,153 @@ typedef struct {
|
|||||||
|
|
||||||
CLAY__WRAPPER_STRUCT(Clay_ElementDeclaration);
|
CLAY__WRAPPER_STRUCT(Clay_ElementDeclaration);
|
||||||
|
|
||||||
|
// Represents the type of error clay encountered while computing layout.
|
||||||
typedef CLAY_PACKED_ENUM {
|
typedef CLAY_PACKED_ENUM {
|
||||||
|
// A text measurement function wasn't provided using Clay_SetMeasureTextFunction(), or the provided function was null.
|
||||||
CLAY_ERROR_TYPE_TEXT_MEASUREMENT_FUNCTION_NOT_PROVIDED,
|
CLAY_ERROR_TYPE_TEXT_MEASUREMENT_FUNCTION_NOT_PROVIDED,
|
||||||
|
// 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().
|
||||||
CLAY_ERROR_TYPE_ARENA_CAPACITY_EXCEEDED,
|
CLAY_ERROR_TYPE_ARENA_CAPACITY_EXCEEDED,
|
||||||
|
// Clay ran out of capacity in its internal array for storing elements. This limit can be increased with Clay_SetMaxElementCount().
|
||||||
CLAY_ERROR_TYPE_ELEMENTS_CAPACITY_EXCEEDED,
|
CLAY_ERROR_TYPE_ELEMENTS_CAPACITY_EXCEEDED,
|
||||||
|
// Clay ran out of capacity in its internal array for storing elements. This limit can be increased with Clay_SetMaxMeasureTextCacheWordCount().
|
||||||
CLAY_ERROR_TYPE_TEXT_MEASUREMENT_CAPACITY_EXCEEDED,
|
CLAY_ERROR_TYPE_TEXT_MEASUREMENT_CAPACITY_EXCEEDED,
|
||||||
|
// Two elements were declared with exactly the same ID within one layout.
|
||||||
CLAY_ERROR_TYPE_DUPLICATE_ID,
|
CLAY_ERROR_TYPE_DUPLICATE_ID,
|
||||||
|
// A floating element was declared using CLAY_ATTACH_TO_ELEMENT_ID and either an invalid .parentId was provided or no element with the provided .parentId was found.
|
||||||
CLAY_ERROR_TYPE_FLOATING_CONTAINER_PARENT_NOT_FOUND,
|
CLAY_ERROR_TYPE_FLOATING_CONTAINER_PARENT_NOT_FOUND,
|
||||||
|
// An element was declared that using CLAY_SIZING_PERCENT but the percentage value was over 1. Percentage values are expected to be in the 0-1 range.
|
||||||
CLAY_ERROR_TYPE_PERCENTAGE_OVER_1,
|
CLAY_ERROR_TYPE_PERCENTAGE_OVER_1,
|
||||||
|
// Clay encountered an internal error. It would be wonderful if you could report this so we can fix it!
|
||||||
CLAY_ERROR_TYPE_INTERNAL_ERROR,
|
CLAY_ERROR_TYPE_INTERNAL_ERROR,
|
||||||
} Clay_ErrorType;
|
} Clay_ErrorType;
|
||||||
|
|
||||||
|
// Data to identify the error that clay has encountered.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
// 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().
|
||||||
|
// CLAY_ERROR_TYPE_ELEMENTS_CAPACITY_EXCEEDED - Clay ran out of capacity in its internal array for storing elements. This limit can be increased with Clay_SetMaxElementCount().
|
||||||
|
// CLAY_ERROR_TYPE_TEXT_MEASUREMENT_CAPACITY_EXCEEDED - Clay ran out of capacity in its internal array for storing elements. This limit can be increased with Clay_SetMaxMeasureTextCacheWordCount().
|
||||||
|
// CLAY_ERROR_TYPE_DUPLICATE_ID - Two elements were declared with exactly the same ID within one layout.
|
||||||
|
// CLAY_ERROR_TYPE_FLOATING_CONTAINER_PARENT_NOT_FOUND - A floating element was declared using CLAY_ATTACH_TO_ELEMENT_ID and either an invalid .parentId was provided or no element with the provided .parentId was found.
|
||||||
|
// CLAY_ERROR_TYPE_PERCENTAGE_OVER_1 - An element was declared that using CLAY_SIZING_PERCENT but the percentage value was over 1. Percentage values are expected to be in the 0-1 range.
|
||||||
|
// CLAY_ERROR_TYPE_INTERNAL_ERROR - Clay encountered an internal error. It would be wonderful if you could report this so we can fix it!
|
||||||
Clay_ErrorType errorType;
|
Clay_ErrorType errorType;
|
||||||
|
// A string containing human-readable error text that explains the error in more detail.
|
||||||
Clay_String errorText;
|
Clay_String errorText;
|
||||||
|
// A transparent pointer passed through from when the error handler was first provided.
|
||||||
void *userData;
|
void *userData;
|
||||||
} Clay_ErrorData;
|
} Clay_ErrorData;
|
||||||
|
|
||||||
|
// A wrapper struct around Clay's error handler function.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
// A user provided function to call when Clay encounters an error during layout.
|
||||||
void (*errorHandlerFunction)(Clay_ErrorData errorText);
|
void (*errorHandlerFunction)(Clay_ErrorData errorText);
|
||||||
|
// A pointer that will be transparently passed through to the error handler when it is called.
|
||||||
void *userData;
|
void *userData;
|
||||||
} Clay_ErrorHandler;
|
} Clay_ErrorHandler;
|
||||||
|
|
||||||
// Function Forward Declarations ---------------------------------
|
// Function Forward Declarations ---------------------------------
|
||||||
// Public API functions ---
|
|
||||||
|
// Public API functions ------------------------------------------
|
||||||
|
|
||||||
|
// Returns the size, in bytes, of the minimum amount of memory Clay requires to operate at its current settings.
|
||||||
uint32_t Clay_MinMemorySize(void);
|
uint32_t Clay_MinMemorySize(void);
|
||||||
Clay_Arena Clay_CreateArenaWithCapacityAndMemory(uint32_t capacity, void *offset);
|
// Creates an arena for clay to use for its internal allocations, given a certain capacity in bytes and a pointer to an allocation of at least that size.
|
||||||
|
// Intended to be used with Clay_MinMemorySize in the following way:
|
||||||
|
// uint32_t minMemoryRequired = Clay_MinMemorySize();
|
||||||
|
// Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(minMemoryRequired, malloc(minMemoryRequired));
|
||||||
|
Clay_Arena Clay_CreateArenaWithCapacityAndMemory(uint32_t capacity, void *memory);
|
||||||
|
// Sets the state of the "pointer" (i.e. the mouse or touch) in Clay's internal data. Used for detecting and responding to mouse events in the debug view,
|
||||||
|
// as well as for Clay_Hovered() and scroll element handling.
|
||||||
void Clay_SetPointerState(Clay_Vector2 position, bool pointerDown);
|
void Clay_SetPointerState(Clay_Vector2 position, bool pointerDown);
|
||||||
|
// Initialize Clay's internal arena and setup required data before layout can begin. Only needs to be called once.
|
||||||
|
// - arena can be created using Clay_CreateArenaWithCapacityAndMemory()
|
||||||
|
// - layoutDimensions are the initial bounding dimensions of the layout (i.e. the screen width and height for a full screen layout)
|
||||||
|
// - errorHandler is used by Clay to inform you if something has gone wrong in configuration or layout.
|
||||||
Clay_Context* Clay_Initialize(Clay_Arena arena, Clay_Dimensions layoutDimensions, Clay_ErrorHandler errorHandler);
|
Clay_Context* Clay_Initialize(Clay_Arena arena, Clay_Dimensions layoutDimensions, Clay_ErrorHandler errorHandler);
|
||||||
|
// Returns the Context that clay is currently using. Used when using multiple instances of clay simultaneously.
|
||||||
Clay_Context* Clay_GetCurrentContext(void);
|
Clay_Context* Clay_GetCurrentContext(void);
|
||||||
|
// Sets the context that clay will use to compute the layout.
|
||||||
|
// Used to restore a context saved from Clay_GetCurrentContext when using multiple instances of clay simultaneously.
|
||||||
void Clay_SetCurrentContext(Clay_Context* context);
|
void Clay_SetCurrentContext(Clay_Context* context);
|
||||||
|
// Updates the state of Clay's internal scroll data, updating scroll content positions if scrollDelta is non zero, and progressing momentum scrolling.
|
||||||
|
// - enableDragScrolling when set to true will enable mobile device like "touch drag" scroll of scroll containers, including momentum scrolling after the touch has ended.
|
||||||
|
// - scrollDelta is the amount to scroll this frame on each axis in pixels.
|
||||||
|
// - deltaTime is the time in seconds since the last "frame" (scroll update)
|
||||||
void Clay_UpdateScrollContainers(bool enableDragScrolling, Clay_Vector2 scrollDelta, float deltaTime);
|
void Clay_UpdateScrollContainers(bool enableDragScrolling, Clay_Vector2 scrollDelta, float deltaTime);
|
||||||
|
// Updates the layout dimensions in response to the window or outer container being resized.
|
||||||
void Clay_SetLayoutDimensions(Clay_Dimensions dimensions);
|
void Clay_SetLayoutDimensions(Clay_Dimensions dimensions);
|
||||||
|
// Called before starting any layout declarations.
|
||||||
void Clay_BeginLayout(void);
|
void Clay_BeginLayout(void);
|
||||||
|
// Called when all layout declarations are finished.
|
||||||
|
// Computes the layout and generates and returns the array of render commands to draw.
|
||||||
Clay_RenderCommandArray Clay_EndLayout(void);
|
Clay_RenderCommandArray Clay_EndLayout(void);
|
||||||
|
// Calculates a hash ID from the given idString.
|
||||||
|
// Generally only used for dynamic strings when CLAY_ID("stringLiteral") can't be used.
|
||||||
Clay_ElementId Clay_GetElementId(Clay_String idString);
|
Clay_ElementId Clay_GetElementId(Clay_String idString);
|
||||||
|
// Calculates a hash ID from the given idString and index.
|
||||||
|
// - index is used to avoid constructing dynamic ID strings in loops.
|
||||||
|
// Generally only used for dynamic strings when CLAY_IDI("stringLiteral", index) can't be used.
|
||||||
Clay_ElementId Clay_GetElementIdWithIndex(Clay_String idString, uint32_t index);
|
Clay_ElementId Clay_GetElementIdWithIndex(Clay_String idString, uint32_t index);
|
||||||
|
// Returns layout data such as the final calculated bounding box for an element with a given ID.
|
||||||
|
// The returned Clay_ElementData contains a `found` bool that will be true if an element with the provided ID was found.
|
||||||
|
// This ID can be calculated either with CLAY_ID() for string literal IDs, or Clay_GetElementId for dynamic strings.
|
||||||
Clay_ElementData Clay_GetElementData(Clay_ElementId id);
|
Clay_ElementData Clay_GetElementData(Clay_ElementId id);
|
||||||
|
// Returns true if the pointer position provided by Clay_SetPointerState is within the current element's bounding box.
|
||||||
|
// Works during element declaration, e.g. CLAY({ .backgroundColor = Clay_Hovered() ? BLUE : RED });
|
||||||
bool Clay_Hovered(void);
|
bool Clay_Hovered(void);
|
||||||
|
// Bind a callback that will be called when the pointer position provided by Clay_SetPointerState is within the current element's bounding box.
|
||||||
|
// - onHoverFunction is a function pointer to a user defined function.
|
||||||
|
// - userData is a pointer that will be transparently passed through when the onHoverFunction is called.
|
||||||
void Clay_OnHover(void (*onHoverFunction)(Clay_ElementId elementId, Clay_PointerData pointerData, intptr_t userData), intptr_t userData);
|
void Clay_OnHover(void (*onHoverFunction)(Clay_ElementId elementId, Clay_PointerData pointerData, intptr_t userData), intptr_t userData);
|
||||||
|
// An imperative function that returns true if the pointer position provided by Clay_SetPointerState is within the element with the provided ID's bounding box.
|
||||||
|
// This ID can be calculated either with CLAY_ID() for string literal IDs, or Clay_GetElementId for dynamic strings.
|
||||||
bool Clay_PointerOver(Clay_ElementId elementId);
|
bool Clay_PointerOver(Clay_ElementId elementId);
|
||||||
|
// Returns data representing the state of the scrolling element with the provided ID.
|
||||||
|
// The returned Clay_ScrollContainerData contains a `found` bool that will be true if a scroll element was found with the provided ID.
|
||||||
|
// An imperative function that returns true if the pointer position provided by Clay_SetPointerState is within the element with the provided ID's bounding box.
|
||||||
|
// This ID can be calculated either with CLAY_ID() for string literal IDs, or Clay_GetElementId for dynamic strings.
|
||||||
Clay_ScrollContainerData Clay_GetScrollContainerData(Clay_ElementId id);
|
Clay_ScrollContainerData Clay_GetScrollContainerData(Clay_ElementId id);
|
||||||
Clay_TextElementConfig * Clay__StoreTextElementConfig(Clay_TextElementConfig config);
|
// Binds a callback function that Clay will call to determine the dimensions of a given string slice.
|
||||||
|
// - measureTextFunction is a user provided function that adheres to the interface Clay_Dimensions (Clay_StringSlice text, Clay_TextElementConfig *config, void *userData);
|
||||||
|
// - userData is a pointer that will be transparently passed through when the measureTextFunction is called.
|
||||||
void Clay_SetMeasureTextFunction(Clay_Dimensions (*measureTextFunction)(Clay_StringSlice text, Clay_TextElementConfig *config, void *userData), void *userData);
|
void Clay_SetMeasureTextFunction(Clay_Dimensions (*measureTextFunction)(Clay_StringSlice text, Clay_TextElementConfig *config, void *userData), void *userData);
|
||||||
|
// Experimental - Used in cases where Clay needs to integrate with a system that manages its own scrolling containers externally.
|
||||||
|
// Please reach out if you plan to use this function, as it may be subject to change.
|
||||||
void Clay_SetQueryScrollOffsetFunction(Clay_Vector2 (*queryScrollOffsetFunction)(uint32_t elementId, void *userData), void *userData);
|
void Clay_SetQueryScrollOffsetFunction(Clay_Vector2 (*queryScrollOffsetFunction)(uint32_t elementId, void *userData), void *userData);
|
||||||
|
// A bounds-checked "get" function for the Clay_RenderCommandArray returned from Clay_EndLayout().
|
||||||
Clay_RenderCommand * Clay_RenderCommandArray_Get(Clay_RenderCommandArray* array, int32_t index);
|
Clay_RenderCommand * Clay_RenderCommandArray_Get(Clay_RenderCommandArray* array, int32_t index);
|
||||||
|
// Enables and disables Clay's internal debug tools.
|
||||||
|
// This state is retained and does not need to be set each frame.
|
||||||
void Clay_SetDebugModeEnabled(bool enabled);
|
void Clay_SetDebugModeEnabled(bool enabled);
|
||||||
|
// Returns true if Clay's internal debug tools are currently enabled.
|
||||||
bool Clay_IsDebugModeEnabled(void);
|
bool Clay_IsDebugModeEnabled(void);
|
||||||
|
// Enables and disables visibility culling. By default, Clay will not generate render commands for elements whose bounding box is entirely outside the screen.
|
||||||
void Clay_SetCullingEnabled(bool enabled);
|
void Clay_SetCullingEnabled(bool enabled);
|
||||||
|
// Returns the maximum number of UI elements supported by Clay's current configuration.
|
||||||
int32_t Clay_GetMaxElementCount(void);
|
int32_t Clay_GetMaxElementCount(void);
|
||||||
|
// Modifies the maximum number of UI elements supported by Clay's current configuration.
|
||||||
|
// This may require reallocating additional memory, and re-calling Clay_Initialize();
|
||||||
void Clay_SetMaxElementCount(int32_t maxElementCount);
|
void Clay_SetMaxElementCount(int32_t maxElementCount);
|
||||||
|
// Returns the maximum number of measured "words" (whitespace seperated runs of characters) that Clay can store in its internal text measurement cache.
|
||||||
int32_t Clay_GetMaxMeasureTextCacheWordCount(void);
|
int32_t Clay_GetMaxMeasureTextCacheWordCount(void);
|
||||||
|
// Modifies the maximum number of measured "words" (whitespace seperated runs of characters) that Clay can store in its internal text measurement cache.
|
||||||
|
// This may require reallocating additional memory, and re-calling Clay_Initialize();
|
||||||
void Clay_SetMaxMeasureTextCacheWordCount(int32_t maxMeasureTextCacheWordCount);
|
void Clay_SetMaxMeasureTextCacheWordCount(int32_t maxMeasureTextCacheWordCount);
|
||||||
|
// Resets Clay's internal text measurement cache, useful if memory to represent strings is being re-used.
|
||||||
|
// Similar behaviour can be achieved on an individual text element level by using Clay_TextElementConfig.hashStringContents
|
||||||
void Clay_ResetMeasureTextCache(void);
|
void Clay_ResetMeasureTextCache(void);
|
||||||
|
|
||||||
// Internal API functions required by macros
|
// Internal API functions required by macros ----------------------
|
||||||
|
|
||||||
void Clay__OpenElement(void);
|
void Clay__OpenElement(void);
|
||||||
void Clay__ConfigureOpenElement(const Clay_ElementDeclaration config);
|
void Clay__ConfigureOpenElement(const Clay_ElementDeclaration config);
|
||||||
void Clay__CloseElement(void);
|
void Clay__CloseElement(void);
|
||||||
Clay_LayoutConfig * Clay__StoreLayoutConfig(Clay_LayoutConfig config);
|
|
||||||
Clay_ElementId Clay__AttachId(Clay_ElementId id);
|
|
||||||
Clay_ElementId Clay__HashString(Clay_String key, uint32_t offset, uint32_t seed);
|
Clay_ElementId Clay__HashString(Clay_String key, uint32_t offset, uint32_t seed);
|
||||||
void Clay__OpenTextElement(Clay_String text, Clay_TextElementConfig *textConfig);
|
void Clay__OpenTextElement(Clay_String text, Clay_TextElementConfig *textConfig);
|
||||||
|
Clay_TextElementConfig *Clay__StoreTextElementConfig(Clay_TextElementConfig config);
|
||||||
uint32_t Clay__GetParentElementId(void);
|
uint32_t Clay__GetParentElementId(void);
|
||||||
|
|
||||||
extern Clay_Color Clay__debugViewHighlightColor;
|
extern Clay_Color Clay__debugViewHighlightColor;
|
||||||
@ -616,6 +880,7 @@ Clay_Color Clay__Color_DEFAULT = CLAY__DEFAULT_STRUCT;
|
|||||||
Clay_CornerRadius Clay__CornerRadius_DEFAULT = CLAY__DEFAULT_STRUCT;
|
Clay_CornerRadius Clay__CornerRadius_DEFAULT = CLAY__DEFAULT_STRUCT;
|
||||||
Clay_BorderWidth Clay__BorderWidth_DEFAULT = CLAY__DEFAULT_STRUCT;
|
Clay_BorderWidth Clay__BorderWidth_DEFAULT = CLAY__DEFAULT_STRUCT;
|
||||||
|
|
||||||
|
// The below functions define array bounds checking and convenience functions for a provided type.
|
||||||
#define CLAY__ARRAY_DEFINE_FUNCTIONS(typeName, arrayName) \
|
#define CLAY__ARRAY_DEFINE_FUNCTIONS(typeName, arrayName) \
|
||||||
\
|
\
|
||||||
typedef struct \
|
typedef struct \
|
||||||
@ -627,7 +892,8 @@ typedef struct \
|
|||||||
typeName typeName##_DEFAULT = CLAY__DEFAULT_STRUCT; \
|
typeName typeName##_DEFAULT = CLAY__DEFAULT_STRUCT; \
|
||||||
\
|
\
|
||||||
arrayName arrayName##_Allocate_Arena(int32_t capacity, Clay_Arena *arena) { \
|
arrayName arrayName##_Allocate_Arena(int32_t capacity, Clay_Arena *arena) { \
|
||||||
return CLAY__INIT(arrayName){.capacity = capacity, .length = 0, .internalArray = (typeName *)Clay__Array_Allocate_Arena(capacity, sizeof(typeName), arena)}; \
|
return CLAY__INIT(arrayName){.capacity = capacity, .length = 0, \
|
||||||
|
.internalArray = (typeName *)Clay__Array_Allocate_Arena(capacity, sizeof(typeName), arena)}; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
typeName *arrayName##_Get(arrayName *array, int32_t index) { \
|
typeName *arrayName##_Get(arrayName *array, int32_t index) { \
|
||||||
@ -708,6 +974,14 @@ typedef struct {
|
|||||||
Clay__Warning *internalArray;
|
Clay__Warning *internalArray;
|
||||||
} Clay__WarningArray;
|
} Clay__WarningArray;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Clay_Color backgroundColor;
|
||||||
|
Clay_CornerRadius cornerRadius;
|
||||||
|
void* userData;
|
||||||
|
} Clay_SharedElementConfig;
|
||||||
|
|
||||||
|
CLAY__WRAPPER_STRUCT(Clay_SharedElementConfig);
|
||||||
|
|
||||||
Clay__WarningArray Clay__WarningArray_Allocate_Arena(int32_t capacity, Clay_Arena *arena);
|
Clay__WarningArray Clay__WarningArray_Allocate_Arena(int32_t capacity, Clay_Arena *arena);
|
||||||
Clay__Warning *Clay__WarningArray_Add(Clay__WarningArray *array, Clay__Warning item);
|
Clay__Warning *Clay__WarningArray_Add(Clay__WarningArray *array, Clay__Warning item);
|
||||||
void* Clay__Array_Allocate_Arena(int32_t capacity, uint32_t itemSize, Clay_Arena *arena);
|
void* Clay__Array_Allocate_Arena(int32_t capacity, uint32_t itemSize, Clay_Arena *arena);
|
||||||
@ -729,6 +1003,17 @@ CLAY__ARRAY_DEFINE(Clay_String, Clay__StringArray)
|
|||||||
CLAY__ARRAY_DEFINE(Clay_SharedElementConfig, Clay__SharedElementConfigArray)
|
CLAY__ARRAY_DEFINE(Clay_SharedElementConfig, Clay__SharedElementConfigArray)
|
||||||
CLAY__ARRAY_DEFINE_FUNCTIONS(Clay_RenderCommand, Clay_RenderCommandArray)
|
CLAY__ARRAY_DEFINE_FUNCTIONS(Clay_RenderCommand, Clay_RenderCommandArray)
|
||||||
|
|
||||||
|
typedef CLAY_PACKED_ENUM {
|
||||||
|
CLAY__ELEMENT_CONFIG_TYPE_NONE,
|
||||||
|
CLAY__ELEMENT_CONFIG_TYPE_BORDER,
|
||||||
|
CLAY__ELEMENT_CONFIG_TYPE_FLOATING,
|
||||||
|
CLAY__ELEMENT_CONFIG_TYPE_SCROLL,
|
||||||
|
CLAY__ELEMENT_CONFIG_TYPE_IMAGE,
|
||||||
|
CLAY__ELEMENT_CONFIG_TYPE_TEXT,
|
||||||
|
CLAY__ELEMENT_CONFIG_TYPE_CUSTOM,
|
||||||
|
CLAY__ELEMENT_CONFIG_TYPE_SHARED,
|
||||||
|
} Clay__ElementConfigType;
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
Clay_TextElementConfig *textElementConfig;
|
Clay_TextElementConfig *textElementConfig;
|
||||||
Clay_ImageElementConfig *imageElementConfig;
|
Clay_ImageElementConfig *imageElementConfig;
|
||||||
@ -1511,6 +1796,19 @@ void Clay__OpenTextElement(Clay_String text, Clay_TextElementConfig *textConfig)
|
|||||||
parentElement->childrenOrTextContent.children.length++;
|
parentElement->childrenOrTextContent.children.length++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Clay_ElementId Clay__AttachId(Clay_ElementId elementId) {
|
||||||
|
Clay_Context* context = Clay_GetCurrentContext();
|
||||||
|
if (context->booleanWarnings.maxElementsExceeded) {
|
||||||
|
return Clay_ElementId_DEFAULT;
|
||||||
|
}
|
||||||
|
Clay_LayoutElement *openLayoutElement = Clay__GetOpenLayoutElement();
|
||||||
|
uint32_t idAlias = openLayoutElement->id;
|
||||||
|
openLayoutElement->id = elementId.id;
|
||||||
|
Clay__AddHashMapItem(elementId, openLayoutElement, idAlias);
|
||||||
|
Clay__StringArray_Add(&context->layoutElementIdStrings, elementId.stringId);
|
||||||
|
return elementId;
|
||||||
|
}
|
||||||
|
|
||||||
void Clay__ConfigureOpenElement(const Clay_ElementDeclaration declaration) {
|
void Clay__ConfigureOpenElement(const Clay_ElementDeclaration declaration) {
|
||||||
Clay_Context* context = Clay_GetCurrentContext();
|
Clay_Context* context = Clay_GetCurrentContext();
|
||||||
Clay_LayoutElement *openLayoutElement = Clay__GetOpenLayoutElement();
|
Clay_LayoutElement *openLayoutElement = Clay__GetOpenLayoutElement();
|
||||||
@ -2549,19 +2847,6 @@ void Clay__CalculateFinalLayout(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Clay_ElementId Clay__AttachId(Clay_ElementId elementId) {
|
|
||||||
Clay_Context* context = Clay_GetCurrentContext();
|
|
||||||
if (context->booleanWarnings.maxElementsExceeded) {
|
|
||||||
return Clay_ElementId_DEFAULT;
|
|
||||||
}
|
|
||||||
Clay_LayoutElement *openLayoutElement = Clay__GetOpenLayoutElement();
|
|
||||||
uint32_t idAlias = openLayoutElement->id;
|
|
||||||
openLayoutElement->id = elementId.id;
|
|
||||||
Clay__AddHashMapItem(elementId, openLayoutElement, idAlias);
|
|
||||||
Clay__StringArray_Add(&context->layoutElementIdStrings, elementId.stringId);
|
|
||||||
return elementId;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma region DebugTools
|
#pragma region DebugTools
|
||||||
Clay_Color CLAY__DEBUGVIEW_COLOR_1 = {58, 56, 52, 255};
|
Clay_Color CLAY__DEBUGVIEW_COLOR_1 = {58, 56, 52, 255};
|
||||||
Clay_Color CLAY__DEBUGVIEW_COLOR_2 = {62, 60, 58, 255};
|
Clay_Color CLAY__DEBUGVIEW_COLOR_2 = {62, 60, 58, 255};
|
||||||
@ -3259,10 +3544,10 @@ uint32_t Clay_MinMemorySize(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CLAY_WASM_EXPORT("Clay_CreateArenaWithCapacityAndMemory")
|
CLAY_WASM_EXPORT("Clay_CreateArenaWithCapacityAndMemory")
|
||||||
Clay_Arena Clay_CreateArenaWithCapacityAndMemory(uint32_t capacity, void *offset) {
|
Clay_Arena Clay_CreateArenaWithCapacityAndMemory(uint32_t capacity, void *memory) {
|
||||||
Clay_Arena arena = {
|
Clay_Arena arena = {
|
||||||
.capacity = capacity,
|
.capacity = capacity,
|
||||||
.memory = (char *)offset
|
.memory = (char *)memory
|
||||||
};
|
};
|
||||||
return arena;
|
return arena;
|
||||||
}
|
}
|
||||||
|
@ -34,11 +34,24 @@ message(STATUS "Using SDL_ttf via FetchContent")
|
|||||||
FetchContent_MakeAvailable(SDL_ttf)
|
FetchContent_MakeAvailable(SDL_ttf)
|
||||||
set_property(DIRECTORY "${sdl_ttf_SOURCE_DIR}" PROPERTY EXCLUDE_FROM_ALL TRUE)
|
set_property(DIRECTORY "${sdl_ttf_SOURCE_DIR}" PROPERTY EXCLUDE_FROM_ALL TRUE)
|
||||||
|
|
||||||
|
# Download SDL_image
|
||||||
|
FetchContent_Declare(
|
||||||
|
SDL_image
|
||||||
|
GIT_REPOSITORY "https://github.com/libsdl-org/SDL_image.git"
|
||||||
|
GIT_TAG main # Slightly risky to use main branch, but it's the only one available
|
||||||
|
GIT_SHALLOW TRUE
|
||||||
|
GIT_PROGRESS TRUE
|
||||||
|
)
|
||||||
|
message(STATUS "Using SDL_image via FetchContent")
|
||||||
|
FetchContent_MakeAvailable(SDL_image)
|
||||||
|
set_property(DIRECTORY "${SDL_image_SOURCE_DIR}" PROPERTY EXCLUDE_FROM_ALL TRUE)
|
||||||
|
|
||||||
# Example executable
|
# Example executable
|
||||||
add_executable(${PROJECT_NAME} main.c)
|
add_executable(${PROJECT_NAME} main.c)
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||||
SDL3::SDL3
|
SDL3::SDL3
|
||||||
SDL3_ttf::SDL3_ttf
|
SDL3_ttf::SDL3_ttf
|
||||||
|
SDL3_image::SDL3_image
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
|
@ -23,6 +23,8 @@ typedef struct app_state {
|
|||||||
ClayVideoDemo_Data demoData;
|
ClayVideoDemo_Data demoData;
|
||||||
} AppState;
|
} AppState;
|
||||||
|
|
||||||
|
SDL_Surface *sample_image;
|
||||||
|
|
||||||
static inline Clay_Dimensions SDL_MeasureText(Clay_StringSlice text, Clay_TextElementConfig *config, void *userData)
|
static inline Clay_Dimensions SDL_MeasureText(Clay_StringSlice text, Clay_TextElementConfig *config, void *userData)
|
||||||
{
|
{
|
||||||
TTF_Font *font = gFonts[config->fontId];
|
TTF_Font *font = gFonts[config->fontId];
|
||||||
@ -68,6 +70,8 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
|||||||
|
|
||||||
gFonts[FONT_ID] = font;
|
gFonts[FONT_ID] = font;
|
||||||
|
|
||||||
|
sample_image = IMG_Load("resources/sample.png");
|
||||||
|
|
||||||
/* Initialize Clay */
|
/* Initialize Clay */
|
||||||
uint64_t totalMemorySize = Clay_MinMemorySize();
|
uint64_t totalMemorySize = Clay_MinMemorySize();
|
||||||
Clay_Arena clayMemory = (Clay_Arena) {
|
Clay_Arena clayMemory = (Clay_Arena) {
|
||||||
|
BIN
examples/SDL3-simple-demo/resources/sample.png
Normal file
BIN
examples/SDL3-simple-demo/resources/sample.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 850 B |
Binary file not shown.
@ -1,4 +0,0 @@
|
|||||||
Please note, the SDL3 renderer is not 100% feature complete. It is currently missing:
|
|
||||||
|
|
||||||
- Images
|
|
||||||
- Scroll / Scissor handling
|
|
@ -2,6 +2,7 @@
|
|||||||
#include <SDL3/SDL_main.h>
|
#include <SDL3/SDL_main.h>
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <SDL3_ttf/SDL_ttf.h>
|
#include <SDL3_ttf/SDL_ttf.h>
|
||||||
|
#include <SDL3_image/SDL_image.h>
|
||||||
|
|
||||||
/* This needs to be global because the "MeasureText" callback doesn't have a
|
/* This needs to be global because the "MeasureText" callback doesn't have a
|
||||||
* user data parameter */
|
* user data parameter */
|
||||||
@ -137,6 +138,8 @@ static void SDL_RenderArc(SDL_Renderer *renderer, const SDL_FPoint center, const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_Rect currentClippingRectangle;
|
||||||
|
|
||||||
static void SDL_RenderClayCommands(SDL_Renderer *renderer, Clay_RenderCommandArray *rcommands)
|
static void SDL_RenderClayCommands(SDL_Renderer *renderer, Clay_RenderCommandArray *rcommands)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < rcommands->length; i++) {
|
for (size_t i = 0; i < rcommands->length; i++) {
|
||||||
@ -232,6 +235,29 @@ static void SDL_RenderClayCommands(SDL_Renderer *renderer, Clay_RenderCommandArr
|
|||||||
}
|
}
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
|
case CLAY_RENDER_COMMAND_TYPE_SCISSOR_START: {
|
||||||
|
Clay_BoundingBox boundingBox = rcmd->boundingBox;
|
||||||
|
currentClippingRectangle = (SDL_Rect) {
|
||||||
|
.x = boundingBox.x,
|
||||||
|
.y = boundingBox.y,
|
||||||
|
.w = boundingBox.width,
|
||||||
|
.h = boundingBox.height,
|
||||||
|
};
|
||||||
|
SDL_SetRenderClipRect(renderer, ¤tClippingRectangle);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CLAY_RENDER_COMMAND_TYPE_SCISSOR_END: {
|
||||||
|
SDL_SetRenderClipRect(renderer, NULL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CLAY_RENDER_COMMAND_TYPE_IMAGE: {
|
||||||
|
Clay_ImageRenderData *config = &rcmd->renderData.image;
|
||||||
|
const SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, config->imageData);
|
||||||
|
const SDL_FRect dest = { rect.x, rect.y, rect.w, rect.h };
|
||||||
|
|
||||||
|
SDL_RenderTexture(renderer, texture, NULL, &dest);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
SDL_Log("Unknown render command type: %d", rcmd->commandType);
|
SDL_Log("Unknown render command type: %d", rcmd->commandType);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user