From 322e0700606af3a4f019609428b09df168a586d1 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sun, 4 Sep 2022 16:05:50 +0700 Subject: [PATCH] Add shadow to label, implement sizeToContents --- .../mc/otm/client/screen/panels/Label.kt | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/Label.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/Label.kt index 92e95a7f0..366c27056 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/Label.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/Label.kt @@ -13,9 +13,14 @@ open class Label @JvmOverloads constructor( y: Float = 0f, width: Float = 100f, height: Float = 10f, - var text: Component = TextComponent("Label") + var text: Component = TextComponent("Label"), + var shadow: Boolean = false ) : EditablePanel(screen, parent, x, y, width, height) { - constructor(screen: MatteryScreen<*>, parent: EditablePanel?, text: Component) : this(screen, parent, x = 0f, text = text) + constructor(screen: MatteryScreen<*>, parent: EditablePanel?, text: Component, shadow: Boolean = false) : this(screen, parent, x = 0f, text = text, shadow = shadow) + + var shadowX = 1f + var shadowY = 1f + var shadowColor = RGBAColor.BLACK init { scissor = true @@ -25,5 +30,19 @@ open class Label @JvmOverloads constructor( override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { font.draw(stack, text, 0f, 0f, color.toInt()) + + if (shadow) { + font.draw(stack, text, shadowX, shadowY, shadowColor.toInt()) + } + } + + override fun sizeToContents() { + super.sizeToContents() + + val w = font.width(text) + val h = font.lineHeight + 2 + + width = width.coerceAtLeast(w.toFloat()) + height = height.coerceAtLeast(h.toFloat()) } }