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

UIText: Check if the textWidth is 0 instead of if the string is empty #143

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/main/kotlin/gg/essential/elementa/components/UIText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,18 @@ constructor(
}

override fun draw(matrixStack: UMatrixStack) {
val text = textState.get()
if (text.isEmpty())
val textWidth = textWidthState.get()

// If you're wondering why we check if the text's width is 0 instead of if the string is empty:
// It's better to check the width derived from the font provider, as the string may just be full of characters
// that can't be rendered (as they aren't supported by current font).
// This check prevents issues from occurring later, e.g. when calculating the scale of the text.
if (textWidth == 0f)
return

beforeDrawCompat(matrixStack)

val scale = getWidth() / textWidthState.get()
val scale = getWidth() / textWidth
val x = getLeft()
val y = getTop() + (if (verticallyCenteredState.get()) fontProviderState.get().getBelowLineHeight() * scale else 0f)
val color = getColor()
Expand Down
Loading