hud: fix some text component crashes

This commit is contained in:
Bixilon 2021-10-15 23:04:34 +02:00
parent 805a1e1cde
commit 1330911287
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 20 additions and 7 deletions

View File

@ -13,10 +13,23 @@
package de.bixilon.minosoft.gui.rendering.font.renderer package de.bixilon.minosoft.gui.rendering.font.renderer
import de.bixilon.minosoft.config.StaticConfiguration
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
class TextRenderInfo( class TextRenderInfo(
val lines: MutableList<TextLineInfo> = mutableListOf(), val lines: MutableList<TextLineInfo> = mutableListOf(),
var currentLineNumber: Int = 0, var currentLineNumber: Int = 0,
) { ) {
val currentLine: TextLineInfo val currentLine: TextLineInfo
get() = lines[currentLineNumber] get() {
if (StaticConfiguration.DEBUG_MODE) {
if (currentLineNumber >= lines.size) {
Log.log(LogMessageType.RENDERING_GENERAL, LogLevels.WARN) { "Out of lines! Did you apply?: $lines ($currentLineNumber)" }
return TextLineInfo()
}
}
return lines[currentLineNumber]
}
} }

View File

@ -18,6 +18,7 @@ import de.bixilon.minosoft.gui.rendering.gui.hud.HUDRenderer
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIMeshCache import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIMeshCache
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer
import de.bixilon.minosoft.gui.rendering.util.vec.Vec2Util.EMPTY import de.bixilon.minosoft.gui.rendering.util.vec.Vec2Util.EMPTY
import de.bixilon.minosoft.gui.rendering.util.vec.Vec2Util.isGreater
import de.bixilon.minosoft.gui.rendering.util.vec.Vec2Util.isSmaller import de.bixilon.minosoft.gui.rendering.util.vec.Vec2Util.isSmaller
import de.bixilon.minosoft.gui.rendering.util.vec.Vec2Util.max import de.bixilon.minosoft.gui.rendering.util.vec.Vec2Util.max
import de.bixilon.minosoft.gui.rendering.util.vec.Vec2Util.min import de.bixilon.minosoft.gui.rendering.util.vec.Vec2Util.min
@ -173,12 +174,12 @@ abstract class Element(val hudRenderer: HUDRenderer) {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
open fun silentApply(): Boolean { open fun silentApply(): Boolean {
val maxSize = maxSize val maxSize = maxSize
if (previousMaxSize != maxSize && (maxSize isSmaller size || maxSize isSmaller prefMaxSize)) { if (previousMaxSize != maxSize && (maxSize isSmaller _size || maxSize isSmaller _prefMaxSize || (maxSize isGreater previousMaxSize && _size isSmaller _prefSize))) {
forceSilentApply() forceSilentApply()
previousMaxSize = maxSize previousMaxSize = maxSize
return true return true
} }
return true return false
} }
/** /**

View File

@ -167,7 +167,7 @@ open class RowLayout(
} }
} }
this.size = size _size = size
} }

View File

@ -155,7 +155,6 @@ class GridLayout(hudRenderer: HUDRenderer, val grid: Vec2i) : Element(hudRendere
override fun silentApply(): Boolean { override fun silentApply(): Boolean {
// ToDo: Check // ToDo: Check
forceSilentApply() forceSilentApply()
applyOnlyChildren()
return true return true
} }

View File

@ -79,7 +79,7 @@ open class TextElement(
this.previousMaxSize = maxSize this.previousMaxSize = maxSize
this.cacheUpToDate = false this.cacheUpToDate = false
this.size = size _size = size
} }
override fun onChildChange(child: Element?) = error("A TextElement can not have a child!") override fun onChildChange(child: Element?) = error("A TextElement can not have a child!")

View File

@ -108,7 +108,7 @@ class TextFlowElement(
this.textSize = textSize this.textSize = textSize
size = Vec2i(maxSize.x, visibleLines.size * Font.TOTAL_CHAR_HEIGHT) _size = Vec2i(maxSize.x, visibleLines.size * Font.TOTAL_CHAR_HEIGHT)
background.size = size background.size = size
this.visibleLines = visibleLines this.visibleLines = visibleLines
} }