mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 09:56:37 -04:00
text renderer: fix crash when text starts with newline + tests
This commit is contained in:
parent
60cda1237e
commit
51d4a31e6c
@ -444,5 +444,25 @@ class ChatComponentRendererTest {
|
||||
)
|
||||
}
|
||||
|
||||
fun `first line blank`() {
|
||||
val text = TextComponent("\nbcd")
|
||||
|
||||
val info = render(text)
|
||||
info.assert(lineIndex = 1, size = Vec2(5.0f, 22.0f), lines = listOf(
|
||||
LineRenderInfo(BaseComponent(), 0.0f),
|
||||
LineRenderInfo(BaseComponent(TextComponent("bcd")), 5.0f),
|
||||
))
|
||||
}
|
||||
|
||||
fun `first component blank`() {
|
||||
val text = BaseComponent(TextComponent("\n"), TextComponent("bcd"))
|
||||
|
||||
val info = render(text)
|
||||
info.assert(lineIndex = 1, size = Vec2(5.0f, 22.0f), lines = listOf(
|
||||
LineRenderInfo(BaseComponent(), 0.0f),
|
||||
LineRenderInfo(BaseComponent(TextComponent("bcd")), 5.0f),
|
||||
))
|
||||
}
|
||||
|
||||
// TODO: shadow, formatting (just basic, that is code point renderer's job)
|
||||
}
|
||||
|
@ -30,11 +30,11 @@ class TextRenderInfo(
|
||||
size.x = maxOf(offset.offset.x - offset.initial.x + width, size.x)
|
||||
|
||||
val line: LineRenderInfo
|
||||
if (lineIndex == 0 && lines.isEmpty()) {
|
||||
if ((lineIndex == 0 && lines.isEmpty()) || lineIndex >= lines.size) {
|
||||
// first char of all lines
|
||||
line = LineRenderInfo()
|
||||
lines += line
|
||||
size.y = properties.lineHeight
|
||||
size.y += properties.lineHeight
|
||||
} else {
|
||||
line = lines[lineIndex]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user