mirror of
https://github.com/nicbarker/clay.git
synced 2025-01-23 18:06:04 +00:00
Rename Clay_Rectangle to Clay_BoundingBox (#4)
This commit is contained in:
parent
52b6b0564e
commit
ca2c625bb5
@ -1462,7 +1462,7 @@ An array of [Clay_RenderCommand](#clay_rendercommand)s representing the calculat
|
|||||||
```C
|
```C
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
Clay_Rectangle boundingBox;
|
Clay_BoundingBox boundingBox;
|
||||||
Clay_ElementConfigUnion config;
|
Clay_ElementConfigUnion config;
|
||||||
Clay_String text;
|
Clay_String text;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
@ -1487,12 +1487,12 @@ An enum indicating how this render command should be handled. Possible values in
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**`.boundingBox`** - `Clay_Rectangle`
|
**`.boundingBox`** - `Clay_BoundingBox`
|
||||||
|
|
||||||
```C
|
```C
|
||||||
typedef struct {
|
typedef struct {
|
||||||
float x, y, width, height;
|
float x, y, width, height;
|
||||||
} Clay_Rectangle;
|
} Clay_BoundingBox;
|
||||||
```
|
```
|
||||||
|
|
||||||
A rectangle representing the bounding box of this render command, with `.x` and `.y` representing the top left corner of the element.
|
A rectangle representing the bounding box of this render command, with `.x` and `.y` representing the top left corner of the element.
|
||||||
|
18
clay.h
18
clay.h
@ -242,7 +242,7 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
float x, y, width, height;
|
float x, y, width, height;
|
||||||
} Clay_Rectangle;
|
} Clay_BoundingBox;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
float width, height;
|
float width, height;
|
||||||
@ -727,7 +727,7 @@ Clay_LayoutElement* Clay__LayoutElementPointerArray_RemoveSwapback(Clay__LayoutE
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
Clay_Rectangle boundingBox;
|
Clay_BoundingBox boundingBox;
|
||||||
Clay_ElementConfigUnion config;
|
Clay_ElementConfigUnion config;
|
||||||
Clay_String text; // TODO I wish there was a way to avoid having to have this on every render command
|
Clay_String text; // TODO I wish there was a way to avoid having to have this on every render command
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
@ -774,7 +774,7 @@ Clay_RenderCommand *Clay_RenderCommandArray_Get(Clay_RenderCommandArray *array,
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
Clay_LayoutElement *layoutElement;
|
Clay_LayoutElement *layoutElement;
|
||||||
Clay_Rectangle boundingBox;
|
Clay_BoundingBox boundingBox;
|
||||||
Clay_Dimensions contentSize;
|
Clay_Dimensions contentSize;
|
||||||
Clay_Vector2 scrollOrigin;
|
Clay_Vector2 scrollOrigin;
|
||||||
Clay_Vector2 pointerOrigin;
|
Clay_Vector2 pointerOrigin;
|
||||||
@ -830,7 +830,7 @@ Clay__ScrollContainerDataInternal Clay__ScrollContainerDataInternalArray_RemoveS
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
Clay_Rectangle boundingBox;
|
Clay_BoundingBox boundingBox;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
Clay_LayoutElement* layoutElement;
|
Clay_LayoutElement* layoutElement;
|
||||||
int32_t nextIndex;
|
int32_t nextIndex;
|
||||||
@ -1157,7 +1157,7 @@ Clay_Dimensions Clay__MeasureTextCached(Clay_String *text, Clay_TextElementConfi
|
|||||||
return measured;
|
return measured;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Clay__PointIsInsideRect(Clay_Vector2 point, Clay_Rectangle rect) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1776,7 +1776,7 @@ void Clay__CalculateFinalLayout(int screenWidth, int screenHeight) {
|
|||||||
if (parentHashMapItem) {
|
if (parentHashMapItem) {
|
||||||
Clay_FloatingElementConfig *config = root->layoutElement->elementConfig.floatingElementConfig;
|
Clay_FloatingElementConfig *config = root->layoutElement->elementConfig.floatingElementConfig;
|
||||||
Clay_Dimensions rootDimensions = root->layoutElement->dimensions;
|
Clay_Dimensions rootDimensions = root->layoutElement->dimensions;
|
||||||
Clay_Rectangle parentBoundingBox = parentHashMapItem->boundingBox;
|
Clay_BoundingBox parentBoundingBox = parentHashMapItem->boundingBox;
|
||||||
// Set X position
|
// Set X position
|
||||||
Clay_Vector2 targetAttachPosition = (Clay_Vector2){};
|
Clay_Vector2 targetAttachPosition = (Clay_Vector2){};
|
||||||
switch (config->attachment.parent) {
|
switch (config->attachment.parent) {
|
||||||
@ -1850,7 +1850,7 @@ void Clay__CalculateFinalLayout(int screenWidth, int screenHeight) {
|
|||||||
if (!Clay__treeNodeVisited.internalArray[dfsBuffer.length - 1]) {
|
if (!Clay__treeNodeVisited.internalArray[dfsBuffer.length - 1]) {
|
||||||
Clay__treeNodeVisited.internalArray[dfsBuffer.length - 1] = true;
|
Clay__treeNodeVisited.internalArray[dfsBuffer.length - 1] = true;
|
||||||
|
|
||||||
Clay_Rectangle currentElementBoundingBox = (Clay_Rectangle) { currentElementTreeNode->position.x, currentElementTreeNode->position.y, currentElement->dimensions.width, currentElement->dimensions.height };
|
Clay_BoundingBox currentElementBoundingBox = (Clay_BoundingBox) { currentElementTreeNode->position.x, currentElementTreeNode->position.y, currentElement->dimensions.width, currentElement->dimensions.height };
|
||||||
if (currentElement->elementType == CLAY__LAYOUT_ELEMENT_TYPE_FLOATING_CONTAINER) {
|
if (currentElement->elementType == CLAY__LAYOUT_ELEMENT_TYPE_FLOATING_CONTAINER) {
|
||||||
Clay_FloatingElementConfig *floatingElementConfig = currentElement->elementConfig.floatingElementConfig;
|
Clay_FloatingElementConfig *floatingElementConfig = currentElement->elementConfig.floatingElementConfig;
|
||||||
Clay_Dimensions expand = floatingElementConfig->expand;
|
Clay_Dimensions expand = floatingElementConfig->expand;
|
||||||
@ -1975,7 +1975,7 @@ void Clay__CalculateFinalLayout(int screenWidth, int screenHeight) {
|
|||||||
});
|
});
|
||||||
// Borders between elements are expressed as additional rectangle render commands
|
// Borders between elements are expressed as additional rectangle render commands
|
||||||
} else if (currentElement->elementType == CLAY__LAYOUT_ELEMENT_TYPE_BORDER_CONTAINER) {
|
} else if (currentElement->elementType == CLAY__LAYOUT_ELEMENT_TYPE_BORDER_CONTAINER) {
|
||||||
Clay_Rectangle currentElementBoundingBox = (Clay_Rectangle) { currentElementTreeNode->position.x, currentElementTreeNode->position.y, currentElement->dimensions.width, currentElement->dimensions.height };
|
Clay_BoundingBox currentElementBoundingBox = (Clay_BoundingBox) { currentElementTreeNode->position.x, currentElementTreeNode->position.y, currentElement->dimensions.width, currentElement->dimensions.height };
|
||||||
bool offscreen = currentElementBoundingBox.x > (float)screenWidth || currentElementBoundingBox.y > (float)screenHeight || currentElementBoundingBox.x + currentElementBoundingBox.width < 0 || currentElementBoundingBox.y + currentElementBoundingBox.height < 0;
|
bool offscreen = currentElementBoundingBox.x > (float)screenWidth || currentElementBoundingBox.y > (float)screenHeight || currentElementBoundingBox.x + currentElementBoundingBox.width < 0 || currentElementBoundingBox.y + currentElementBoundingBox.height < 0;
|
||||||
if (offscreen) {
|
if (offscreen) {
|
||||||
dfsBuffer.length--;
|
dfsBuffer.length--;
|
||||||
@ -2122,7 +2122,7 @@ void Clay_SetPointerPosition(Clay_Vector2 position) {
|
|||||||
Clay__treeNodeVisited.internalArray[dfsBuffer.length - 1] = true;
|
Clay__treeNodeVisited.internalArray[dfsBuffer.length - 1] = true;
|
||||||
Clay_LayoutElement *currentElement = *Clay__LayoutElementPointerArray_Get(&dfsBuffer, (int)dfsBuffer.length - 1);
|
Clay_LayoutElement *currentElement = *Clay__LayoutElementPointerArray_Get(&dfsBuffer, (int)dfsBuffer.length - 1);
|
||||||
Clay_LayoutElementHashMapItem *mapItem = Clay__GetHashMapItem(currentElement->id); // TODO I wish there was a way around this, maybe the fact that it's essentially a binary tree limits the cost, have to measure
|
Clay_LayoutElementHashMapItem *mapItem = Clay__GetHashMapItem(currentElement->id); // TODO I wish there was a way around this, maybe the fact that it's essentially a binary tree limits the cost, have to measure
|
||||||
if ((mapItem && Clay__PointIsInsideRect(position, mapItem->boundingBox)) || (!mapItem && Clay__PointIsInsideRect(position, (Clay_Rectangle) {0,0, currentElement->dimensions.width, currentElement->dimensions.height}))) {
|
if ((mapItem && Clay__PointIsInsideRect(position, mapItem->boundingBox)) || (!mapItem && Clay__PointIsInsideRect(position, (Clay_BoundingBox) {0,0, currentElement->dimensions.width, currentElement->dimensions.height}))) {
|
||||||
Clay__int32_tArray_Add(&Clay__pointerOverIds, (int)currentElement->id);
|
Clay__int32_tArray_Add(&Clay__pointerOverIds, (int)currentElement->id);
|
||||||
if (currentElement->elementType == CLAY__LAYOUT_ELEMENT_TYPE_TEXT) {
|
if (currentElement->elementType == CLAY__LAYOUT_ELEMENT_TYPE_TEXT) {
|
||||||
dfsBuffer.length--;
|
dfsBuffer.length--;
|
||||||
|
@ -135,7 +135,7 @@ void Clay_Raylib_Render(Clay_RenderCommandArray renderCommands)
|
|||||||
for (int j = 0; j < renderCommands.length; j++)
|
for (int j = 0; j < renderCommands.length; j++)
|
||||||
{
|
{
|
||||||
Clay_RenderCommand *renderCommand = Clay_RenderCommandArray_Get(&renderCommands, j);
|
Clay_RenderCommand *renderCommand = Clay_RenderCommandArray_Get(&renderCommands, j);
|
||||||
Clay_Rectangle boundingBox = renderCommand->boundingBox;
|
Clay_BoundingBox boundingBox = renderCommand->boundingBox;
|
||||||
switch (renderCommand->commandType)
|
switch (renderCommand->commandType)
|
||||||
{
|
{
|
||||||
case CLAY_RENDER_COMMAND_TYPE_TEXT: {
|
case CLAY_RENDER_COMMAND_TYPE_TEXT: {
|
||||||
@ -214,7 +214,7 @@ void Clay_Raylib_Render(Clay_RenderCommandArray renderCommands)
|
|||||||
if (!customElement) continue;
|
if (!customElement) continue;
|
||||||
switch (customElement->type) {
|
switch (customElement->type) {
|
||||||
case CUSTOM_LAYOUT_ELEMENT_TYPE_3D_MODEL: {
|
case CUSTOM_LAYOUT_ELEMENT_TYPE_3D_MODEL: {
|
||||||
Clay_Rectangle rootBox = renderCommands.internalArray[0].boundingBox;
|
Clay_BoundingBox rootBox = renderCommands.internalArray[0].boundingBox;
|
||||||
float scaleValue = CLAY__MIN(CLAY__MIN(1, 768 / rootBox.height) * CLAY__MAX(1, rootBox.width / 1024), 1.5f);
|
float scaleValue = CLAY__MIN(CLAY__MIN(1, 768 / rootBox.height) * CLAY__MAX(1, rootBox.width / 1024), 1.5f);
|
||||||
Ray positionRay = GetScreenToWorldPointWithZDistance((Vector2) { renderCommand->boundingBox.x + renderCommand->boundingBox.width / 2, renderCommand->boundingBox.y + (renderCommand->boundingBox.height / 2) + 20 }, Raylib_camera, (int)roundf(rootBox.width), (int)roundf(rootBox.height), 140);
|
Ray positionRay = GetScreenToWorldPointWithZDistance((Vector2) { renderCommand->boundingBox.x + renderCommand->boundingBox.width / 2, renderCommand->boundingBox.y + (renderCommand->boundingBox.height / 2) + 20 }, Raylib_camera, (int)roundf(rootBox.width), (int)roundf(rootBox.height), 140);
|
||||||
BeginMode3D(Raylib_camera);
|
BeginMode3D(Raylib_camera);
|
||||||
|
Loading…
Reference in New Issue
Block a user