mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-19 04:38:01 +00:00
[Core] Add z-index and string base to Render Commands
This commit is contained in:
parent
c0dac38c87
commit
948468ad86
10
clay.h
10
clay.h
@ -471,7 +471,8 @@ CLAY__TYPEDEF(Clay_RenderCommandType, CLAY_PACKED_ENUM {
|
|||||||
CLAY__TYPEDEF(Clay_RenderCommand, struct {
|
CLAY__TYPEDEF(Clay_RenderCommand, struct {
|
||||||
Clay_BoundingBox 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_StringSlice text; // TODO I wish there was a way to avoid having to have this on every render command
|
||||||
|
uint32_t zIndex;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
Clay_RenderCommandType commandType;
|
Clay_RenderCommandType commandType;
|
||||||
});
|
});
|
||||||
@ -2601,6 +2602,7 @@ void Clay__CalculateFinalLayout() {
|
|||||||
.boundingBox = clipHashMapItem->boundingBox,
|
.boundingBox = clipHashMapItem->boundingBox,
|
||||||
.config = { .scrollElementConfig = Clay__StoreScrollElementConfig(CLAY__INIT(Clay_ScrollElementConfig)CLAY__DEFAULT_STRUCT) },
|
.config = { .scrollElementConfig = Clay__StoreScrollElementConfig(CLAY__INIT(Clay_ScrollElementConfig)CLAY__DEFAULT_STRUCT) },
|
||||||
.id = Clay__RehashWithNumber(rootElement->id, 10), // TODO need a better strategy for managing derived ids
|
.id = Clay__RehashWithNumber(rootElement->id, 10), // TODO need a better strategy for managing derived ids
|
||||||
|
.zIndex = root->zIndex,
|
||||||
.commandType = CLAY_RENDER_COMMAND_TYPE_SCISSOR_START,
|
.commandType = CLAY_RENDER_COMMAND_TYPE_SCISSOR_START,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -2732,7 +2734,8 @@ void Clay__CalculateFinalLayout() {
|
|||||||
Clay__AddRenderCommand(CLAY__INIT(Clay_RenderCommand) {
|
Clay__AddRenderCommand(CLAY__INIT(Clay_RenderCommand) {
|
||||||
.boundingBox = { currentElementBoundingBox.x, currentElementBoundingBox.y + yPosition, wrappedLine.dimensions.width, wrappedLine.dimensions.height }, // TODO width
|
.boundingBox = { currentElementBoundingBox.x, currentElementBoundingBox.y + yPosition, wrappedLine.dimensions.width, wrappedLine.dimensions.height }, // TODO width
|
||||||
.config = configUnion,
|
.config = configUnion,
|
||||||
.text = wrappedLine.line,
|
.text = CLAY__INIT(Clay_StringSlice) { .length = wrappedLine.line.length, .chars = wrappedLine.line.chars, .baseChars = currentElement->childrenOrTextContent.textElementData->text.chars },
|
||||||
|
.zIndex = root->zIndex,
|
||||||
.id = Clay__HashNumber(lineIndex, currentElement->id).id,
|
.id = Clay__HashNumber(lineIndex, currentElement->id).id,
|
||||||
.commandType = CLAY_RENDER_COMMAND_TYPE_TEXT,
|
.commandType = CLAY_RENDER_COMMAND_TYPE_TEXT,
|
||||||
});
|
});
|
||||||
@ -3945,7 +3948,8 @@ Clay_RenderCommandArray Clay_EndLayout() {
|
|||||||
context->warningsEnabled = true;
|
context->warningsEnabled = true;
|
||||||
}
|
}
|
||||||
if (context->booleanWarnings.maxElementsExceeded) {
|
if (context->booleanWarnings.maxElementsExceeded) {
|
||||||
Clay__AddRenderCommand(CLAY__INIT(Clay_RenderCommand ) { .boundingBox = { context->layoutDimensions.width / 2 - 59 * 4, context->layoutDimensions.height / 2, 0, 0 }, .config = { .textElementConfig = &Clay__DebugView_ErrorTextConfig }, .text = CLAY_STRING("Clay Error: Layout elements exceeded Clay__maxElementCount"), .commandType = CLAY_RENDER_COMMAND_TYPE_TEXT });
|
Clay_String message = CLAY_STRING("Clay Error: Layout elements exceeded Clay__maxElementCount");
|
||||||
|
Clay__AddRenderCommand(CLAY__INIT(Clay_RenderCommand ) { .boundingBox = { context->layoutDimensions.width / 2 - 59 * 4, context->layoutDimensions.height / 2, 0, 0 }, .config = { .textElementConfig = &Clay__DebugView_ErrorTextConfig }, .text = CLAY__INIT(Clay_StringSlice) { .length = message.length, .chars = message.chars, .baseChars = message.chars }, .commandType = CLAY_RENDER_COMMAND_TYPE_TEXT });
|
||||||
} else {
|
} else {
|
||||||
Clay__CalculateFinalLayout();
|
Clay__CalculateFinalLayout();
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ target_link_libraries(clay_examples_raylib_sidebar_scrolling_container PUBLIC ra
|
|||||||
if(MSVC)
|
if(MSVC)
|
||||||
set(CMAKE_C_FLAGS_DEBUG "/D CLAY_DEBUG")
|
set(CMAKE_C_FLAGS_DEBUG "/D CLAY_DEBUG")
|
||||||
else()
|
else()
|
||||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Werror -DCLAY_DEBUG -fsanitize=address")
|
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DCLAY_DEBUG -fsanitize=address")
|
||||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ static void Clay_SDL2_Render(SDL_Renderer *renderer, Clay_RenderCommandArray ren
|
|||||||
}
|
}
|
||||||
case CLAY_RENDER_COMMAND_TYPE_TEXT: {
|
case CLAY_RENDER_COMMAND_TYPE_TEXT: {
|
||||||
Clay_TextElementConfig *config = renderCommand->config.textElementConfig;
|
Clay_TextElementConfig *config = renderCommand->config.textElementConfig;
|
||||||
Clay_String text = renderCommand->text;
|
Clay_StringSlice text = renderCommand->text;
|
||||||
char *cloned = (char *)calloc(text.length + 1, 1);
|
char *cloned = (char *)calloc(text.length + 1, 1);
|
||||||
memcpy(cloned, text.chars, text.length);
|
memcpy(cloned, text.chars, text.length);
|
||||||
TTF_Font* font = fonts[config->fontId].font;
|
TTF_Font* font = fonts[config->fontId].font;
|
||||||
|
@ -158,7 +158,7 @@ static void SDL_RenderClayCommands(SDL_Renderer *renderer, Clay_RenderCommandArr
|
|||||||
} break;
|
} break;
|
||||||
case CLAY_RENDER_COMMAND_TYPE_TEXT: {
|
case CLAY_RENDER_COMMAND_TYPE_TEXT: {
|
||||||
const Clay_TextElementConfig *config = rcmd->config.textElementConfig;
|
const Clay_TextElementConfig *config = rcmd->config.textElementConfig;
|
||||||
const Clay_String *text = &rcmd->text;
|
const Clay_StringSlice *text = &rcmd->text;
|
||||||
const SDL_Color color = { config->textColor.r, config->textColor.g, config->textColor.b, config->textColor.a };
|
const SDL_Color color = { config->textColor.r, config->textColor.g, config->textColor.b, config->textColor.a };
|
||||||
|
|
||||||
TTF_Font *font = gFonts[config->fontId];
|
TTF_Font *font = gFonts[config->fontId];
|
||||||
|
@ -138,7 +138,7 @@ void Clay_Raylib_Render(Clay_RenderCommandArray renderCommands)
|
|||||||
{
|
{
|
||||||
case CLAY_RENDER_COMMAND_TYPE_TEXT: {
|
case CLAY_RENDER_COMMAND_TYPE_TEXT: {
|
||||||
// Raylib uses standard C strings so isn't compatible with cheap slices, we need to clone the string to append null terminator
|
// Raylib uses standard C strings so isn't compatible with cheap slices, we need to clone the string to append null terminator
|
||||||
Clay_String text = renderCommand->text;
|
Clay_StringSlice text = renderCommand->text;
|
||||||
char *cloned = (char *)malloc(text.length + 1);
|
char *cloned = (char *)malloc(text.length + 1);
|
||||||
memcpy(cloned, text.chars, text.length);
|
memcpy(cloned, text.chars, text.length);
|
||||||
cloned[text.length] = '\0';
|
cloned[text.length] = '\0';
|
||||||
|
Loading…
Reference in New Issue
Block a user