Make DynamicLabel update text before resizing

This commit is contained in:
DBotThePony 2025-02-25 12:04:39 +07:00
parent 06e2a97cfc
commit ab68f8d36d
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 14 additions and 2 deletions

View File

@ -22,4 +22,13 @@ open class DynamicLabel<out S : Screen>(
super.tickInner()
text = textSupplier.get()
}
// reserve some extra space for text
override val textSizeDeterminationPadding: Float
get() = 14f
override fun sizeToContents() {
text = textSupplier.get()
super.sizeToContents()
}
}

View File

@ -60,11 +60,14 @@ open class Label<out S : Screen>(
}
}
protected open val textSizeDeterminationPadding: Float
get() = 0f
override fun sizeToContents() {
val w = font.width(text)
val w = font.width(text) + textSizeDeterminationPadding
val h = font.lineHeight + 2
width = width.coerceAtLeast(w.toFloat())
width = width.coerceAtLeast(w)
height = height.coerceAtLeast(h.toFloat())
}
}