mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 19:35:00 -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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pushLine() {
|
fun pushLine(index: Int = -1) {
|
||||||
if (consumer != null || currentLineText.isEmpty()) {
|
var pushText: String = currentLineText
|
||||||
|
if (index > 0) {
|
||||||
|
pushText = currentLineText.substring(0, index)
|
||||||
|
}
|
||||||
|
if (consumer != null || pushText.isEmpty()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
renderInfo.currentLine.text += text.copy(message = currentLineText)
|
renderInfo.currentLine.text += text.copy(message = pushText)
|
||||||
currentLineText = ""
|
currentLineText = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,11 +128,11 @@ object TextComponentRenderer : ChatComponentRenderer<TextComponent> {
|
|||||||
}
|
}
|
||||||
applyOffset()
|
applyOffset()
|
||||||
|
|
||||||
|
for ((index, charCode) in text.message.codePoints().toArray().withIndex()) {
|
||||||
for (charCode in text.message.codePoints().toArray()) {
|
|
||||||
val char = charCode.toChar()
|
val char = charCode.toChar()
|
||||||
if (char == '\n') {
|
if (char == '\n') {
|
||||||
if (wrap()) {
|
if (wrap()) {
|
||||||
|
pushLine(index)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
@ -157,6 +161,7 @@ object TextComponentRenderer : ChatComponentRenderer<TextComponent> {
|
|||||||
val previousY = offset.y
|
val previousY = offset.y
|
||||||
|
|
||||||
if (addX(width)) {
|
if (addX(width)) {
|
||||||
|
pushLine(index)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,9 +219,14 @@ open class TextElement(
|
|||||||
textElement._prefMaxSize = Vec2i(offset.x, charHeight)
|
textElement._prefMaxSize = Vec2i(offset.x, charHeight)
|
||||||
textElement.forceSilentApply()
|
textElement.forceSilentApply()
|
||||||
|
|
||||||
|
|
||||||
offset.x += fontAlignment.getOffset(size.x, line.width)
|
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 {
|
override fun toString(): String {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user