From 89e91796a5622e29103c5dc9bca8b41350e5da39 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 6 Mar 2021 15:53:25 -0500 Subject: [PATCH] Fix not being able to open Redstone Emitter GUI --- .../net/shadowfacts/cacao/view/Label.kt | 2 +- .../kotlin/net/shadowfacts/cacao/view/View.kt | 20 +++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/net/shadowfacts/cacao/view/Label.kt b/src/main/kotlin/net/shadowfacts/cacao/view/Label.kt index f76bc3f..a6e6bc0 100644 --- a/src/main/kotlin/net/shadowfacts/cacao/view/Label.kt +++ b/src/main/kotlin/net/shadowfacts/cacao/view/Label.kt @@ -84,7 +84,7 @@ class Label( if (RenderHelper.disabled) return false val oldSize = intrinsicContentSize - if (wrappingMode == WrappingMode.WRAP && canWrap) { + if (wrappingMode == WrappingMode.WRAP && canWrap && hasSolver) { 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()) diff --git a/src/main/kotlin/net/shadowfacts/cacao/view/View.kt b/src/main/kotlin/net/shadowfacts/cacao/view/View.kt index 68c690c..8db74f9 100644 --- a/src/main/kotlin/net/shadowfacts/cacao/view/View.kt +++ b/src/main/kotlin/net/shadowfacts/cacao/view/View.kt @@ -48,6 +48,9 @@ open class View(): Responder { */ var solver: Solver by solverDelegate + val hasSolver: Boolean + get() = solverDelegate.isInitialized + /** * Layout anchor for the left edge of this view in the window's coordinate system. */ @@ -92,17 +95,22 @@ open class View(): Responder { /** * The rectangle for this view in the coordinate system of its superview view (or the window, if there is no superview). - * If using constraint based layout, this property is not initialized until [didLayout] called. + * If using constraint based layout, this property has zero dimensions until [didLayout] called. * Otherwise, this must be set manually. * Setting this property updates the [bounds]. */ - var frame: Rect by ObservableLateInitProperty { this.bounds = Rect(Point.ORIGIN, it.size) } + var frame = Rect(0.0, 0.0, 0.0, 0.0) + set(value) { + field = value + bounds = Rect(Point.ORIGIN, value.size) + } + /** * The rectangle for this view in its own coordinate system. - * If using constraint based layout, this property is not initialized until [didLayout] called. + * If using constraint based layout, this property has zero dimensions until [didLayout] called. * Otherwise, this will be initialized when [frame] is set. */ - lateinit var bounds: Rect + var bounds = Rect(0.0, 0.0, 0.0, 0.0) /** * The position on the Z-axis of this view. @@ -182,7 +190,7 @@ open class View(): Responder { subviewsSortedByZIndex = subviews.sortedBy(View::zIndex) view.superview = this - if (solverDelegate.isInitialized) { + if (hasSolver) { view.solver = solver } view.window = window @@ -293,7 +301,7 @@ open class View(): Responder { } private fun updateIntrinsicContentSizeConstraints(old: Size?, new: Size?) { - if (!usesConstraintBasedLayout || !solverDelegate.isInitialized) return + if (!usesConstraintBasedLayout || !hasSolver) return if (old != null) { solver.removeConstraint(intrinsicContentSizeWidthConstraint!!)