diff options
author | Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> | 2024-09-09 09:58:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-09 09:58:25 +0200 |
commit | c578c393b9ff882563a4e9d380a94662fa1ce2fb (patch) | |
tree | bc8328b68e3090b9dea7531d23727995b288ba3d | |
parent | 796ef7ca4139669f15e323c112378125760b5292 (diff) | |
download | skyhanni-c578c393b9ff882563a4e9d380a94662fa1ce2fb.tar.gz skyhanni-c578c393b9ff882563a4e9d380a94662fa1ce2fb.tar.bz2 skyhanni-c578c393b9ff882563a4e9d380a94662fa1ce2fb.zip |
Backend: Renderable SearchBox added full hide if empty (#2481)
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt index 91abc636d..48d5caafb 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt @@ -568,8 +568,10 @@ interface Renderable { val textBoxHeight = (9 * scale).toInt() + 1 + val isTextBoxEmpty get() = textInput.textBox.isEmpty() + override var width: Int = content.width - override val height: Int = content.height + ySpacing + textBoxHeight + override var height: Int = content.height + if (hideIfNoText && isTextBoxEmpty) 0 else (ySpacing + textBoxHeight) override val horizontalAlign = content.horizontalAlign override val verticalAlign = content.verticalAlign @@ -577,24 +579,39 @@ interface Renderable { init { textInput.registerToEvent(key) { + var shouldUpdate = false + if (hideIfNoText) { + if (isTextBoxEmpty) { + if (height != content.height) { + height = content.height + shouldUpdate = true + } + } else { + if (height == content.height) { + height = content.height + ySpacing + textBoxHeight + shouldUpdate = true + } + } + } val searchWidth = searchWidth if (searchWidth > width) { width = searchWidth - onUpdateSize(this) + shouldUpdate = true } else { if (width > content.width) { width = maxOf(content.width, searchWidth) - onUpdateSize(this) + shouldUpdate = true } } + if (shouldUpdate) { + onUpdateSize(this) + } } } override fun render(posX: Int, posY: Int) { - if (shouldRenderTopElseBottom) { - if (!(hideIfNoText && textInput.textBox.isEmpty())) { - RenderableUtils.renderString(searchPrefix + textInput.editText(), scale, color) - } + if (shouldRenderTopElseBottom && !(hideIfNoText && isTextBoxEmpty)) { + RenderableUtils.renderString(searchPrefix + textInput.editText(), scale, color) GlStateManager.translate(0f, (ySpacing + textBoxHeight).toFloat(), 0f) } if (isHovered(posX, posY) && condition() && shouldAllowLink(true, bypassChecks)) { @@ -613,7 +630,9 @@ interface Renderable { } else { textInput.disable() } - if (!shouldRenderTopElseBottom) { + if (hideIfNoText && isTextBoxEmpty) { + content.render(posX, posY) + } else if (!shouldRenderTopElseBottom) { content.render(posX, posY) GlStateManager.translate(0f, (ySpacing).toFloat(), 0f) if (!(hideIfNoText && textInput.textBox.isEmpty())) { @@ -1115,7 +1134,7 @@ interface Renderable { uMax, vMin, vMax, - GL11.GL_NEAREST + GL11.GL_NEAREST, ) GlStateManager.color(1f, 1f, 1f, 1f) @@ -1154,7 +1173,7 @@ interface Renderable { uMax, vMin, vMax, - GL11.GL_NEAREST + GL11.GL_NEAREST, ) GlStateManager.color(1f, 1f, 1f, 1f) } |