mirror of
https://github.com/nicbarker/clay.git
synced 2025-05-07 02:48:04 +00:00
Compare commits
6 Commits
fd7ebbe9f1
...
56a787865a
Author | SHA1 | Date | |
---|---|---|---|
|
56a787865a | ||
|
cd82ce6fcf | ||
|
23863edde0 | ||
|
974af1e61c | ||
|
10f1565f6f | ||
|
77bc75fc8b |
22
clay.h
22
clay.h
@ -2117,9 +2117,9 @@ void Clay__InitializePersistentMemory(Clay_Context* context) {
|
||||
void Clay__CompressChildrenAlongAxis(bool xAxis, float totalSizeToDistribute, Clay__int32_tArray resizableContainerBuffer) {
|
||||
Clay_Context* context = Clay_GetCurrentContext();
|
||||
Clay__int32_tArray largestContainers = context->openClipElementStack;
|
||||
largestContainers.length = 0;
|
||||
|
||||
while (totalSizeToDistribute > 0.1) {
|
||||
largestContainers.length = 0;
|
||||
float largestSize = 0;
|
||||
float targetSize = 0;
|
||||
for (int32_t i = 0; i < resizableContainerBuffer.length; ++i) {
|
||||
@ -2141,23 +2141,29 @@ void Clay__CompressChildrenAlongAxis(bool xAxis, float totalSizeToDistribute, Cl
|
||||
}
|
||||
}
|
||||
|
||||
if (largestContainers.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
targetSize = CLAY__MAX(targetSize, (largestSize * largestContainers.length) - totalSizeToDistribute) / largestContainers.length;
|
||||
|
||||
for (int32_t childOffset = 0; childOffset < largestContainers.length; childOffset++) {
|
||||
Clay_LayoutElement *childElement = Clay_LayoutElementArray_Get(&context->layoutElements, Clay__int32_tArray_Get(&largestContainers, childOffset));
|
||||
int32_t childIndex = Clay__int32_tArray_Get(&largestContainers, childOffset);
|
||||
Clay_LayoutElement *childElement = Clay_LayoutElementArray_Get(&context->layoutElements, childIndex);
|
||||
float *childSize = xAxis ? &childElement->dimensions.width : &childElement->dimensions.height;
|
||||
float childMinSize = xAxis ? childElement->minDimensions.width : childElement->minDimensions.height;
|
||||
float oldChildSize = *childSize;
|
||||
*childSize = CLAY__MAX(childMinSize, targetSize);
|
||||
totalSizeToDistribute -= (oldChildSize - *childSize);
|
||||
if (*childSize == childMinSize) {
|
||||
Clay__int32_tArray_RemoveSwapback(&largestContainers, childOffset);
|
||||
childOffset--;
|
||||
for (int32_t i = 0; i < resizableContainerBuffer.length; i++) {
|
||||
if (Clay__int32_tArray_Get(&resizableContainerBuffer, i) == childIndex) {
|
||||
Clay__int32_tArray_RemoveSwapback(&resizableContainerBuffer, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (largestContainers.length == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#define CLAY_IMPLEMENTATION
|
||||
#include "../../clay.h"
|
||||
#include "../../renderers/raylib/clay_renderer_raylib.c"
|
||||
#define CLAY_RAYLIB_IMPLEMENTATION // This is different to the video, the raylib renderer is now in a header file
|
||||
#include "../../renderers/raylib/clay_renderer_raylib.h"
|
||||
|
||||
const int FONT_ID_BODY_16 = 0;
|
||||
Clay_Color COLOR_WHITE = { 255, 255, 255, 255};
|
||||
|
@ -1,6 +1,7 @@
|
||||
#define CLAY_IMPLEMENTATION
|
||||
#include "../../clay.h"
|
||||
#include "../../renderers/raylib/clay_renderer_raylib.c"
|
||||
#define CLAY_RAYLIB_IMPLEMENTATION
|
||||
#include "../../renderers/raylib/clay_renderer_raylib.h"
|
||||
|
||||
const uint32_t FONT_ID_BODY_24 = 0;
|
||||
const uint32_t FONT_ID_BODY_16 = 1;
|
||||
|
@ -1,3 +1,6 @@
|
||||
#ifndef CLAY_RENDERER_RAYLIB_H
|
||||
#define CLAY_RENDERER_RAYLIB_H
|
||||
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
#include "stdint.h"
|
||||
@ -14,8 +17,6 @@ typedef struct
|
||||
Font font;
|
||||
} Raylib_Font;
|
||||
|
||||
Raylib_Font Raylib_fonts[10];
|
||||
Camera Raylib_camera;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@ -38,6 +39,14 @@ typedef struct
|
||||
};
|
||||
} CustomLayoutElement;
|
||||
|
||||
#ifdef CLAY_RAYLIB_IMPLEMENTATION
|
||||
#undef CLAY_RAYLIB_IMPLEMENTATION
|
||||
|
||||
// Global state
|
||||
Raylib_Font Raylib_fonts[10];
|
||||
Camera Raylib_camera;
|
||||
uint32_t measureCalls = 0;
|
||||
|
||||
// Get a ray trace from the screen position (i.e mouse) within a specific section of the screen
|
||||
Ray GetScreenToWorldPointWithZDistance(Vector2 position, Camera camera, int screenWidth, int screenHeight, float zDistance)
|
||||
{
|
||||
@ -87,8 +96,6 @@ Ray GetScreenToWorldPointWithZDistance(Vector2 position, Camera camera, int scre
|
||||
return ray;
|
||||
}
|
||||
|
||||
uint32_t measureCalls = 0;
|
||||
|
||||
static inline Clay_Dimensions Raylib_MeasureText(Clay_String *text, Clay_TextElementConfig *config) {
|
||||
measureCalls++;
|
||||
// Measure string size for Font
|
||||
@ -122,6 +129,7 @@ static inline Clay_Dimensions Raylib_MeasureText(Clay_String *text, Clay_TextEle
|
||||
}
|
||||
|
||||
void Clay_Raylib_Initialize(int width, int height, const char *title, unsigned int flags) {
|
||||
measureCalls = 0;
|
||||
SetConfigFlags(flags);
|
||||
InitWindow(width, height, title);
|
||||
// EnableEventWaiting();
|
||||
@ -231,3 +239,6 @@ void Clay_Raylib_Render(Clay_RenderCommandArray renderCommands)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CLAY_RAYLIB_IMPLEMENTATION
|
||||
#endif // CLAY_RENDERER_RAYLIB_H
|
Loading…
Reference in New Issue
Block a user