Compare commits

...

3 Commits

Author SHA1 Message Date
Piggybank Studios
1349abbb1d
Merge fbf8251996 into 19a27b39f2 2025-03-08 19:05:39 -08:00
Daniel Collin
19a27b39f2
[Compilers] Fixed SIMD related compile error on some ARM compilers (#316)
Some checks are pending
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) Waiting to run
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Waiting to run
2025-03-09 10:28:09 +13:00
Taylor Robbins (Piggybank Studios)
fbf8251996 Adds CLAY_TEXT_ALIGN_SHRINK option to Clay_TextAlignment which tells the TEXT command producing code it is allowed to pass a boundingBox that is horizontally smaller than the result of the MeasureText call for that string. The Renderer is then able to choose how it wants to fit a piece of text in a smaller space (often this involves removing some number of characters and replacing them with "..." characters) 2025-03-05 13:04:57 -08:00

16
clay.h
View File

@ -353,6 +353,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.
@ -1771,7 +1773,7 @@ bool Clay__MemCmp(const char *s1, const char *s2, int32_t length);
uint8x16_t v2 = vld1q_u8((const uint8_t *)s2); uint8x16_t v2 = vld1q_u8((const uint8_t *)s2);
// Compare vectors // Compare vectors
if (vminvq_u32(vceqq_u8(v1, v2)) != 0xFFFFFFFF) { // If there's a difference if (vminvq_u32(vreinterpretq_u32_u8(vceqq_u8(v1, v2))) != 0xFFFFFFFF) { // If there's a difference
return false; return false;
} }
@ -2678,14 +2680,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,