Compare commits

...

7 Commits

Author SHA1 Message Date
peter
a0dea26198
Merge 23863edde0 into 6cb9c7c483 2025-01-05 02:36:13 +01:00
vince
6cb9c7c483
fix #99 - [Core] Bug in text wrapping at very narrow widths (#163)
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Waiting to run
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Failing after 1m36s
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Failing after 16s
2025-01-05 14:34:36 +13:00
vince
723f59dffd
[Renderers/Web] treat RenderCommand.commandType as uint8_t instead of uint32_t (#162) 2025-01-05 14:34:16 +13:00
peterc-s
23863edde0
add undef
Author:    peterc-s <pjcsmail@gmail.com>
2024-12-28 14:22:18 +00:00
peterc-s
974af1e61c
update raylib video example to use header file and fix segfault
Author:    peterc-s <pjcsmail@gmail.com>
2024-12-28 14:22:16 +00:00
peterc-s
10f1565f6f
update raylib scrolling sidebar example
Author:    peterc-s <pjcsmail@gmail.com>
2024-12-28 14:22:13 +00:00
peterc-s
77bc75fc8b
move raylib renderer to header file
Author:    peterc-s <pjcsmail@gmail.com>
2024-12-28 14:22:05 +00:00
7 changed files with 31 additions and 11 deletions

1
clay.h
View File

@ -2392,6 +2392,7 @@ void Clay__CalculateFinalLayout(void) {
Clay__WrappedTextLineArray_Add(&Clay__wrappedTextLines, CLAY__INIT(Clay__WrappedTextLine) { { measuredWord->width, lineHeight }, { .length = measuredWord->length, .chars = &textElementData->text.chars[measuredWord->startOffset] } });
textElementData->wrappedLines.length++;
wordIndex = measuredWord->next;
lineStartOffset = measuredWord->startOffset + measuredWord->length;
}
// measuredWord->length == 0 means a newline character
else if (measuredWord->length == 0 || lineWidth + measuredWord->width > containerElement->dimensions.width) {

View File

@ -426,7 +426,8 @@
element.style.height = Math.round(renderCommand.boundingBox.height.value) + 'px';
}
switch(renderCommand.commandType.value) {
// note: commandType is packed to uint8_t and has 3 garbage bytes of padding
switch(renderCommand.commandType.value & 0xff) {
case (CLAY_RENDER_COMMAND_TYPE_NONE): {
break;
}
@ -580,7 +581,9 @@
for (let i = 0; i < length; i++, arrayOffset += renderCommandSize) {
let renderCommand = readStructAtAddress(arrayOffset, renderCommandDefinition);
let boundingBox = renderCommand.boundingBox;
switch(renderCommand.commandType.value) {
// note: commandType is packed to uint8_t and has 3 garbage bytes of padding
switch(renderCommand.commandType.value & 0xff) {
case (CLAY_RENDER_COMMAND_TYPE_NONE): {
break;
}

View File

@ -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};

View File

@ -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;

View File

@ -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

View File

@ -317,7 +317,9 @@
for (let i = 0; i < length; i++, arrayOffset += renderCommandSize) {
let renderCommand = readStructAtAddress(arrayOffset, renderCommandDefinition);
let boundingBox = renderCommand.boundingBox;
switch(renderCommand.commandType.value) {
// note: commandType is packed to uint8_t and has 3 garbage bytes of padding
switch(renderCommand.commandType.value & 0xff) {
case (CLAY_RENDER_COMMAND_TYPE_NONE): {
break;
}

View File

@ -336,7 +336,7 @@
let element = null;
if (!elementCache[renderCommand.id.value]) {
let elementType = 'div';
switch (renderCommand.commandType.value) {
switch (renderCommand.commandType.value & 0xff) {
case CLAY_RENDER_COMMAND_TYPE_RECTANGLE: {
if (readStructAtAddress(renderCommand.config.value, rectangleConfigDefinition).link.length.value > 0) {
elementType = 'a';
@ -384,7 +384,8 @@
element.style.height = Math.round(renderCommand.boundingBox.height.value) + 'px';
}
switch(renderCommand.commandType.value) {
// note: commandType is packed to uint8_t and has 3 garbage bytes of padding
switch(renderCommand.commandType.value & 0xff) {
case (CLAY_RENDER_COMMAND_TYPE_NONE): {
break;
}