mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 02:45:13 -04:00
text renderer: fix text in line when line cut off
This commit is contained in:
parent
870a691c7e
commit
f9536f7f32
@ -48,11 +48,15 @@ object TextComponentRenderer : ChatComponentRenderer<TextComponent> {
|
||||
return true
|
||||
}
|
||||
|
||||
fun pushLine() {
|
||||
if (consumer != null || currentLineText.isEmpty()) {
|
||||
fun pushLine(index: Int = -1) {
|
||||
var pushText: String = currentLineText
|
||||
if (index > 0) {
|
||||
pushText = currentLineText.substring(0, index)
|
||||
}
|
||||
if (consumer != null || pushText.isEmpty()) {
|
||||
return
|
||||
}
|
||||
renderInfo.currentLine.text += text.copy(message = currentLineText)
|
||||
renderInfo.currentLine.text += text.copy(message = pushText)
|
||||
currentLineText = ""
|
||||
}
|
||||
|
||||
@ -124,11 +128,11 @@ object TextComponentRenderer : ChatComponentRenderer<TextComponent> {
|
||||
}
|
||||
applyOffset()
|
||||
|
||||
|
||||
for (charCode in text.message.codePoints().toArray()) {
|
||||
for ((index, charCode) in text.message.codePoints().toArray().withIndex()) {
|
||||
val char = charCode.toChar()
|
||||
if (char == '\n') {
|
||||
if (wrap()) {
|
||||
pushLine(index)
|
||||
return true
|
||||
}
|
||||
continue
|
||||
@ -157,6 +161,7 @@ object TextComponentRenderer : ChatComponentRenderer<TextComponent> {
|
||||
val previousY = offset.y
|
||||
|
||||
if (addX(width)) {
|
||||
pushLine(index)
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -219,9 +219,14 @@ open class TextElement(
|
||||
textElement._prefMaxSize = Vec2i(offset.x, charHeight)
|
||||
textElement.forceSilentApply()
|
||||
|
||||
|
||||
offset.x += fontAlignment.getOffset(size.x, line.width)
|
||||
|
||||
return Pair(line.text.getTextAt(textElement.renderInfo.lines.getOrNull(0)?.text?.message?.length ?: return null), offset)
|
||||
val line0 = textElement.renderInfo.lines.getOrNull(0) ?: return null
|
||||
val text = line.text.getTextAt(line0.text.message.length)
|
||||
offset.x -= line0.width // ToDo: Not 100% correct
|
||||
|
||||
return Pair(text, offset)
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
|
Loading…
x
Reference in New Issue
Block a user