mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-23 22:58:06 +00:00
Compare commits
8 Commits
fe1785e1b1
...
e825d44b57
Author | SHA1 | Date | |
---|---|---|---|
|
e825d44b57 | ||
|
982ade4cf9 | ||
|
d5af2c3dc0 | ||
|
2677bec854 | ||
|
05ac2810d8 | ||
|
1f8cab8d72 | ||
|
6186596b41 | ||
|
fbf8251996 |
23
clay.h
23
clay.h
@ -102,6 +102,10 @@
|
|||||||
|
|
||||||
static uint8_t CLAY__ELEMENT_DEFINITION_LATCH;
|
static uint8_t CLAY__ELEMENT_DEFINITION_LATCH;
|
||||||
|
|
||||||
|
// GCC marks the above CLAY__ELEMENT_DEFINITION_LATCH as an unused variable for files that include clay.h but don't declare any layout
|
||||||
|
// This is to suppress that warning
|
||||||
|
static inline void Clay__SuppressUnusedLatchDefinitionVariableWarning(void) { (void) CLAY__ELEMENT_DEFINITION_LATCH; }
|
||||||
|
|
||||||
// Publicly visible layout element macros -----------------------------------------------------
|
// Publicly visible layout element macros -----------------------------------------------------
|
||||||
|
|
||||||
/* This macro looks scary on the surface, but is actually quite simple.
|
/* This macro looks scary on the surface, but is actually quite simple.
|
||||||
@ -353,6 +357,8 @@ typedef CLAY_PACKED_ENUM {
|
|||||||
CLAY_TEXT_ALIGN_CENTER,
|
CLAY_TEXT_ALIGN_CENTER,
|
||||||
// Horizontally aligns wrapped lines of text to the right hand side of their bounding box.
|
// Horizontally aligns wrapped lines of text to the right hand side of their bounding box.
|
||||||
CLAY_TEXT_ALIGN_RIGHT,
|
CLAY_TEXT_ALIGN_RIGHT,
|
||||||
|
// The boundingBox passed to the TEXT render command may be smaller than the measured text size. The renderer must then decide how to shorten the text to make it fit
|
||||||
|
CLAY_TEXT_ALIGN_SHRINK,
|
||||||
} Clay_TextAlignment;
|
} Clay_TextAlignment;
|
||||||
|
|
||||||
// Controls various functionality related to text elements.
|
// Controls various functionality related to text elements.
|
||||||
@ -1654,6 +1660,8 @@ void Clay__CloseElement(void) {
|
|||||||
elementHasScrollVertical = config->config.scrollElementConfig->vertical;
|
elementHasScrollVertical = config->config.scrollElementConfig->vertical;
|
||||||
context->openClipElementStack.length--;
|
context->openClipElementStack.length--;
|
||||||
break;
|
break;
|
||||||
|
} else if (config->type == CLAY__ELEMENT_CONFIG_TYPE_FLOATING) {
|
||||||
|
context->openClipElementStack.length--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1933,6 +1941,9 @@ void Clay__ConfigureOpenElementPtr(const Clay_ElementDeclaration *declaration) {
|
|||||||
if (!openLayoutElementId.id) {
|
if (!openLayoutElementId.id) {
|
||||||
openLayoutElementId = Clay__HashString(CLAY_STRING("Clay__FloatingContainer"), context->layoutElementTreeRoots.length, 0);
|
openLayoutElementId = Clay__HashString(CLAY_STRING("Clay__FloatingContainer"), context->layoutElementTreeRoots.length, 0);
|
||||||
}
|
}
|
||||||
|
int32_t currentElementIndex = Clay__int32_tArray_GetValue(&context->openLayoutElementStack, context->openLayoutElementStack.length - 1);
|
||||||
|
Clay__int32_tArray_Set(&context->layoutElementClipElementIds, currentElementIndex, clipElementId);
|
||||||
|
Clay__int32_tArray_Add(&context->openClipElementStack, clipElementId);
|
||||||
Clay__LayoutElementTreeRootArray_Add(&context->layoutElementTreeRoots, CLAY__INIT(Clay__LayoutElementTreeRoot) {
|
Clay__LayoutElementTreeRootArray_Add(&context->layoutElementTreeRoots, CLAY__INIT(Clay__LayoutElementTreeRoot) {
|
||||||
.layoutElementIndex = Clay__int32_tArray_GetValue(&context->openLayoutElementStack, context->openLayoutElementStack.length - 1),
|
.layoutElementIndex = Clay__int32_tArray_GetValue(&context->openLayoutElementStack, context->openLayoutElementStack.length - 1),
|
||||||
.parentId = floatingConfig.parentId,
|
.parentId = floatingConfig.parentId,
|
||||||
@ -2683,14 +2694,24 @@ void Clay__CalculateFinalLayout(void) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
float offset = (currentElementBoundingBox.width - wrappedLine->dimensions.width);
|
float offset = (currentElementBoundingBox.width - wrappedLine->dimensions.width);
|
||||||
if (textElementConfig->textAlignment == CLAY_TEXT_ALIGN_LEFT) {
|
if (textElementConfig->textAlignment == CLAY_TEXT_ALIGN_LEFT || textElementConfig->textAlignment == CLAY_TEXT_ALIGN_SHRINK) {
|
||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
if (textElementConfig->textAlignment == CLAY_TEXT_ALIGN_CENTER) {
|
if (textElementConfig->textAlignment == CLAY_TEXT_ALIGN_CENTER) {
|
||||||
offset /= 2;
|
offset /= 2;
|
||||||
}
|
}
|
||||||
|
Clay_BoundingBox textBoundingBox = {
|
||||||
|
currentElementBoundingBox.x + offset,
|
||||||
|
currentElementBoundingBox.y + yPosition,
|
||||||
|
wrappedLine->dimensions.width,
|
||||||
|
wrappedLine->dimensions.height
|
||||||
|
};
|
||||||
|
if (textElementConfig->textAlignment == CLAY_TEXT_ALIGN_SHRINK && boundingBox.width > currentElementBoundingBox.width) {
|
||||||
|
boundingBox.width = currentElementBoundingBox.width;
|
||||||
|
}
|
||||||
Clay__AddRenderCommand(CLAY__INIT(Clay_RenderCommand) {
|
Clay__AddRenderCommand(CLAY__INIT(Clay_RenderCommand) {
|
||||||
.boundingBox = { currentElementBoundingBox.x + offset, currentElementBoundingBox.y + yPosition, wrappedLine->dimensions.width, wrappedLine->dimensions.height },
|
.boundingBox = { currentElementBoundingBox.x + offset, currentElementBoundingBox.y + yPosition, wrappedLine->dimensions.width, wrappedLine->dimensions.height },
|
||||||
|
.boundingBox = textBoundingBox,
|
||||||
.renderData = { .text = {
|
.renderData = { .text = {
|
||||||
.stringContents = CLAY__INIT(Clay_StringSlice) { .length = wrappedLine->line.length, .chars = wrappedLine->line.chars, .baseChars = currentElement->childrenOrTextContent.textElementData->text.chars },
|
.stringContents = CLAY__INIT(Clay_StringSlice) { .length = wrappedLine->line.length, .chars = wrappedLine->line.chars, .baseChars = currentElement->childrenOrTextContent.textElementData->text.chars },
|
||||||
.textColor = textElementConfig->textColor,
|
.textColor = textElementConfig->textColor,
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <SDL_ttf.h>
|
#include <SDL_ttf.h>
|
||||||
#include <SDL_image.h>
|
#include <SDL_image.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#ifndef M_PI
|
#ifndef M_PI
|
||||||
#define M_PI 3.14159
|
#define M_PI 3.14159
|
||||||
|
Loading…
Reference in New Issue
Block a user