Skip to content

Commit

Permalink
Fix a bug when a single word couldn't fit in its container
Browse files Browse the repository at this point in the history
  • Loading branch information
nicbarker committed Oct 22, 2024
1 parent 29ebbb2 commit 8355144
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions clay.h
Original file line number Diff line number Diff line change
Expand Up @@ -2180,8 +2180,13 @@ void Clay__CalculateFinalLayout() {
}
for (int wordIndex = 0; wordIndex < measureTextCacheItem->measuredWords.length; ++wordIndex) {
Clay__MeasuredWord *measuredWord = Clay__MeasuredWordArraySlice_Get(&measureTextCacheItem->measuredWords, wordIndex);
// Only word on the line is too large, just render it anyway
if (lineLengthChars == 0 && lineWidth + measuredWord->width > containerElement->dimensions.width) {
Clay__StringArray_Add(&Clay__wrappedTextLines, CLAY__INIT(Clay_String) {.length = measuredWord->length, .chars = &textElementData->text.chars[measuredWord->startOffset] });
textElementData->wrappedLines.length++;
}
// measuredWord->length == 0 means a newline character
if (measuredWord->length == 0 || lineWidth + measuredWord->width > containerElement->dimensions.width) {
else if (measuredWord->length == 0 || lineWidth + measuredWord->width > containerElement->dimensions.width) {
Clay__StringArray_Add(&Clay__wrappedTextLines, CLAY__INIT(Clay_String) {.length = (int)lineLengthChars, .chars = &textElementData->text.chars[lineStartOffset] });
textElementData->wrappedLines.length++;
if (lineLengthChars > 0 && measuredWord->length > 0) {
Expand Down Expand Up @@ -2458,7 +2463,7 @@ void Clay__CalculateFinalLayout() {
continue;
}
Clay_RenderCommandArray_Add(&Clay__renderCommands, CLAY__INIT(Clay_RenderCommand) {
.boundingBox = { currentElementBoundingBox.x, currentElementBoundingBox.y + yPosition, (float)50, naturalLineHeight }, // TODO width
.boundingBox = { currentElementBoundingBox.x, currentElementBoundingBox.y + yPosition, currentElement->dimensions.width, naturalLineHeight }, // TODO width
.config = configUnion,
.text = wrappedLine,
.id = Clay__HashNumber(lineIndex, currentElement->id).id,
Expand Down

0 comments on commit 8355144

Please sign in to comment.