remove TextElement init workaround, call construct after initializing

This commit is contained in:
Bixilon 2023-07-24 16:18:27 +02:00
parent 93e0876322
commit 14662b4c7f
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 11 additions and 6 deletions

View File

@ -47,4 +47,6 @@ class FadingTextElementTest {
assertFalse(element.update)
element.assetSize(Vec2(5.0f, 11.0f))
}
// TODO: rendering (alpha), show, force hide, empty again
}

View File

@ -140,4 +140,9 @@ abstract class Element(val guiRenderer: GUIRenderer, initialCacheSize: Int = 100
protected inline fun <T> KProperty0<T>.delegate(): GuiDelegate<T> = this.apply { isAccessible = true }.getDelegate().unsafeCast()
protected inline fun <T> KProperty0<T>.acknowledge(): T = delegate().acknowledge()
protected inline fun <T> KProperty0<T>.rendering(): T = delegate().rendering()
protected open fun construct() {
tryUpdate()
}
}

View File

@ -52,7 +52,6 @@ open class TextElement(
parent: Element? = null,
properties: TextRenderProperties = TextRenderProperties.DEFAULT,
) : Element(guiRenderer, text.charCount * 6 * GUIMesh.GUIMeshStruct.FLOATS_PER_VERTEX), Labeled {
protected open val updateOnInitialize: Boolean get() = true
private var activeElement: TextComponent? = null
lateinit var info: TextRenderInfo
private set
@ -75,9 +74,7 @@ open class TextElement(
init {
this.parent = parent
if (updateOnInitialize) {
update()
}
construct()
}
private fun updateWishSize(text: ChatComponent) {

View File

@ -35,7 +35,6 @@ class FadingTextElement(
parent: Element? = null,
properties: TextRenderProperties = TextRenderProperties.DEFAULT,
) : TextElement(guiRenderer = guiRenderer, text = text, background = background, parent, properties) {
override val updateOnInitialize: Boolean get() = false
private var phase: FadePhase? by GuiDelegate(null)
var times: FadingTimes = times
@ -48,9 +47,11 @@ class FadingTextElement(
init {
show()
tryUpdate()
super.construct()
}
override fun construct() = Unit // don't get called by TextElement before phase delegate is initialized
private fun updateSize() {
this.size = if (phase == null) Vec2.EMPTY else info.size.withBackgroundSize()
}