Make DynamicLabel update text before resizing
This commit is contained in:
parent
06e2a97cfc
commit
ab68f8d36d
@ -22,4 +22,13 @@ open class DynamicLabel<out S : Screen>(
|
|||||||
super.tickInner()
|
super.tickInner()
|
||||||
text = textSupplier.get()
|
text = textSupplier.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reserve some extra space for text
|
||||||
|
override val textSizeDeterminationPadding: Float
|
||||||
|
get() = 14f
|
||||||
|
|
||||||
|
override fun sizeToContents() {
|
||||||
|
text = textSupplier.get()
|
||||||
|
super.sizeToContents()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,11 +60,14 @@ open class Label<out S : Screen>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected open val textSizeDeterminationPadding: Float
|
||||||
|
get() = 0f
|
||||||
|
|
||||||
override fun sizeToContents() {
|
override fun sizeToContents() {
|
||||||
val w = font.width(text)
|
val w = font.width(text) + textSizeDeterminationPadding
|
||||||
val h = font.lineHeight + 2
|
val h = font.lineHeight + 2
|
||||||
|
|
||||||
width = width.coerceAtLeast(w.toFloat())
|
width = width.coerceAtLeast(w)
|
||||||
height = height.coerceAtLeast(h.toFloat())
|
height = height.coerceAtLeast(h.toFloat())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user