Fix crash in EnumButtonTests due to attempted TextRenderer usage

This commit is contained in:
Shadowfacts 2019-06-27 19:32:35 -04:00
parent ed3d2d3621
commit d750339c07
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 6 additions and 3 deletions

View File

@ -6,7 +6,6 @@ import net.shadowfacts.cacao.geometry.Point
import net.shadowfacts.cacao.geometry.Size import net.shadowfacts.cacao.geometry.Size
import net.shadowfacts.cacao.util.Color import net.shadowfacts.cacao.util.Color
import net.shadowfacts.cacao.util.RenderHelper import net.shadowfacts.cacao.util.RenderHelper
import kotlin.math.roundToInt
/** /**
* A simple View that displays text. Allows for controlling the color and shadow of the text. Label cannot be used * A simple View that displays text. Allows for controlling the color and shadow of the text. Label cannot be used
@ -94,8 +93,7 @@ class Label(
var lines = text.split("\n") var lines = text.split("\n")
if (wrappingMode == WrappingMode.WRAP) { if (wrappingMode == WrappingMode.WRAP) {
lines = lines.flatMap { lines = lines.flatMap {
val maxWidth = bounds.width.toInt() wrapStringToWidthAsList(it, bounds.width)
textRenderer.wrapStringToWidthAsList(it, maxWidth)
} }
} }
if (0 < maxLines && maxLines < lines.size) { if (0 < maxLines && maxLines < lines.size) {
@ -104,4 +102,9 @@ class Label(
this.lines = lines this.lines = lines
} }
private fun wrapStringToWidthAsList(string: String, width: Double): List<String> {
if (RenderHelper.disabled) return listOf(string)
return textRenderer.wrapStringToWidthAsList(string, width.toInt())
}
} }