mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
fix crashes with text alignment
This commit is contained in:
parent
f2b0fab5d8
commit
f42fec6421
@ -12,6 +12,7 @@ import de.bixilon.minosoft.gui.rendering.font.renderer.element.TextRenderPropert
|
||||
import de.bixilon.minosoft.gui.rendering.font.types.dummy.DummyFontType
|
||||
import de.bixilon.minosoft.gui.rendering.font.types.font.EmptyFont
|
||||
import de.bixilon.minosoft.gui.rendering.gui.elements.HorizontalAlignments
|
||||
import de.bixilon.minosoft.gui.rendering.gui.mesh.DummyGUIVertexConsumer
|
||||
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2Util.MAX
|
||||
import org.testng.Assert.assertEquals
|
||||
@ -211,6 +212,16 @@ class ChatComponentRendererTest {
|
||||
)
|
||||
}
|
||||
|
||||
fun `no space y with consumer`() {
|
||||
val info = render(TextComponent("bcd\n\nefgh"), maxSize = Vec2(Float.MAX_VALUE, 10.0f), consumer = DummyGUIVertexConsumer())
|
||||
info.assert(
|
||||
lineIndex = 0,
|
||||
lines = listOf(),
|
||||
size = Vec2(0.0f, 0.0f),
|
||||
cutOff = true,
|
||||
)
|
||||
}
|
||||
|
||||
fun `no space`() {
|
||||
val info = render(TextComponent("bcd\n\nefgh"), maxSize = Vec2(0.0f, 0.0f))
|
||||
info.assert(
|
||||
|
@ -42,7 +42,7 @@ interface CodePointRenderer {
|
||||
|
||||
private fun getVerticalSpacing(offset: TextOffset, properties: TextRenderProperties, info: TextRenderInfo, align: Boolean): Float {
|
||||
var lineStart = offset.initial.x
|
||||
if (align) {
|
||||
if (align && info.lines.isNotEmpty()) {
|
||||
lineStart += properties.alignment.getOffset(info.size.x, info.lines[info.lineIndex].width)
|
||||
}
|
||||
if (offset.offset.x == lineStart) return 0.0f
|
||||
|
@ -68,7 +68,7 @@ object TextComponentRenderer : ChatComponentRenderer<TextComponent> {
|
||||
if (text.message.isEmpty()) return false
|
||||
|
||||
|
||||
if (consumer != null && info.lineIndex == 0 && offset.offset.x == offset.initial.x) {
|
||||
if (consumer != null && info.lineIndex == 0 && info.lines.isNotEmpty() && offset.offset.x == offset.initial.x) {
|
||||
// switched to consumer mode but offset was not updated yet
|
||||
offset.align(properties.alignment, info.lines.first().width, info.size)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user