Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] CLAY_TEXT not rendering lines that contain single characters #188

Closed
Ryzee119 opened this issue Jan 12, 2025 · 11 comments
Closed

[Core] CLAY_TEXT not rendering lines that contain single characters #188

Ryzee119 opened this issue Jan 12, 2025 · 11 comments

Comments

@Ryzee119
Copy link
Contributor

Ryzee119 commented Jan 12, 2025

Clay_LayoutConfig layoutElement1 = {.padding = {4}, .sizing = {.height = CLAY_SIZING_FIT(), .width = CLAY_SIZING_FIT()}};
Clay_TextElementConfig textElement = {.fontId = FONT_ID_BODY_24, .textColor = {255, 255, 255, 255}, .fontSize = 64};
CLAY(CLAY_LAYOUT(layoutElement1)) {
    CLAY_TEXT(CLAY_STRING("Hello\nWorld\nI\nCode\n"), CLAY_TEXT_CONFIG(textElement));
}

Seems somehow related to fontSize and how it scales?
Im using the raylib rendering backend

image

however changing to fontSize = 32 (for example) appears to fix it

image

@nicbarker
Copy link
Owner

Hello 👋
I think it's possible that you've got the syntax slightly confused, CLAY_TEXT is a child element and should go inside the braces, like this:

Clay_TextElementConfig textElement = {.fontId = FONT_ID_BODY_24, .textColor = {255, 255, 255, 255}, .fontSize = 64};
CLAY(CLAY_LAYOUT(layoutElement1)) {
    CLAY_TEXT(CLAY_STRING("Hello\nWorld\nI\nCode\n"), CLAY_TEXT_CONFIG(textElement));
}

@Ryzee119
Copy link
Contributor Author

Ryzee119 commented Jan 12, 2025

Thanks, still wrapping my head around the syntax, problems still occurs however. I updated the issue description with the correct syntax

@nicbarker
Copy link
Owner

@Ryzee119 that's totally fine! The syntax is a little odd at the moment for sure, we have plans to improve it 🙂

@nicbarker
Copy link
Owner

Is it alright if I close this issue?

@Ryzee119
Copy link
Contributor Author

Is it alright if I close this issue?

You can, but the issue is still present with the correct syntax too

@Ryzee119
Copy link
Contributor Author

Ryzee119 commented Jan 13, 2025

clay/clay.h

Line 1707 in 208c7cb

if (length > 1) {

Changing this to >= 1 fixes the issue. Im fairly sure this is how it should be.

I think it appears to work on some scales due to another quirk/bug in the string slices. At some font scaling CLAY_RENDER_COMMAND_TYPE_TEXT is (correctly?) receiving strings broken up by spaces and new lines, however other times it just sends to entire string in one block. This was hiding the bug.

@nicbarker
Copy link
Owner

@Ryzee119 very nice work finding it!

@nicbarker
Copy link
Owner

That bug you've described certainly looks very suspicious though, I will dig into the issues at different font sizes.

@Ryzee119
Copy link
Contributor Author

That bug you've described certainly looks very suspicious though, I will dig into the issues at different font sizes.

Ive found this issue. If a line that contains new line characters is shorter than the container size it just pushes it to the render without parsing the new lines. This is bailing too early. Ill raise a new issue

clay/clay.h

Lines 2370 to 2374 in 208c7cb

if (textElementData->preferredDimensions.width <= containerElement->dimensions.width) {
Clay__WrappedTextLineArray_Add(&context->wrappedTextLines, CLAY__INIT(Clay__WrappedTextLine) { containerElement->dimensions, textElementData->text });
textElementData->wrappedLines.length++;
continue;
}

@nicbarker
Copy link
Owner

Yep I've found it too, already fixing it 😁

@nicbarker
Copy link
Owner

Tentative fix is here: #192

@nicbarker nicbarker changed the title CLAY_TEXT not rendering lines that contain single characters [Core] CLAY_TEXT not rendering lines that contain single characters Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants