diff --git a/src/main/kotlin/net/shadowfacts/cacao/view/Label.kt b/src/main/kotlin/net/shadowfacts/cacao/view/Label.kt index a6e6bc0..02e9aef 100644 --- a/src/main/kotlin/net/shadowfacts/cacao/view/Label.kt +++ b/src/main/kotlin/net/shadowfacts/cacao/view/Label.kt @@ -80,11 +80,12 @@ class Label( updateIntrinsicContentSize(false) } - private fun updateIntrinsicContentSize(canWrap: Boolean): Boolean { + private fun updateIntrinsicContentSize(canWrap: Boolean, isFromDidLayout: Boolean = false): Boolean { if (RenderHelper.disabled) return false val oldSize = intrinsicContentSize - if (wrappingMode == WrappingMode.WRAP && canWrap && hasSolver) { + // don't wrap until we've laid out without wrapping to ensure the current bounds reflect the maximum available space + if (wrappingMode == WrappingMode.WRAP && canWrap && hasSolver && isFromDidLayout) { val lines = textRenderer.wrapLines(text, bounds.width.toInt()) val height = (if (maxLines == 0) lines.size else min(lines.size, maxLines)) * textRenderer.fontHeight intrinsicContentSize = Size(bounds.width, height.toDouble()) @@ -120,7 +121,7 @@ class Label( super.didLayout() computeLines() - if (updateIntrinsicContentSize(true)) { + if (updateIntrinsicContentSize(true, true)) { // if the intrinsic content size changes, relayout window!!.layout() }