update clay and update abi to new clay version
This commit is contained in:
parent
254c01a11d
commit
89d89985dd
3 changed files with 451 additions and 371 deletions
|
@ -1,64 +1,52 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
// VERSION: 0.10
|
// VERSION: 0.11
|
||||||
|
|
||||||
#ifndef CLAY_IMPLEMENTATION
|
/*
|
||||||
#define CLAY_IMPLEMENTATION
|
NOTE: In order to use this library you must define
|
||||||
|
the following macro in exactly one file, _before_ including clay.h:
|
||||||
|
|
||||||
#ifdef CLAY_WASM
|
#define CLAY_IMPLEMENTATION
|
||||||
#define CLAY_WASM_EXPORT(name) __attribute__((export_name(name)))
|
#include "clay.h"
|
||||||
#else
|
|
||||||
#define CLAY_WASM_EXPORT(null)
|
See the examples folder for details.
|
||||||
#endif
|
*/
|
||||||
|
|
||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include "stdbool.h"
|
#include "stdbool.h"
|
||||||
#include "stddef.h"
|
#include "stddef.h"
|
||||||
#ifdef CLAY_OVERFLOW_TRAP
|
|
||||||
#include "signal.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CLAY_MAX_ELEMENT_COUNT
|
// -----------------------------------------
|
||||||
#define CLAY_MAX_ELEMENT_COUNT 8192
|
// HEADER DECLARATIONS ---------------------
|
||||||
#endif
|
// -----------------------------------------
|
||||||
|
|
||||||
#ifndef CLAY__NULL
|
#ifndef CLAY_HEADER
|
||||||
#define CLAY__NULL 0
|
#define CLAY_HEADER
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CLAY__MAXFLOAT
|
// Public Macro API ------------------------
|
||||||
#define CLAY__MAXFLOAT 3.40282346638528859812e+38F
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define CLAY__MAX(x, y) (((x) > (y)) ? (x) : (y))
|
#define CLAY_LAYOUT(...) Clay__StoreLayoutConfig((Clay_LayoutConfig) {__VA_ARGS__ })
|
||||||
#define CLAY__MIN(x, y) (((x) < (y)) ? (x) : (y))
|
|
||||||
|
|
||||||
#define CLAY__ALIGNMENT(type) (offsetof(struct { char c; type x; }, x))
|
#define CLAY_RECTANGLE_CONFIG(...) Clay__StoreRectangleElementConfig((Clay_RectangleElementConfig) {__VA_ARGS__ })
|
||||||
|
|
||||||
// Publicly visible config macros -----------------------------------------------------
|
#define CLAY_TEXT_CONFIG(...) Clay__StoreTextElementConfig((Clay_TextElementConfig) {__VA_ARGS__ })
|
||||||
|
|
||||||
#define CLAY_LAYOUT(...) Clay__LayoutConfigArray_Add(&Clay__layoutConfigs, (Clay_LayoutConfig) {__VA_ARGS__ })
|
#define CLAY_IMAGE_CONFIG(...) Clay__StoreImageElementConfig((Clay_ImageElementConfig) {__VA_ARGS__ })
|
||||||
|
|
||||||
#define CLAY_RECTANGLE_CONFIG(...) Clay__RectangleElementConfigArray_Add(&Clay__rectangleElementConfigs, (Clay_RectangleElementConfig) {__VA_ARGS__ })
|
#define CLAY_FLOATING_CONFIG(...) Clay__StoreFloatingElementConfig((Clay_FloatingElementConfig) {__VA_ARGS__ })
|
||||||
|
|
||||||
#define CLAY_TEXT_CONFIG(...) Clay__TextElementConfigArray_Add(&Clay__textElementConfigs, (Clay_TextElementConfig) {__VA_ARGS__ })
|
#define CLAY_CUSTOM_ELEMENT_CONFIG(...) Clay__StoreCustomElementConfig((Clay_CustomElementConfig) {__VA_ARGS__ })
|
||||||
|
|
||||||
#define CLAY_IMAGE_CONFIG(...) Clay__ImageElementConfigArray_Add(&Clay__imageElementConfigs, (Clay_ImageElementConfig) {__VA_ARGS__ })
|
#define CLAY_SCROLL_CONFIG(...) Clay__StoreScrollElementConfig((Clay_ScrollElementConfig) {__VA_ARGS__ })
|
||||||
|
|
||||||
#define CLAY_FLOATING_CONFIG(...) Clay__FloatingElementConfigArray_Add(&Clay__floatingElementConfigs, (Clay_FloatingElementConfig) {__VA_ARGS__ })
|
#define CLAY_BORDER_CONFIG(...) Clay__StoreBorderElementConfig((Clay_BorderElementConfig) { __VA_ARGS__ })
|
||||||
|
|
||||||
#define CLAY_CUSTOM_ELEMENT_CONFIG(...) Clay__CustomElementConfigArray_Add(&Clay__customElementConfigs, (Clay_CustomElementConfig) {__VA_ARGS__ })
|
#define CLAY_BORDER_CONFIG_OUTSIDE(...) Clay__StoreBorderElementConfig((Clay_BorderElementConfig) { .left = { __VA_ARGS__ }, .right = { __VA_ARGS__ }, .top = { __VA_ARGS__ }, .bottom = { __VA_ARGS__ } })
|
||||||
|
|
||||||
#define CLAY_SCROLL_CONFIG(...) Clay__ScrollElementConfigArray_Add(&Clay__scrollElementConfigs, (Clay_ScrollElementConfig) {__VA_ARGS__ })
|
#define CLAY_BORDER_CONFIG_OUTSIDE_RADIUS(width, color, radius) Clay__StoreBorderElementConfig((Clay_BorderElementConfig) { .left = { width, color }, .right = { width, color }, .top = { width, color }, .bottom = { width, color }, .cornerRadius = { radius, radius, radius, radius } })
|
||||||
|
|
||||||
#define CLAY_BORDER_CONFIG(...) Clay__BorderElementConfigArray_Add(&Clay__borderElementConfigs, (Clay_BorderElementConfig ) { __VA_ARGS__ })
|
#define CLAY_BORDER_CONFIG_ALL(...) Clay__StoreBorderElementConfig((Clay_BorderElementConfig) { .left = { __VA_ARGS__ }, .right = { __VA_ARGS__ }, .top = { __VA_ARGS__ }, .bottom = { __VA_ARGS__ }, .betweenChildren = { __VA_ARGS__ } })
|
||||||
|
|
||||||
#define CLAY_BORDER_CONFIG_OUTSIDE(...) Clay__BorderElementConfigArray_Add(&Clay__borderElementConfigs, (Clay_BorderElementConfig ) { .left = { __VA_ARGS__ }, .right = { __VA_ARGS__ }, .top = { __VA_ARGS__ }, .bottom = { __VA_ARGS__ } })
|
#define CLAY_BORDER_CONFIG_ALL_RADIUS(width, color, radius) Clay__StoreBorderElementConfig((Clay_BorderElementConfig) { .left = { __VA_ARGS__ }, .right = { __VA_ARGS__ }, .top = { __VA_ARGS__ }, .bottom = { __VA_ARGS__ }, .betweenChildren = { __VA_ARGS__ }, .cornerRadius = { radius, radius, radius, radius }})
|
||||||
|
|
||||||
#define CLAY_BORDER_CONFIG_OUTSIDE_RADIUS(width, color, radius) Clay__BorderElementConfigArray_Add(&Clay__borderElementConfigs, (Clay_BorderElementConfig ) { .left = { width, color }, .right = { width, color }, .top = { width, color }, .bottom = { width, color }, .cornerRadius = { radius, radius, radius, radius } })
|
|
||||||
|
|
||||||
#define CLAY_BORDER_CONFIG_ALL(...) Clay__BorderElementConfigArray_Add(&Clay__borderElementConfigs, (Clay_BorderElementConfig ) { .left = { __VA_ARGS__ }, .right = { __VA_ARGS__ }, .top = { __VA_ARGS__ }, .bottom = { __VA_ARGS__ }, .betweenChildren = { __VA_ARGS__ } })
|
|
||||||
|
|
||||||
#define CLAY_BORDER_CONFIG_ALL_RADIUS(width, color, radius) Clay__BorderElementConfigArray_Add(&Clay__borderElementConfigs, (Clay_BorderElementConfig ) { .left = { __VA_ARGS__ }, .right = { __VA_ARGS__ }, .top = { __VA_ARGS__ }, .bottom = { __VA_ARGS__ }, .betweenChildren = { __VA_ARGS__ }, .cornerRadius = { radius, radius, radius, radius }})
|
|
||||||
|
|
||||||
#define CLAY_CORNER_RADIUS(radius) (Clay_CornerRadius) { radius, radius, radius, radius }
|
#define CLAY_CORNER_RADIUS(radius) (Clay_CornerRadius) { radius, radius, radius, radius }
|
||||||
|
|
||||||
|
@ -68,7 +56,7 @@
|
||||||
|
|
||||||
#define CLAY_SIZING_FIXED(fixedSize) (Clay_SizingAxis) { .type = CLAY__SIZING_TYPE_GROW, .sizeMinMax = { fixedSize, fixedSize } }
|
#define CLAY_SIZING_FIXED(fixedSize) (Clay_SizingAxis) { .type = CLAY__SIZING_TYPE_GROW, .sizeMinMax = { fixedSize, fixedSize } }
|
||||||
|
|
||||||
#define CLAY_SIZING_PERCENT(percentOfParent) (Clay_SizingAxis) { .type = CLAY__SIZING_TYPE_PERCENT, .sizePercent = percentOfParent }
|
#define CLAY_SIZING_PERCENT(percentOfParent) (Clay_SizingAxis) { .type = CLAY__SIZING_TYPE_PERCENT, .sizePercent = (percentOfParent) }
|
||||||
|
|
||||||
#define CLAY_ID(label) Clay__HashString(CLAY_STRING(label), 0)
|
#define CLAY_ID(label) Clay__HashString(CLAY_STRING(label), 0)
|
||||||
|
|
||||||
|
@ -76,9 +64,9 @@
|
||||||
|
|
||||||
#define CLAY_ID_AUTO (Clay_ElementId) { .stringId = CLAY_STRING("Auto Generated ID"), .id = Clay__RehashWithNumber(Clay__dynamicElementIndexBaseHash.id, Clay__dynamicElementIndex++) }
|
#define CLAY_ID_AUTO (Clay_ElementId) { .stringId = CLAY_STRING("Auto Generated ID"), .id = Clay__RehashWithNumber(Clay__dynamicElementIndexBaseHash.id, Clay__dynamicElementIndex++) }
|
||||||
|
|
||||||
#define CLAY__STRING_LENGTH(s) ((sizeof(s) / sizeof(s[0])) - sizeof(s[0]))
|
#define CLAY__STRING_LENGTH(s) ((sizeof(s) / sizeof((s)[0])) - sizeof((s)[0]))
|
||||||
|
|
||||||
#define CLAY_STRING(string) (Clay_String) { .length = CLAY__STRING_LENGTH(string), .chars = string }
|
#define CLAY_STRING(string) (Clay_String) { .length = CLAY__STRING_LENGTH(string), .chars = (string) }
|
||||||
|
|
||||||
// Publicly visible layout element macros -----------------------------------------------------
|
// Publicly visible layout element macros -----------------------------------------------------
|
||||||
#define CLAY_CONTAINER(id, layoutConfig, children) \
|
#define CLAY_CONTAINER(id, layoutConfig, children) \
|
||||||
|
@ -118,8 +106,11 @@
|
||||||
children \
|
children \
|
||||||
Clay__CloseElementWithChildren()
|
Clay__CloseElementWithChildren()
|
||||||
|
|
||||||
bool Clay__warningsEnabled = true;
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
@ -127,9 +118,6 @@ typedef struct {
|
||||||
const char *chars;
|
const char *chars;
|
||||||
} Clay_String;
|
} Clay_String;
|
||||||
|
|
||||||
Clay_String CLAY__SPACECHAR = (Clay_String) { .length = 1, .chars = " " };
|
|
||||||
Clay_String CLAY__STRING_DEFAULT = (Clay_String) { .length = 0, .chars = "" };
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Clay_String label;
|
Clay_String label;
|
||||||
uint64_t nextAllocation;
|
uint64_t nextAllocation;
|
||||||
|
@ -137,6 +125,334 @@ typedef struct {
|
||||||
char *memory;
|
char *memory;
|
||||||
} Clay_Arena;
|
} Clay_Arena;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
float width, height;
|
||||||
|
} Clay_Dimensions;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
float x, y;
|
||||||
|
} Clay_Vector2;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
float r, g, b, a;
|
||||||
|
} Clay_Color;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
float x, y, width, height;
|
||||||
|
} Clay_BoundingBox;
|
||||||
|
|
||||||
|
// baseId + offset = id
|
||||||
|
typedef struct {
|
||||||
|
uint32_t id;
|
||||||
|
uint32_t offset;
|
||||||
|
uint32_t baseId;
|
||||||
|
Clay_String stringId;
|
||||||
|
} Clay_ElementId;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
float topLeft;
|
||||||
|
float topRight;
|
||||||
|
float bottomLeft;
|
||||||
|
float bottomRight;
|
||||||
|
} Clay_CornerRadius;
|
||||||
|
|
||||||
|
// Element Configs ---------------------------
|
||||||
|
// Layout
|
||||||
|
typedef enum __attribute__((__packed__)) {
|
||||||
|
CLAY_LEFT_TO_RIGHT,
|
||||||
|
CLAY_TOP_TO_BOTTOM,
|
||||||
|
} Clay_LayoutDirection;
|
||||||
|
|
||||||
|
typedef enum __attribute__((__packed__)) {
|
||||||
|
CLAY_ALIGN_X_LEFT,
|
||||||
|
CLAY_ALIGN_X_RIGHT,
|
||||||
|
CLAY_ALIGN_X_CENTER,
|
||||||
|
} Clay_LayoutAlignmentX;
|
||||||
|
|
||||||
|
typedef enum __attribute__((__packed__)) {
|
||||||
|
CLAY_ALIGN_Y_TOP,
|
||||||
|
CLAY_ALIGN_Y_BOTTOM,
|
||||||
|
CLAY_ALIGN_Y_CENTER,
|
||||||
|
} Clay_LayoutAlignmentY;
|
||||||
|
|
||||||
|
typedef enum __attribute__((__packed__)) {
|
||||||
|
CLAY__SIZING_TYPE_FIT,
|
||||||
|
CLAY__SIZING_TYPE_GROW,
|
||||||
|
CLAY__SIZING_TYPE_PERCENT,
|
||||||
|
} Clay__SizingType;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Clay_LayoutAlignmentX x;
|
||||||
|
Clay_LayoutAlignmentY y;
|
||||||
|
} Clay_ChildAlignment;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
float min;
|
||||||
|
float max;
|
||||||
|
} Clay_SizingMinMax;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
union {
|
||||||
|
Clay_SizingMinMax sizeMinMax;
|
||||||
|
float sizePercent;
|
||||||
|
};
|
||||||
|
Clay__SizingType type;
|
||||||
|
} Clay_SizingAxis;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Clay_SizingAxis width;
|
||||||
|
Clay_SizingAxis height;
|
||||||
|
} Clay_Sizing;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t x;
|
||||||
|
uint16_t y;
|
||||||
|
} Clay_Padding;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Clay_Sizing sizing;
|
||||||
|
Clay_Padding padding;
|
||||||
|
uint16_t childGap;
|
||||||
|
Clay_LayoutDirection layoutDirection;
|
||||||
|
Clay_ChildAlignment childAlignment;
|
||||||
|
} Clay_LayoutConfig;
|
||||||
|
|
||||||
|
// Rectangle
|
||||||
|
typedef struct {
|
||||||
|
Clay_Color color;
|
||||||
|
Clay_CornerRadius cornerRadius;
|
||||||
|
#ifdef CLAY_EXTEND_CONFIG_RECTANGLE
|
||||||
|
CLAY_EXTEND_CONFIG_RECTANGLE
|
||||||
|
#endif
|
||||||
|
} Clay_RectangleElementConfig;
|
||||||
|
|
||||||
|
// Text
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
CLAY_TEXT_WRAP_WORDS,
|
||||||
|
CLAY_TEXT_WRAP_NEWLINES,
|
||||||
|
CLAY_TEXT_WRAP_NONE,
|
||||||
|
} Clay_TextElementConfigWrapMode;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
Clay_Color textColor;
|
||||||
|
uint16_t fontId;
|
||||||
|
uint16_t fontSize;
|
||||||
|
uint16_t letterSpacing;
|
||||||
|
uint16_t lineSpacing;
|
||||||
|
Clay_TextElementConfigWrapMode wrapMode;
|
||||||
|
#ifdef CLAY_EXTEND_CONFIG_TEXT
|
||||||
|
CLAY_EXTEND_CONFIG_TEXT
|
||||||
|
#endif
|
||||||
|
} Clay_TextElementConfig;
|
||||||
|
|
||||||
|
// Image
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
void * imageData;
|
||||||
|
Clay_Dimensions sourceDimensions;
|
||||||
|
#ifdef CLAY_EXTEND_CONFIG_IMAGE
|
||||||
|
CLAY_EXTEND_CONFIG_IMAGE
|
||||||
|
#endif
|
||||||
|
} Clay_ImageElementConfig;
|
||||||
|
|
||||||
|
// Floating
|
||||||
|
typedef enum __attribute__((__packed__)) {
|
||||||
|
CLAY_ATTACH_POINT_LEFT_TOP,
|
||||||
|
CLAY_ATTACH_POINT_LEFT_CENTER,
|
||||||
|
CLAY_ATTACH_POINT_LEFT_BOTTOM,
|
||||||
|
CLAY_ATTACH_POINT_CENTER_TOP,
|
||||||
|
CLAY_ATTACH_POINT_CENTER_CENTER,
|
||||||
|
CLAY_ATTACH_POINT_CENTER_BOTTOM,
|
||||||
|
CLAY_ATTACH_POINT_RIGHT_TOP,
|
||||||
|
CLAY_ATTACH_POINT_RIGHT_CENTER,
|
||||||
|
CLAY_ATTACH_POINT_RIGHT_BOTTOM,
|
||||||
|
} Clay_FloatingAttachPointType;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
Clay_FloatingAttachPointType element;
|
||||||
|
Clay_FloatingAttachPointType parent;
|
||||||
|
} Clay_FloatingAttachPoints;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
Clay_Vector2 offset;
|
||||||
|
Clay_Dimensions expand;
|
||||||
|
uint16_t zIndex;
|
||||||
|
uint32_t parentId;
|
||||||
|
Clay_FloatingAttachPoints attachment;
|
||||||
|
} Clay_FloatingElementConfig;
|
||||||
|
|
||||||
|
// Custom
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
#ifndef CLAY_EXTEND_CONFIG_CUSTOM
|
||||||
|
void* customData;
|
||||||
|
#else
|
||||||
|
CLAY_EXTEND_CONFIG_CUSTOM
|
||||||
|
#endif
|
||||||
|
} Clay_CustomElementConfig;
|
||||||
|
|
||||||
|
// Scroll
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
bool horizontal;
|
||||||
|
bool vertical;
|
||||||
|
} Clay_ScrollElementConfig;
|
||||||
|
|
||||||
|
// Border
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t width;
|
||||||
|
Clay_Color color;
|
||||||
|
} Clay_Border;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
Clay_Border left;
|
||||||
|
Clay_Border right;
|
||||||
|
Clay_Border top;
|
||||||
|
Clay_Border bottom;
|
||||||
|
Clay_Border betweenChildren;
|
||||||
|
Clay_CornerRadius cornerRadius;
|
||||||
|
} Clay_BorderElementConfig;
|
||||||
|
|
||||||
|
typedef union
|
||||||
|
{
|
||||||
|
Clay_RectangleElementConfig *rectangleElementConfig;
|
||||||
|
Clay_TextElementConfig *textElementConfig;
|
||||||
|
Clay_ImageElementConfig *imageElementConfig;
|
||||||
|
Clay_FloatingElementConfig *floatingElementConfig;
|
||||||
|
Clay_CustomElementConfig *customElementConfig;
|
||||||
|
Clay_ScrollElementConfig *scrollElementConfig;
|
||||||
|
Clay_BorderElementConfig *borderElementConfig;
|
||||||
|
} Clay_ElementConfigUnion;
|
||||||
|
|
||||||
|
// Miscellaneous Structs & Enums ---------------------------------
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
// 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;
|
||||||
|
Clay_Dimensions scrollContainerDimensions;
|
||||||
|
Clay_Dimensions contentDimensions;
|
||||||
|
Clay_ScrollElementConfig config;
|
||||||
|
// Indicates whether an actual scroll container matched the provided ID or if the default struct was returned.
|
||||||
|
bool found;
|
||||||
|
} Clay_ScrollContainerData;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CLAY_RENDER_COMMAND_TYPE_NONE,
|
||||||
|
CLAY_RENDER_COMMAND_TYPE_RECTANGLE,
|
||||||
|
CLAY_RENDER_COMMAND_TYPE_BORDER,
|
||||||
|
CLAY_RENDER_COMMAND_TYPE_TEXT,
|
||||||
|
CLAY_RENDER_COMMAND_TYPE_IMAGE,
|
||||||
|
CLAY_RENDER_COMMAND_TYPE_SCISSOR_START,
|
||||||
|
CLAY_RENDER_COMMAND_TYPE_SCISSOR_END,
|
||||||
|
CLAY_RENDER_COMMAND_TYPE_CUSTOM,
|
||||||
|
} Clay_RenderCommandType;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
Clay_BoundingBox boundingBox;
|
||||||
|
Clay_ElementConfigUnion config;
|
||||||
|
Clay_String text; // TODO I wish there was a way to avoid having to have this on every render command
|
||||||
|
uint32_t id;
|
||||||
|
Clay_RenderCommandType commandType;
|
||||||
|
} Clay_RenderCommand;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t capacity;
|
||||||
|
uint32_t length;
|
||||||
|
Clay_RenderCommand *internalArray;
|
||||||
|
} Clay_RenderCommandArray;
|
||||||
|
|
||||||
|
// Function Forward Declarations ---------------------------------
|
||||||
|
// Public API functions
|
||||||
|
uint32_t Clay_MinMemorySize();
|
||||||
|
Clay_Arena Clay_CreateArenaWithCapacityAndMemory(uint32_t capacity, void *offset);
|
||||||
|
void Clay_SetPointerState(Clay_Vector2 position, bool pointerDown);
|
||||||
|
void Clay_Initialize(Clay_Arena arena, Clay_Dimensions layoutDimensions);
|
||||||
|
void Clay_UpdateScrollContainers(bool isPointerActive, Clay_Vector2 scrollDelta, float deltaTime);
|
||||||
|
void Clay_SetLayoutDimensions(Clay_Dimensions dimensions);
|
||||||
|
void Clay_BeginLayout();
|
||||||
|
Clay_RenderCommandArray Clay_EndLayout();
|
||||||
|
bool Clay_PointerOver(Clay_ElementId id);
|
||||||
|
Clay_ScrollContainerData Clay_GetScrollContainerData(Clay_ElementId id);
|
||||||
|
void Clay_SetMeasureTextFunction(Clay_Dimensions (*measureTextFunction)(Clay_String *text, Clay_TextElementConfig *config));
|
||||||
|
Clay_RenderCommand * Clay_RenderCommandArray_Get(Clay_RenderCommandArray* array, int32_t index);
|
||||||
|
void Clay_SetDebugModeEnabled(bool enabled);
|
||||||
|
|
||||||
|
void Clay_OpenContainerElement(Clay_ElementId id, Clay_LayoutConfig *layoutConfig);
|
||||||
|
void Clay_OpenRectangleElement(Clay_ElementId id, Clay_LayoutConfig *layoutConfig, Clay_RectangleElementConfig *rectangleConfig);
|
||||||
|
void Clay_OpenTextElement(Clay_ElementId id, Clay_String *text, Clay_TextElementConfig *textConfig);
|
||||||
|
void Clay_OpenImageElement(Clay_ElementId id, Clay_LayoutConfig *layoutConfig, Clay_ImageElementConfig *imageConfig);
|
||||||
|
void Clay_OpenScrollElement(Clay_ElementId id, Clay_LayoutConfig *layoutConfig, Clay_ScrollElementConfig *imageConfig);
|
||||||
|
void Clay_OpenFloatingElement(Clay_ElementId id, Clay_LayoutConfig *layoutConfig, Clay_FloatingElementConfig *imageConfig);
|
||||||
|
void Clay_OpenBorderElement(Clay_ElementId id, Clay_LayoutConfig *layoutConfig, Clay_BorderElementConfig *imageConfig);
|
||||||
|
void Clay_OpenCustomElement(Clay_ElementId id, Clay_LayoutConfig *layoutConfig, Clay_CustomElementConfig *imageConfig);
|
||||||
|
void Clay_CloseElementWithChildren();
|
||||||
|
void Clay_CloseScrollElement();
|
||||||
|
void Clay_CloseFloatingElement();
|
||||||
|
|
||||||
|
// Internal API functions required by macros
|
||||||
|
Clay_LayoutConfig * Clay__StoreLayoutConfig(Clay_LayoutConfig config);
|
||||||
|
Clay_RectangleElementConfig * Clay__StoreRectangleElementConfig(Clay_RectangleElementConfig config);
|
||||||
|
Clay_TextElementConfig * Clay__StoreTextElementConfig(Clay_TextElementConfig config);
|
||||||
|
Clay_ImageElementConfig * Clay__StoreImageElementConfig(Clay_ImageElementConfig config);
|
||||||
|
Clay_FloatingElementConfig * Clay__StoreFloatingElementConfig(Clay_FloatingElementConfig config);
|
||||||
|
Clay_CustomElementConfig * Clay__StoreCustomElementConfig(Clay_CustomElementConfig config);
|
||||||
|
Clay_ScrollElementConfig * Clay__StoreScrollElementConfig(Clay_ScrollElementConfig config);
|
||||||
|
Clay_BorderElementConfig * Clay__StoreBorderElementConfig(Clay_BorderElementConfig config);
|
||||||
|
Clay_ElementId Clay_HashString(Clay_String toHash, uint32_t index);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// -----------------------------------------
|
||||||
|
// IMPLEMENTATION --------------------------
|
||||||
|
// -----------------------------------------
|
||||||
|
#ifdef CLAY_IMPLEMENTATION
|
||||||
|
#undef CLAY_IMPLEMENTATION
|
||||||
|
|
||||||
|
#ifdef CLAY_WASM
|
||||||
|
#define CLAY_WASM_EXPORT(name) __attribute__((export_name(name)))
|
||||||
|
#else
|
||||||
|
#define CLAY_WASM_EXPORT(null)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CLAY_OVERFLOW_TRAP
|
||||||
|
#include "signal.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CLAY_MAX_ELEMENT_COUNT
|
||||||
|
#define CLAY_MAX_ELEMENT_COUNT 8192
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CLAY__NULL
|
||||||
|
#define CLAY__NULL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CLAY__MAXFLOAT
|
||||||
|
#define CLAY__MAXFLOAT 3.40282346638528859812e+38F
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define CLAY__MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||||
|
#define CLAY__MIN(x, y) (((x) < (y)) ? (x) : (y))
|
||||||
|
|
||||||
|
#define CLAY__ALIGNMENT(type) (offsetof(struct { char c; type x; }, x))
|
||||||
|
|
||||||
|
bool Clay__warningsEnabled = true;
|
||||||
|
|
||||||
|
Clay_String CLAY__SPACECHAR = (Clay_String) { .length = 1, .chars = " " };
|
||||||
|
Clay_String CLAY__STRING_DEFAULT = (Clay_String) { .length = 0, .chars = "" };
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
Clay_String baseMessage;
|
Clay_String baseMessage;
|
||||||
|
@ -156,11 +472,11 @@ typedef struct
|
||||||
Clay__WarningArray Clay__WarningArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) {
|
Clay__WarningArray Clay__WarningArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) {
|
||||||
uint64_t totalSizeBytes = capacity * sizeof(Clay_String);
|
uint64_t totalSizeBytes = capacity * sizeof(Clay_String);
|
||||||
Clay__WarningArray array = (Clay__WarningArray){.capacity = capacity, .length = 0};
|
Clay__WarningArray array = (Clay__WarningArray){.capacity = capacity, .length = 0};
|
||||||
uint64_t nextAllocAddress = (uint64_t)((uint64_t)arena->nextAllocation + (uint64_t)arena->memory);
|
uint64_t nextAllocAddress = (uint64_t)arena->nextAllocation + (uint64_t)arena->memory;
|
||||||
uint64_t arenaOffsetAligned = nextAllocAddress + (CLAY__ALIGNMENT(Clay_String) - (nextAllocAddress % CLAY__ALIGNMENT(Clay_String)));
|
uint64_t arenaOffsetAligned = nextAllocAddress + (CLAY__ALIGNMENT(Clay_String) - (nextAllocAddress % CLAY__ALIGNMENT(Clay_String)));
|
||||||
arenaOffsetAligned -= (uint64_t)arena->memory;
|
arenaOffsetAligned -= (uint64_t)arena->memory;
|
||||||
if (arenaOffsetAligned + totalSizeBytes <= arena->capacity) {
|
if (arenaOffsetAligned + totalSizeBytes <= arena->capacity) {
|
||||||
array.internalArray = (Clay__Warning*)((uint64_t)arena->memory + arenaOffsetAligned);
|
array.internalArray = (Clay__Warning*)((uint64_t)arena->memory + (uint64_t)arenaOffsetAligned);
|
||||||
arena->nextAllocation = arenaOffsetAligned + totalSizeBytes;
|
arena->nextAllocation = arenaOffsetAligned + totalSizeBytes;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -190,12 +506,12 @@ Clay__Warning *Clay__WarningArray_Add(Clay__WarningArray *array, Clay__Warning i
|
||||||
void* Clay__Array_Allocate_Arena(uint32_t capacity, uint32_t itemSize, uint32_t alignment, Clay_Arena *arena)
|
void* Clay__Array_Allocate_Arena(uint32_t capacity, uint32_t itemSize, uint32_t alignment, Clay_Arena *arena)
|
||||||
{
|
{
|
||||||
uint64_t totalSizeBytes = capacity * itemSize;
|
uint64_t totalSizeBytes = capacity * itemSize;
|
||||||
uint64_t nextAllocAddress = (uint64_t)(arena->nextAllocation + (uint64_t)arena->memory);
|
uint64_t nextAllocAddress = (uint64_t)arena->nextAllocation + (uint64_t)arena->memory;
|
||||||
uint64_t arenaOffsetAligned = nextAllocAddress + (alignment - (nextAllocAddress % alignment));
|
uint64_t arenaOffsetAligned = nextAllocAddress + (alignment - (nextAllocAddress % alignment));
|
||||||
arenaOffsetAligned -= (uint64_t)arena->memory;
|
arenaOffsetAligned -= (uint64_t)arena->memory;
|
||||||
if (arenaOffsetAligned + totalSizeBytes <= arena->capacity) {
|
if (arenaOffsetAligned + totalSizeBytes <= arena->capacity) {
|
||||||
arena->nextAllocation = arenaOffsetAligned + totalSizeBytes;
|
arena->nextAllocation = arenaOffsetAligned + totalSizeBytes;
|
||||||
return (void*)((uint64_t)arena->memory + arenaOffsetAligned);
|
return (void*)((uint64_t)arena->memory + (uint64_t)arenaOffsetAligned);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (Clay__warningsEnabled) {
|
if (Clay__warningsEnabled) {
|
||||||
|
@ -253,14 +569,6 @@ Clay__BoolArray Clay__BoolArray_Allocate_Arena(uint32_t capacity, Clay_Arena *ar
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
// __GENERATED__ template
|
// __GENERATED__ template
|
||||||
|
|
||||||
// baseId + offset = id
|
|
||||||
typedef struct {
|
|
||||||
uint32_t id;
|
|
||||||
uint32_t offset;
|
|
||||||
uint32_t baseId;
|
|
||||||
Clay_String stringId;
|
|
||||||
} Clay_ElementId;
|
|
||||||
|
|
||||||
Clay_ElementId CLAY__ELEMENT_ID_DEFAULT = (Clay_ElementId) {};
|
Clay_ElementId CLAY__ELEMENT_ID_DEFAULT = (Clay_ElementId) {};
|
||||||
|
|
||||||
// __GENERATED__ template array_define,array_get,array_add TYPE=Clay_ElementId NAME=Clay__ElementIdArray DEFAULT_VALUE=&CLAY__ELEMENT_ID_DEFAULT
|
// __GENERATED__ template array_define,array_get,array_add TYPE=Clay_ElementId NAME=Clay__ElementIdArray DEFAULT_VALUE=&CLAY__ELEMENT_ID_DEFAULT
|
||||||
|
@ -288,56 +596,6 @@ Clay_ElementId *Clay__ElementIdArray_Add(Clay__ElementIdArray *array, Clay_Eleme
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
// __GENERATED__ template
|
// __GENERATED__ template
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
float r, g, b, a;
|
|
||||||
} Clay_Color;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
float x, y, width, height;
|
|
||||||
} Clay_BoundingBox;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
float width, height;
|
|
||||||
} Clay_Dimensions;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
float x, y;
|
|
||||||
} Clay_Vector2;
|
|
||||||
|
|
||||||
typedef enum __attribute__((__packed__)) {
|
|
||||||
CLAY_LEFT_TO_RIGHT,
|
|
||||||
CLAY_TOP_TO_BOTTOM,
|
|
||||||
} Clay_LayoutDirection;
|
|
||||||
|
|
||||||
typedef enum __attribute__((__packed__)) {
|
|
||||||
CLAY_ALIGN_X_LEFT,
|
|
||||||
CLAY_ALIGN_X_RIGHT,
|
|
||||||
CLAY_ALIGN_X_CENTER,
|
|
||||||
} Clay_LayoutAlignmentX;
|
|
||||||
|
|
||||||
typedef enum __attribute__((__packed__)) {
|
|
||||||
CLAY_ALIGN_Y_TOP,
|
|
||||||
CLAY_ALIGN_Y_BOTTOM,
|
|
||||||
CLAY_ALIGN_Y_CENTER,
|
|
||||||
} Clay_LayoutAlignmentY;
|
|
||||||
|
|
||||||
typedef enum __attribute__((__packed__)) {
|
|
||||||
CLAY__SIZING_TYPE_FIT,
|
|
||||||
CLAY__SIZING_TYPE_GROW,
|
|
||||||
CLAY__SIZING_TYPE_PERCENT,
|
|
||||||
} Clay__SizingType;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
CLAY_RENDER_COMMAND_TYPE_NONE,
|
|
||||||
CLAY_RENDER_COMMAND_TYPE_RECTANGLE,
|
|
||||||
CLAY_RENDER_COMMAND_TYPE_BORDER,
|
|
||||||
CLAY_RENDER_COMMAND_TYPE_TEXT,
|
|
||||||
CLAY_RENDER_COMMAND_TYPE_IMAGE,
|
|
||||||
CLAY_RENDER_COMMAND_TYPE_SCISSOR_START,
|
|
||||||
CLAY_RENDER_COMMAND_TYPE_SCISSOR_END,
|
|
||||||
CLAY_RENDER_COMMAND_TYPE_CUSTOM,
|
|
||||||
} Clay_RenderCommandType;
|
|
||||||
|
|
||||||
typedef enum __attribute__((__packed__)) {
|
typedef enum __attribute__((__packed__)) {
|
||||||
CLAY__LAYOUT_ELEMENT_TYPE_CONTAINER,
|
CLAY__LAYOUT_ELEMENT_TYPE_CONTAINER,
|
||||||
CLAY__LAYOUT_ELEMENT_TYPE_RECTANGLE,
|
CLAY__LAYOUT_ELEMENT_TYPE_RECTANGLE,
|
||||||
|
@ -360,67 +618,6 @@ Clay_RenderCommandType Clay__LayoutElementTypeToRenderCommandType[] = {
|
||||||
[CLAY__LAYOUT_ELEMENT_TYPE_CUSTOM] = CLAY_RENDER_COMMAND_TYPE_CUSTOM,
|
[CLAY__LAYOUT_ELEMENT_TYPE_CUSTOM] = CLAY_RENDER_COMMAND_TYPE_CUSTOM,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum __attribute__((__packed__)) {
|
|
||||||
CLAY_ATTACH_POINT_LEFT_TOP,
|
|
||||||
CLAY_ATTACH_POINT_LEFT_CENTER,
|
|
||||||
CLAY_ATTACH_POINT_LEFT_BOTTOM,
|
|
||||||
CLAY_ATTACH_POINT_CENTER_TOP,
|
|
||||||
CLAY_ATTACH_POINT_CENTER_CENTER,
|
|
||||||
CLAY_ATTACH_POINT_CENTER_BOTTOM,
|
|
||||||
CLAY_ATTACH_POINT_RIGHT_TOP,
|
|
||||||
CLAY_ATTACH_POINT_RIGHT_CENTER,
|
|
||||||
CLAY_ATTACH_POINT_RIGHT_BOTTOM,
|
|
||||||
} Clay_FloatingAttachPointType;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
Clay_FloatingAttachPointType element;
|
|
||||||
Clay_FloatingAttachPointType parent;
|
|
||||||
} Clay_FloatingAttachPoints;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Clay_LayoutAlignmentX x;
|
|
||||||
Clay_LayoutAlignmentY y;
|
|
||||||
} Clay_ChildAlignment;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
float min;
|
|
||||||
float max;
|
|
||||||
} Clay_SizingMinMax;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
union {
|
|
||||||
Clay_SizingMinMax sizeMinMax;
|
|
||||||
float sizePercent;
|
|
||||||
};
|
|
||||||
Clay__SizingType type;
|
|
||||||
} Clay_SizingAxis;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Clay_SizingAxis width;
|
|
||||||
Clay_SizingAxis height;
|
|
||||||
} Clay_Sizing;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint16_t x;
|
|
||||||
uint16_t y;
|
|
||||||
} Clay_Padding;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
float topLeft;
|
|
||||||
float topRight;
|
|
||||||
float bottomLeft;
|
|
||||||
float bottomRight;
|
|
||||||
} Clay_CornerRadius;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Clay_Sizing sizing;
|
|
||||||
Clay_Padding padding;
|
|
||||||
uint16_t childGap;
|
|
||||||
Clay_LayoutDirection layoutDirection;
|
|
||||||
Clay_ChildAlignment childAlignment;
|
|
||||||
} Clay_LayoutConfig;
|
|
||||||
|
|
||||||
Clay_LayoutConfig CLAY_LAYOUT_DEFAULT = (Clay_LayoutConfig){};
|
Clay_LayoutConfig CLAY_LAYOUT_DEFAULT = (Clay_LayoutConfig){};
|
||||||
|
|
||||||
// __GENERATED__ template array_define,array_add TYPE=Clay_LayoutConfig NAME=Clay__LayoutConfigArray DEFAULT_VALUE=&CLAY_LAYOUT_DEFAULT
|
// __GENERATED__ template array_define,array_add TYPE=Clay_LayoutConfig NAME=Clay__LayoutConfigArray DEFAULT_VALUE=&CLAY_LAYOUT_DEFAULT
|
||||||
|
@ -445,14 +642,6 @@ Clay_LayoutConfig *Clay__LayoutConfigArray_Add(Clay__LayoutConfigArray *array, C
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
// __GENERATED__ template
|
// __GENERATED__ template
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Clay_Color color;
|
|
||||||
Clay_CornerRadius cornerRadius;
|
|
||||||
#ifdef CLAY_EXTEND_CONFIG_RECTANGLE
|
|
||||||
CLAY_EXTEND_CONFIG_RECTANGLE
|
|
||||||
#endif
|
|
||||||
} Clay_RectangleElementConfig;
|
|
||||||
|
|
||||||
Clay_RectangleElementConfig CLAY__RECTANGLE_ELEMENT_CONFIG_DEFAULT = (Clay_RectangleElementConfig){0};
|
Clay_RectangleElementConfig CLAY__RECTANGLE_ELEMENT_CONFIG_DEFAULT = (Clay_RectangleElementConfig){0};
|
||||||
|
|
||||||
// __GENERATED__ template array_define,array_add TYPE=Clay_RectangleElementConfig NAME=Clay__RectangleElementConfigArray DEFAULT_VALUE=&CLAY__RECTANGLE_ELEMENT_CONFIG_DEFAULT
|
// __GENERATED__ template array_define,array_add TYPE=Clay_RectangleElementConfig NAME=Clay__RectangleElementConfigArray DEFAULT_VALUE=&CLAY__RECTANGLE_ELEMENT_CONFIG_DEFAULT
|
||||||
|
@ -477,26 +666,6 @@ Clay_RectangleElementConfig *Clay__RectangleElementConfigArray_Add(Clay__Rectang
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
// __GENERATED__ template
|
// __GENERATED__ template
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
CLAY_TEXT_WRAP_WORDS,
|
|
||||||
CLAY_TEXT_WRAP_NEWLINES,
|
|
||||||
CLAY_TEXT_WRAP_NONE,
|
|
||||||
} Clay_TextElementConfigWrapMode;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
Clay_Color textColor;
|
|
||||||
uint16_t fontId;
|
|
||||||
uint16_t fontSize;
|
|
||||||
uint16_t letterSpacing;
|
|
||||||
uint16_t lineSpacing;
|
|
||||||
Clay_TextElementConfigWrapMode wrapMode;
|
|
||||||
#ifdef CLAY_EXTEND_CONFIG_TEXT
|
|
||||||
CLAY_EXTEND_CONFIG_TEXT
|
|
||||||
#endif
|
|
||||||
} Clay_TextElementConfig;
|
|
||||||
|
|
||||||
Clay_TextElementConfig CLAY__TEXT_ELEMENT_CONFIG_DEFAULT = (Clay_TextElementConfig) {};
|
Clay_TextElementConfig CLAY__TEXT_ELEMENT_CONFIG_DEFAULT = (Clay_TextElementConfig) {};
|
||||||
|
|
||||||
// __GENERATED__ template array_define,array_add TYPE=Clay_TextElementConfig NAME=Clay__TextElementConfigArray DEFAULT_VALUE=&CLAY__TEXT_ELEMENT_CONFIG_DEFAULT
|
// __GENERATED__ template array_define,array_add TYPE=Clay_TextElementConfig NAME=Clay__TextElementConfigArray DEFAULT_VALUE=&CLAY__TEXT_ELEMENT_CONFIG_DEFAULT
|
||||||
|
@ -521,15 +690,6 @@ Clay_TextElementConfig *Clay__TextElementConfigArray_Add(Clay__TextElementConfig
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
// __GENERATED__ template
|
// __GENERATED__ template
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
void * imageData;
|
|
||||||
Clay_Dimensions sourceDimensions;
|
|
||||||
#ifdef CLAY_EXTEND_CONFIG_IMAGE
|
|
||||||
CLAY_EXTEND_CONFIG_IMAGE
|
|
||||||
#endif
|
|
||||||
} Clay_ImageElementConfig;
|
|
||||||
|
|
||||||
Clay_ImageElementConfig CLAY__IMAGE_ELEMENT_CONFIG_DEFAULT = (Clay_ImageElementConfig) {};
|
Clay_ImageElementConfig CLAY__IMAGE_ELEMENT_CONFIG_DEFAULT = (Clay_ImageElementConfig) {};
|
||||||
|
|
||||||
// __GENERATED__ template array_define,array_add TYPE=Clay_ImageElementConfig NAME=Clay__ImageElementConfigArray DEFAULT_VALUE=&CLAY__IMAGE_ELEMENT_CONFIG_DEFAULT
|
// __GENERATED__ template array_define,array_add TYPE=Clay_ImageElementConfig NAME=Clay__ImageElementConfigArray DEFAULT_VALUE=&CLAY__IMAGE_ELEMENT_CONFIG_DEFAULT
|
||||||
|
@ -554,15 +714,6 @@ Clay_ImageElementConfig *Clay__ImageElementConfigArray_Add(Clay__ImageElementCon
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
// __GENERATED__ template
|
// __GENERATED__ template
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
Clay_Vector2 offset;
|
|
||||||
Clay_Dimensions expand;
|
|
||||||
uint16_t zIndex;
|
|
||||||
uint32_t parentId;
|
|
||||||
Clay_FloatingAttachPoints attachment;
|
|
||||||
} Clay_FloatingElementConfig;
|
|
||||||
|
|
||||||
Clay_FloatingElementConfig CLAY__FLOATING_ELEMENT_CONFIG_DEFAULT = (Clay_FloatingElementConfig) {};
|
Clay_FloatingElementConfig CLAY__FLOATING_ELEMENT_CONFIG_DEFAULT = (Clay_FloatingElementConfig) {};
|
||||||
|
|
||||||
// __GENERATED__ template array_define,array_add TYPE=Clay_FloatingElementConfig NAME=Clay__FloatingElementConfigArray DEFAULT_VALUE=&CLAY__FLOATING_ELEMENT_CONFIG_DEFAULT
|
// __GENERATED__ template array_define,array_add TYPE=Clay_FloatingElementConfig NAME=Clay__FloatingElementConfigArray DEFAULT_VALUE=&CLAY__FLOATING_ELEMENT_CONFIG_DEFAULT
|
||||||
|
@ -587,15 +738,6 @@ Clay_FloatingElementConfig *Clay__FloatingElementConfigArray_Add(Clay__FloatingE
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
// __GENERATED__ template
|
// __GENERATED__ template
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
#ifndef CLAY_EXTEND_CONFIG_CUSTOM
|
|
||||||
void* customData;
|
|
||||||
#else
|
|
||||||
CLAY_EXTEND_CONFIG_CUSTOM
|
|
||||||
#endif
|
|
||||||
} Clay_CustomElementConfig;
|
|
||||||
|
|
||||||
Clay_CustomElementConfig CLAY__CUSTOM_ELEMENT_CONFIG_DEFAULT = (Clay_CustomElementConfig) {};
|
Clay_CustomElementConfig CLAY__CUSTOM_ELEMENT_CONFIG_DEFAULT = (Clay_CustomElementConfig) {};
|
||||||
|
|
||||||
// __GENERATED__ template array_define,array_add TYPE=Clay_CustomElementConfig NAME=Clay__CustomElementConfigArray DEFAULT_VALUE=&CLAY__CUSTOM_ELEMENT_CONFIG_DEFAULT
|
// __GENERATED__ template array_define,array_add TYPE=Clay_CustomElementConfig NAME=Clay__CustomElementConfigArray DEFAULT_VALUE=&CLAY__CUSTOM_ELEMENT_CONFIG_DEFAULT
|
||||||
|
@ -620,12 +762,6 @@ Clay_CustomElementConfig *Clay__CustomElementConfigArray_Add(Clay__CustomElement
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
// __GENERATED__ template
|
// __GENERATED__ template
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
bool horizontal;
|
|
||||||
bool vertical;
|
|
||||||
} Clay_ScrollElementConfig;
|
|
||||||
|
|
||||||
Clay_ScrollElementConfig CLAY__SCROLL_CONTAINER_ELEMENT_CONFIG_DEFAULT = (Clay_ScrollElementConfig ) {};
|
Clay_ScrollElementConfig CLAY__SCROLL_CONTAINER_ELEMENT_CONFIG_DEFAULT = (Clay_ScrollElementConfig ) {};
|
||||||
|
|
||||||
// __GENERATED__ template array_define,array_add TYPE=Clay_ScrollElementConfig NAME=Clay__ScrollElementConfigArray DEFAULT_VALUE=&CLAY__SCROLL_CONTAINER_ELEMENT_CONFIG_DEFAULT
|
// __GENERATED__ template array_define,array_add TYPE=Clay_ScrollElementConfig NAME=Clay__ScrollElementConfigArray DEFAULT_VALUE=&CLAY__SCROLL_CONTAINER_ELEMENT_CONFIG_DEFAULT
|
||||||
|
@ -683,22 +819,6 @@ Clay__TextElementData *Clay__TextElementDataArray_Add(Clay__TextElementDataArray
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
// __GENERATED__ template
|
// __GENERATED__ template
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
uint32_t width;
|
|
||||||
Clay_Color color;
|
|
||||||
} Clay_Border;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
Clay_Border left;
|
|
||||||
Clay_Border right;
|
|
||||||
Clay_Border top;
|
|
||||||
Clay_Border bottom;
|
|
||||||
Clay_Border betweenChildren;
|
|
||||||
Clay_CornerRadius cornerRadius;
|
|
||||||
} Clay_BorderElementConfig;
|
|
||||||
|
|
||||||
Clay_BorderElementConfig CLAY__BORDER_CONTAINER_ELEMENT_CONFIG_DEFAULT = (Clay_BorderElementConfig ) {};
|
Clay_BorderElementConfig CLAY__BORDER_CONTAINER_ELEMENT_CONFIG_DEFAULT = (Clay_BorderElementConfig ) {};
|
||||||
|
|
||||||
// __GENERATED__ template array_define,array_add TYPE=Clay_BorderElementConfig NAME=Clay__BorderElementConfigArray DEFAULT_VALUE=&CLAY__BORDER_CONTAINER_ELEMENT_CONFIG_DEFAULT
|
// __GENERATED__ template array_define,array_add TYPE=Clay_BorderElementConfig NAME=Clay__BorderElementConfigArray DEFAULT_VALUE=&CLAY__BORDER_CONTAINER_ELEMENT_CONFIG_DEFAULT
|
||||||
|
@ -729,17 +849,6 @@ typedef struct
|
||||||
uint16_t length;
|
uint16_t length;
|
||||||
} Clay__LayoutElementChildren;
|
} Clay__LayoutElementChildren;
|
||||||
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
Clay_RectangleElementConfig *rectangleElementConfig;
|
|
||||||
Clay_TextElementConfig *textElementConfig;
|
|
||||||
Clay_ImageElementConfig *imageElementConfig;
|
|
||||||
Clay_FloatingElementConfig *floatingElementConfig;
|
|
||||||
Clay_CustomElementConfig *customElementConfig;
|
|
||||||
Clay_ScrollElementConfig *scrollElementConfig;
|
|
||||||
Clay_BorderElementConfig *borderElementConfig;
|
|
||||||
} Clay_ElementConfigUnion;
|
|
||||||
|
|
||||||
typedef struct t_Clay_LayoutElement
|
typedef struct t_Clay_LayoutElement
|
||||||
{
|
{
|
||||||
#ifdef CLAY_DEBUG
|
#ifdef CLAY_DEBUG
|
||||||
|
@ -818,26 +927,10 @@ Clay_LayoutElement* Clay__LayoutElementPointerArray_RemoveSwapback(Clay__LayoutE
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
// __GENERATED__ template
|
// __GENERATED__ template
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
Clay_BoundingBox boundingBox;
|
|
||||||
Clay_ElementConfigUnion config;
|
|
||||||
Clay_String text; // TODO I wish there was a way to avoid having to have this on every render command
|
|
||||||
uint32_t id;
|
|
||||||
Clay_RenderCommandType commandType;
|
|
||||||
} Clay_RenderCommand;
|
|
||||||
|
|
||||||
Clay_RenderCommand CLAY__RENDER_COMMAND_DEFAULT = (Clay_RenderCommand) {};
|
Clay_RenderCommand CLAY__RENDER_COMMAND_DEFAULT = (Clay_RenderCommand) {};
|
||||||
|
|
||||||
// __GENERATED__ template array_define TYPE=Clay_RenderCommand NAME=Clay_RenderCommandArray
|
// __GENERATED__ template array_define TYPE=Clay_RenderCommand NAME=Clay_RenderCommandArray
|
||||||
#pragma region generated
|
#pragma region generated
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
uint32_t capacity;
|
|
||||||
uint32_t length;
|
|
||||||
Clay_RenderCommand *internalArray;
|
|
||||||
} Clay_RenderCommandArray;
|
|
||||||
|
|
||||||
Clay_RenderCommandArray Clay_RenderCommandArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) {
|
Clay_RenderCommandArray Clay_RenderCommandArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) {
|
||||||
return (Clay_RenderCommandArray){.capacity = capacity, .length = 0, .internalArray = (Clay_RenderCommand *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_RenderCommand), CLAY__ALIGNMENT(Clay_RenderCommand), arena)};
|
return (Clay_RenderCommandArray){.capacity = capacity, .length = 0, .internalArray = (Clay_RenderCommand *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_RenderCommand), CLAY__ALIGNMENT(Clay_RenderCommand), arena)};
|
||||||
}
|
}
|
||||||
|
@ -2325,19 +2418,14 @@ void Clay__CalculateFinalLayout() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct
|
inline Clay_LayoutConfig * Clay__StoreLayoutConfig(Clay_LayoutConfig config) { return Clay__LayoutConfigArray_Add(&Clay__layoutConfigs, config); }
|
||||||
{
|
inline Clay_RectangleElementConfig * Clay__StoreRectangleElementConfig(Clay_RectangleElementConfig config) { return Clay__RectangleElementConfigArray_Add(&Clay__rectangleElementConfigs, config); }
|
||||||
// Note: This is a pointer to the real internal scroll position, mutating it may cause a change in final layout.
|
inline Clay_TextElementConfig * Clay__StoreTextElementConfig(Clay_TextElementConfig config) { return Clay__TextElementConfigArray_Add(&Clay__textElementConfigs, config); }
|
||||||
// Intended for use with external functionality that modifies scroll position, such as scroll bars or auto scrolling.
|
inline Clay_ImageElementConfig * Clay__StoreImageElementConfig(Clay_ImageElementConfig config) { return Clay__ImageElementConfigArray_Add(&Clay__imageElementConfigs, config); }
|
||||||
Clay_Vector2 *scrollPosition;
|
inline Clay_FloatingElementConfig * Clay__StoreFloatingElementConfig(Clay_FloatingElementConfig config) { return Clay__FloatingElementConfigArray_Add(&Clay__floatingElementConfigs, config); }
|
||||||
Clay_Dimensions scrollContainerDimensions;
|
inline Clay_CustomElementConfig * Clay__StoreCustomElementConfig(Clay_CustomElementConfig config) { return Clay__CustomElementConfigArray_Add(&Clay__customElementConfigs, config); }
|
||||||
Clay_Dimensions contentDimensions;
|
inline Clay_ScrollElementConfig * Clay__StoreScrollElementConfig(Clay_ScrollElementConfig config) { return Clay__ScrollElementConfigArray_Add(&Clay__scrollElementConfigs, config); }
|
||||||
Clay_ScrollElementConfig config;
|
inline Clay_BorderElementConfig * Clay__StoreBorderElementConfig(Clay_BorderElementConfig config) { return Clay__BorderElementConfigArray_Add(&Clay__borderElementConfigs, config); }
|
||||||
// Indicates whether an actual scroll container matched the provided ID or if the default struct was returned.
|
|
||||||
bool found;
|
|
||||||
} Clay_ScrollContainerData;
|
|
||||||
|
|
||||||
Clay_ScrollContainerData Clay_GetScrollContainerData(Clay_ElementId id);
|
|
||||||
|
|
||||||
#pragma region DebugTools
|
#pragma region DebugTools
|
||||||
const Clay_Color CLAY__DEBUGVIEW_COLOR_1 = (Clay_Color) {58, 56, 52, 255};
|
const Clay_Color CLAY__DEBUGVIEW_COLOR_1 = (Clay_Color) {58, 56, 52, 255};
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
|
#define CLAY_IMPLEMENTATION
|
||||||
#include<clay.h>
|
#include<clay.h>
|
45
src/root.zig
45
src/root.zig
|
@ -255,18 +255,18 @@ const extern_elements = struct {
|
||||||
extern "c" fn Clay__CloseElementWithChildren() void;
|
extern "c" fn Clay__CloseElementWithChildren() void;
|
||||||
extern "c" fn Clay__CloseScrollElement() void;
|
extern "c" fn Clay__CloseScrollElement() void;
|
||||||
extern "c" fn Clay__CloseFloatingElement() void;
|
extern "c" fn Clay__CloseFloatingElement() void;
|
||||||
extern "c" fn Clay__LayoutConfigArray_Add(array: *ClayArray(LayoutConfig), config: LayoutConfig) *LayoutConfig;
|
extern "c" fn Clay__StoreLayoutConfig(config: LayoutConfig) *LayoutConfig;
|
||||||
extern "c" fn Clay__RectangleElementConfigArray_Add(array: *ClayArray(RectangleElementConfig), config: RectangleElementConfig) *RectangleElementConfig;
|
extern "c" fn Clay__StoreRectangleElementConfig(config: RectangleElementConfig) *RectangleElementConfig;
|
||||||
extern "c" fn Clay__TextElementConfigArray_Add(array: *ClayArray(TextElementConfig), config: TextElementConfig) *TextElementConfig;
|
extern "c" fn Clay__StoreTextElementConfig(config: TextElementConfig) *TextElementConfig;
|
||||||
extern "c" fn Clay__ImageElementConfigArray_Add(array: *ClayArray(ImageElementConfig), config: ImageElementConfig) *ImageElementConfig;
|
extern "c" fn Clay__StoreImageElementConfig(config: ImageElementConfig) *ImageElementConfig;
|
||||||
extern "c" fn Clay__FloatingElementConfigArray_Add(array: *ClayArray(FloatingElementConfig), config: FloatingElementConfig) *FloatingElementConfig;
|
extern "c" fn Clay__StoreFloatingElementConfig(config: FloatingElementConfig) *FloatingElementConfig;
|
||||||
extern "c" fn Clay__CustomElementConfigArray_Add(array: *ClayArray(CustomElementConfig), config: CustomElementConfig) *CustomElementConfig;
|
extern "c" fn Clay__StoreCustomElementConfig(config: CustomElementConfig) *CustomElementConfig;
|
||||||
extern "c" fn Clay__ScrollElementConfigArray_Add(array: *ClayArray(ScrollElementConfig), config: ScrollElementConfig) *ScrollElementConfig;
|
extern "c" fn Clay__StoreScrollElementConfig(config: ScrollElementConfig) *ScrollElementConfig;
|
||||||
extern "c" fn Clay__BorderElementConfigArray_Add(array: *ClayArray(BorderElementConfig), config: BorderElementConfig) *BorderElementConfig;
|
extern "c" fn Clay__StoreBorderElementConfig(config: BorderElementConfig) *BorderElementConfig;
|
||||||
extern "c" fn Clay__HashString(toHash: String, index: u32) ElementId;
|
extern "c" fn Clay__HashString(toHash: String, index: u32) ElementId;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Foreign function
|
// Public function declarations
|
||||||
pub const MinMemorySize = extern_elements.Clay_MinMemorySize;
|
pub const MinMemorySize = extern_elements.Clay_MinMemorySize;
|
||||||
pub const CreateArenaWithCapacityAndMemory = extern_elements.Clay_CreateArenaWithCapacityAndMemory;
|
pub const CreateArenaWithCapacityAndMemory = extern_elements.Clay_CreateArenaWithCapacityAndMemory;
|
||||||
pub const SetPointerState = extern_elements.Clay_SetPointerState;
|
pub const SetPointerState = extern_elements.Clay_SetPointerState;
|
||||||
|
@ -281,16 +281,7 @@ pub const SetMeasureTextFunction = extern_elements.Clay_SetMeasureTextFunction;
|
||||||
pub const RenderCommandArray_Get = extern_elements.Clay_RenderCommandArray_Get;
|
pub const RenderCommandArray_Get = extern_elements.Clay_RenderCommandArray_Get;
|
||||||
pub const SetDebugModeEnabled = extern_elements.Clay_SetDebugModeEnabled;
|
pub const SetDebugModeEnabled = extern_elements.Clay_SetDebugModeEnabled;
|
||||||
|
|
||||||
// Private external variables
|
// Private function declarations
|
||||||
extern "c" var Clay__layoutConfigs: ClayArray(LayoutConfig);
|
|
||||||
extern "c" var Clay__rectangleElementConfigs: ClayArray(RectangleElementConfig);
|
|
||||||
extern "c" var Clay__textElementConfigs: ClayArray(TextElementConfig);
|
|
||||||
extern "c" var Clay__imageElementConfigs: ClayArray(ImageElementConfig);
|
|
||||||
extern "c" var Clay__floatingElementConfigs: ClayArray(FloatingElementConfig);
|
|
||||||
extern "c" var Clay__customElementConfigs: ClayArray(CustomElementConfig);
|
|
||||||
extern "c" var Clay__scrollElementConfigs: ClayArray(ScrollElementConfig);
|
|
||||||
extern "c" var Clay__borderElementConfigs: ClayArray(BorderElementConfig);
|
|
||||||
|
|
||||||
pub const OpenContainerElement = extern_elements.Clay__OpenContainerElement;
|
pub const OpenContainerElement = extern_elements.Clay__OpenContainerElement;
|
||||||
pub const OpenRectangleElement = extern_elements.Clay__OpenRectangleElement;
|
pub const OpenRectangleElement = extern_elements.Clay__OpenRectangleElement;
|
||||||
pub const OpenTextElement = extern_elements.Clay__OpenTextElement;
|
pub const OpenTextElement = extern_elements.Clay__OpenTextElement;
|
||||||
|
@ -302,14 +293,14 @@ pub const OpenCustomElement = extern_elements.Clay__OpenCustomElement;
|
||||||
pub const CloseElementWithChildren = extern_elements.Clay__CloseElementWithChildren;
|
pub const CloseElementWithChildren = extern_elements.Clay__CloseElementWithChildren;
|
||||||
pub const CloseScrollElement = extern_elements.Clay__CloseScrollElement;
|
pub const CloseScrollElement = extern_elements.Clay__CloseScrollElement;
|
||||||
pub const CloseFloatingElement = extern_elements.Clay__CloseFloatingElement;
|
pub const CloseFloatingElement = extern_elements.Clay__CloseFloatingElement;
|
||||||
pub const LayoutConfigArray_Add = extern_elements.Clay__LayoutConfigArray_Add;
|
pub const StoreLayoutConfig = extern_elements.Clay__StoreLayoutConfig;
|
||||||
pub const RectangleElementConfigArray_Add = extern_elements.Clay__RectangleElementConfigArray_Add;
|
pub const StoreRectangleElementConfig = extern_elements.Clay__StoreRectangleElementConfig;
|
||||||
pub const TextElementConfigArray_Add = extern_elements.Clay__TextElementConfigArray_Add;
|
pub const StoreTextElementConfig = extern_elements.Clay__StoreTextElementConfig;
|
||||||
pub const ImageElementConfigArray_Add = extern_elements.Clay__ImageElementConfigArray_Add;
|
pub const StoreImageElementConfig = extern_elements.Clay__StoreImageElementConfig;
|
||||||
pub const FloatingElementConfigArray_Add = extern_elements.Clay__FloatingElementConfigArray_Add;
|
pub const StoreFloatingElementConfig = extern_elements.Clay__StoreFloatingElementConfig;
|
||||||
pub const CustomElementConfigArray_Add = extern_elements.Clay__CustomElementConfigArray_Add;
|
pub const StoreCustomElementConfig = extern_elements.Clay__StoreCustomElementConfig;
|
||||||
pub const ScrollElementConfigArray_Add = extern_elements.Clay__ScrollElementConfigArray_Add;
|
pub const StoreScrollElementConfig = extern_elements.Clay__StoreScrollElementConfig;
|
||||||
pub const BorderElementConfigArray_Add = extern_elements.Clay__BorderElementConfigArray_Add;
|
pub const StoreBorderElementConfig = extern_elements.Clay__StoreBorderElementConfig;
|
||||||
pub const HashString = extern_elements.Clay__HashString;
|
pub const HashString = extern_elements.Clay__HashString;
|
||||||
|
|
||||||
fn measureText(str: *String, conf: *TextElementConfig) callconv(.C) Dimensions {
|
fn measureText(str: *String, conf: *TextElementConfig) callconv(.C) Dimensions {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue