mirror of
https://github.com/nicbarker/clay.git
synced 2025-05-13 13:58:07 +00:00
Compare commits
5 Commits
f4a19ffb25
...
006bf569f0
Author | SHA1 | Date | |
---|---|---|---|
|
006bf569f0 | ||
|
0468243ac7 | ||
|
b9c5f8e47f | ||
|
95fcd85a2a | ||
|
4c02bd08a7 |
@ -229,8 +229,9 @@ RenderCommandData :: struct #raw_union {
|
|||||||
RenderCommand :: struct {
|
RenderCommand :: struct {
|
||||||
boundingBox: BoundingBox,
|
boundingBox: BoundingBox,
|
||||||
renderData: RenderCommandData,
|
renderData: RenderCommandData,
|
||||||
zIndex: i32,
|
userData: rawptr,
|
||||||
id: u32,
|
id: u32,
|
||||||
|
zIndex: i16,
|
||||||
commandType: RenderCommandType,
|
commandType: RenderCommandType,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,6 +327,7 @@ ElementDeclaration :: struct {
|
|||||||
custom: CustomElementConfig,
|
custom: CustomElementConfig,
|
||||||
scroll: ScrollElementConfig,
|
scroll: ScrollElementConfig,
|
||||||
border: BorderElementConfig,
|
border: BorderElementConfig,
|
||||||
|
userData: rawptr
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorType :: enum {
|
ErrorType :: enum {
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -71,9 +71,13 @@ clayRaylibRender :: proc(renderCommands: ^clay.ClayArray(clay.RenderCommand), al
|
|||||||
)
|
)
|
||||||
case clay.RenderCommandType.Image:
|
case clay.RenderCommandType.Image:
|
||||||
config := renderCommand.renderData.image
|
config := renderCommand.renderData.image
|
||||||
|
tintColor := config.backgroundColor
|
||||||
|
if (tintColor.rgba == 0) {
|
||||||
|
tintColor = { 255, 255, 255, 255 }
|
||||||
|
}
|
||||||
// TODO image handling
|
// TODO image handling
|
||||||
imageTexture := cast(^raylib.Texture2D)config.imageData
|
imageTexture := cast(^raylib.Texture2D)config.imageData
|
||||||
raylib.DrawTextureEx(imageTexture^, raylib.Vector2{boundingBox.x, boundingBox.y}, 0, boundingBox.width / cast(f32)imageTexture.width, clayColorToRaylibColor(config.backgroundColor))
|
raylib.DrawTextureEx(imageTexture^, raylib.Vector2{boundingBox.x, boundingBox.y}, 0, boundingBox.width / cast(f32)imageTexture.width, clayColorToRaylibColor(tintColor))
|
||||||
case clay.RenderCommandType.ScissorStart:
|
case clay.RenderCommandType.ScissorStart:
|
||||||
raylib.BeginScissorMode(
|
raylib.BeginScissorMode(
|
||||||
cast(i32)math.round(boundingBox.x),
|
cast(i32)math.round(boundingBox.x),
|
||||||
|
40
clay.h
40
clay.h
@ -801,6 +801,7 @@ typedef struct { // todo get this struct into a single cache line
|
|||||||
intptr_t hoverFunctionUserData;
|
intptr_t hoverFunctionUserData;
|
||||||
int32_t nextIndex;
|
int32_t nextIndex;
|
||||||
uint32_t generation;
|
uint32_t generation;
|
||||||
|
uint32_t idAlias;
|
||||||
Clay__DebugElementData *debugData;
|
Clay__DebugElementData *debugData;
|
||||||
} Clay_LayoutElementHashMapItem;
|
} Clay_LayoutElementHashMapItem;
|
||||||
|
|
||||||
@ -1210,12 +1211,12 @@ bool Clay__PointIsInsideRect(Clay_Vector2 point, Clay_BoundingBox rect) {
|
|||||||
return point.x >= rect.x && point.x <= rect.x + rect.width && point.y >= rect.y && point.y <= rect.y + rect.height;
|
return point.x >= rect.x && point.x <= rect.x + rect.width && point.y >= rect.y && point.y <= rect.y + rect.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
Clay_LayoutElementHashMapItem* Clay__AddHashMapItem(Clay_ElementId elementId, Clay_LayoutElement* layoutElement) {
|
Clay_LayoutElementHashMapItem* Clay__AddHashMapItem(Clay_ElementId elementId, Clay_LayoutElement* layoutElement, uint32_t idAlias) {
|
||||||
Clay_Context* context = Clay_GetCurrentContext();
|
Clay_Context* context = Clay_GetCurrentContext();
|
||||||
if (context->layoutElementsHashMapInternal.length == context->layoutElementsHashMapInternal.capacity - 1) {
|
if (context->layoutElementsHashMapInternal.length == context->layoutElementsHashMapInternal.capacity - 1) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
Clay_LayoutElementHashMapItem item = { .elementId = elementId, .layoutElement = layoutElement, .nextIndex = -1, .generation = context->generation + 1 };
|
Clay_LayoutElementHashMapItem item = { .elementId = elementId, .layoutElement = layoutElement, .nextIndex = -1, .generation = context->generation + 1, .idAlias = idAlias };
|
||||||
uint32_t hashBucket = elementId.id % context->layoutElementsHashMap.capacity;
|
uint32_t hashBucket = elementId.id % context->layoutElementsHashMap.capacity;
|
||||||
int32_t hashItemPrevious = -1;
|
int32_t hashItemPrevious = -1;
|
||||||
int32_t hashItemIndex = context->layoutElementsHashMap.internalArray[hashBucket];
|
int32_t hashItemIndex = context->layoutElementsHashMap.internalArray[hashBucket];
|
||||||
@ -1271,7 +1272,7 @@ void Clay__GenerateIdForAnonymousElement(Clay_LayoutElement *openLayoutElement)
|
|||||||
Clay_LayoutElement *parentElement = Clay_LayoutElementArray_Get(&context->layoutElements, Clay__int32_tArray_GetValue(&context->openLayoutElementStack, context->openLayoutElementStack.length - 2));
|
Clay_LayoutElement *parentElement = Clay_LayoutElementArray_Get(&context->layoutElements, Clay__int32_tArray_GetValue(&context->openLayoutElementStack, context->openLayoutElementStack.length - 2));
|
||||||
Clay_ElementId elementId = Clay__HashNumber(parentElement->childrenOrTextContent.children.length, parentElement->id);
|
Clay_ElementId elementId = Clay__HashNumber(parentElement->childrenOrTextContent.children.length, parentElement->id);
|
||||||
openLayoutElement->id = elementId.id;
|
openLayoutElement->id = elementId.id;
|
||||||
Clay__AddHashMapItem(elementId, openLayoutElement);
|
Clay__AddHashMapItem(elementId, openLayoutElement, 0);
|
||||||
Clay__StringArray_Add(&context->layoutElementIdStrings, elementId.stringId);
|
Clay__StringArray_Add(&context->layoutElementIdStrings, elementId.stringId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1483,7 +1484,7 @@ void Clay__OpenTextElement(Clay_String text, Clay_TextElementConfig *textConfig)
|
|||||||
Clay__MeasureTextCacheItem *textMeasured = Clay__MeasureTextCached(&text, textConfig);
|
Clay__MeasureTextCacheItem *textMeasured = Clay__MeasureTextCached(&text, textConfig);
|
||||||
Clay_ElementId elementId = Clay__HashNumber(parentElement->childrenOrTextContent.children.length, parentElement->id);
|
Clay_ElementId elementId = Clay__HashNumber(parentElement->childrenOrTextContent.children.length, parentElement->id);
|
||||||
textElement->id = elementId.id;
|
textElement->id = elementId.id;
|
||||||
Clay__AddHashMapItem(elementId, textElement);
|
Clay__AddHashMapItem(elementId, textElement, 0);
|
||||||
Clay__StringArray_Add(&context->layoutElementIdStrings, elementId.stringId);
|
Clay__StringArray_Add(&context->layoutElementIdStrings, elementId.stringId);
|
||||||
Clay_Dimensions textDimensions = { .width = textMeasured->unwrappedDimensions.width, .height = textConfig->lineHeight > 0 ? (float)textConfig->lineHeight : textMeasured->unwrappedDimensions.height };
|
Clay_Dimensions textDimensions = { .width = textMeasured->unwrappedDimensions.width, .height = textConfig->lineHeight > 0 ? (float)textConfig->lineHeight : textMeasured->unwrappedDimensions.height };
|
||||||
textElement->dimensions = textDimensions;
|
textElement->dimensions = textDimensions;
|
||||||
@ -2184,6 +2185,12 @@ void Clay__CalculateFinalLayout(void) {
|
|||||||
Clay_LayoutElementHashMapItem *hashMapItem = Clay__GetHashMapItem(currentElement->id);
|
Clay_LayoutElementHashMapItem *hashMapItem = Clay__GetHashMapItem(currentElement->id);
|
||||||
if (hashMapItem) {
|
if (hashMapItem) {
|
||||||
hashMapItem->boundingBox = currentElementBoundingBox;
|
hashMapItem->boundingBox = currentElementBoundingBox;
|
||||||
|
if (hashMapItem->idAlias) {
|
||||||
|
Clay_LayoutElementHashMapItem *hashMapItemAlias = Clay__GetHashMapItem(hashMapItem->idAlias);
|
||||||
|
if (hashMapItemAlias) {
|
||||||
|
hashMapItemAlias->boundingBox = currentElementBoundingBox;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sortedConfigIndexes[20];
|
int32_t sortedConfigIndexes[20];
|
||||||
@ -2219,6 +2226,7 @@ void Clay__CalculateFinalLayout(void) {
|
|||||||
Clay_ElementConfig *elementConfig = Clay__ElementConfigArraySlice_Get(¤tElement->elementConfigs, sortedConfigIndexes[elementConfigIndex]);
|
Clay_ElementConfig *elementConfig = Clay__ElementConfigArraySlice_Get(¤tElement->elementConfigs, sortedConfigIndexes[elementConfigIndex]);
|
||||||
Clay_RenderCommand renderCommand = {
|
Clay_RenderCommand renderCommand = {
|
||||||
.boundingBox = currentElementBoundingBox,
|
.boundingBox = currentElementBoundingBox,
|
||||||
|
.userData = sharedConfig->userData,
|
||||||
.id = currentElement->id,
|
.id = currentElement->id,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2399,6 +2407,7 @@ void Clay__CalculateFinalLayout(void) {
|
|||||||
.cornerRadius = sharedConfig->cornerRadius,
|
.cornerRadius = sharedConfig->cornerRadius,
|
||||||
.width = borderConfig->width
|
.width = borderConfig->width
|
||||||
}},
|
}},
|
||||||
|
.userData = sharedConfig->userData,
|
||||||
.id = Clay__HashNumber(currentElement->id, currentElement->childrenOrTextContent.children.length).id,
|
.id = Clay__HashNumber(currentElement->id, currentElement->childrenOrTextContent.children.length).id,
|
||||||
.commandType = CLAY_RENDER_COMMAND_TYPE_BORDER,
|
.commandType = CLAY_RENDER_COMMAND_TYPE_BORDER,
|
||||||
};
|
};
|
||||||
@ -2415,6 +2424,7 @@ void Clay__CalculateFinalLayout(void) {
|
|||||||
.renderData = { .rectangle = {
|
.renderData = { .rectangle = {
|
||||||
.backgroundColor = borderConfig->color,
|
.backgroundColor = borderConfig->color,
|
||||||
} },
|
} },
|
||||||
|
.userData = sharedConfig->userData,
|
||||||
.id = Clay__HashNumber(currentElement->id, currentElement->childrenOrTextContent.children.length + 1 + i).id,
|
.id = Clay__HashNumber(currentElement->id, currentElement->childrenOrTextContent.children.length + 1 + i).id,
|
||||||
.commandType = CLAY_RENDER_COMMAND_TYPE_RECTANGLE,
|
.commandType = CLAY_RENDER_COMMAND_TYPE_RECTANGLE,
|
||||||
});
|
});
|
||||||
@ -2426,12 +2436,13 @@ void Clay__CalculateFinalLayout(void) {
|
|||||||
Clay_LayoutElement *childElement = Clay_LayoutElementArray_Get(&context->layoutElements, currentElement->childrenOrTextContent.children.elements[i]);
|
Clay_LayoutElement *childElement = Clay_LayoutElementArray_Get(&context->layoutElements, currentElement->childrenOrTextContent.children.elements[i]);
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
Clay__AddRenderCommand(CLAY__INIT(Clay_RenderCommand) {
|
Clay__AddRenderCommand(CLAY__INIT(Clay_RenderCommand) {
|
||||||
.boundingBox = { currentElementBoundingBox.x + scrollOffset.x, currentElementBoundingBox.y + borderOffset.y + scrollOffset.y, currentElement->dimensions.width, (float)borderConfig->width.betweenChildren },
|
.boundingBox = { currentElementBoundingBox.x + scrollOffset.x, currentElementBoundingBox.y + borderOffset.y + scrollOffset.y, currentElement->dimensions.width, (float)borderConfig->width.betweenChildren },
|
||||||
.renderData = { .rectangle = {
|
.renderData = { .rectangle = {
|
||||||
.backgroundColor = borderConfig->color,
|
.backgroundColor = borderConfig->color,
|
||||||
} },
|
} },
|
||||||
.id = Clay__HashNumber(currentElement->id, currentElement->childrenOrTextContent.children.length + 1 + i).id,
|
.userData = sharedConfig->userData,
|
||||||
.commandType = CLAY_RENDER_COMMAND_TYPE_RECTANGLE,
|
.id = Clay__HashNumber(currentElement->id, currentElement->childrenOrTextContent.children.length + 1 + i).id,
|
||||||
|
.commandType = CLAY_RENDER_COMMAND_TYPE_RECTANGLE,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
borderOffset.y += (childElement->dimensions.height + (float)layoutConfig->childGap);
|
borderOffset.y += (childElement->dimensions.height + (float)layoutConfig->childGap);
|
||||||
@ -2444,7 +2455,7 @@ void Clay__CalculateFinalLayout(void) {
|
|||||||
if (closeScrollElement) {
|
if (closeScrollElement) {
|
||||||
Clay__AddRenderCommand(CLAY__INIT(Clay_RenderCommand) {
|
Clay__AddRenderCommand(CLAY__INIT(Clay_RenderCommand) {
|
||||||
.id = Clay__HashNumber(currentElement->id, rootElement->childrenOrTextContent.children.length + 11).id,
|
.id = Clay__HashNumber(currentElement->id, rootElement->childrenOrTextContent.children.length + 11).id,
|
||||||
.commandType = CLAY_RENDER_COMMAND_TYPE_SCISSOR_END,
|
.commandType = CLAY_RENDER_COMMAND_TYPE_SCISSOR_END,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2512,8 +2523,9 @@ Clay_ElementId Clay__AttachId(Clay_ElementId elementId) {
|
|||||||
return Clay_ElementId_DEFAULT;
|
return Clay_ElementId_DEFAULT;
|
||||||
}
|
}
|
||||||
Clay_LayoutElement *openLayoutElement = Clay__GetOpenLayoutElement();
|
Clay_LayoutElement *openLayoutElement = Clay__GetOpenLayoutElement();
|
||||||
|
uint32_t idAlias = openLayoutElement->id;
|
||||||
openLayoutElement->id = elementId.id;
|
openLayoutElement->id = elementId.id;
|
||||||
Clay__AddHashMapItem(elementId, openLayoutElement);
|
Clay__AddHashMapItem(elementId, openLayoutElement, idAlias);
|
||||||
Clay__StringArray_Add(&context->layoutElementIdStrings, elementId.stringId);
|
Clay__StringArray_Add(&context->layoutElementIdStrings, elementId.stringId);
|
||||||
return elementId;
|
return elementId;
|
||||||
}
|
}
|
||||||
@ -3254,6 +3266,10 @@ void Clay_SetPointerState(Clay_Vector2 position, bool isPointerDown) {
|
|||||||
}
|
}
|
||||||
Clay__ElementIdArray_Add(&context->pointerOverIds, mapItem->elementId);
|
Clay__ElementIdArray_Add(&context->pointerOverIds, mapItem->elementId);
|
||||||
found = true;
|
found = true;
|
||||||
|
|
||||||
|
if (mapItem->idAlias != 0) {
|
||||||
|
Clay__ElementIdArray_Add(&context->pointerOverIds, CLAY__INIT(Clay_ElementId) { .id = mapItem->idAlias });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (Clay__ElementHasConfig(currentElement, CLAY__ELEMENT_CONFIG_TYPE_TEXT)) {
|
if (Clay__ElementHasConfig(currentElement, CLAY__ELEMENT_CONFIG_TYPE_TEXT)) {
|
||||||
dfsBuffer.length--;
|
dfsBuffer.length--;
|
||||||
|
@ -226,7 +226,7 @@ int main(void) {
|
|||||||
uint64_t totalMemorySize = Clay_MinMemorySize();
|
uint64_t totalMemorySize = Clay_MinMemorySize();
|
||||||
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize));
|
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize));
|
||||||
Clay_Initialize(clayMemory, (Clay_Dimensions) { (float)GetScreenWidth(), (float)GetScreenHeight() }, (Clay_ErrorHandler) { HandleClayErrors });
|
Clay_Initialize(clayMemory, (Clay_Dimensions) { (float)GetScreenWidth(), (float)GetScreenHeight() }, (Clay_ErrorHandler) { HandleClayErrors });
|
||||||
Clay_Raylib_Initialize(1024, 768, "Clay - Raylib Renderer Example", FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_HIGHDPI | FLAG_MSAA_4X_HINT);
|
Clay_Raylib_Initialize(1024, 768, "Clay - Raylib Renderer Example", FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE | FLAG_MSAA_4X_HINT);
|
||||||
profilePicture = LoadTextureFromImage(LoadImage("resources/profile-picture.png"));
|
profilePicture = LoadTextureFromImage(LoadImage("resources/profile-picture.png"));
|
||||||
|
|
||||||
Font fonts[2];
|
Font fonts[2];
|
||||||
|
Loading…
Reference in New Issue
Block a user