diff options
author | Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> | 2024-04-07 16:18:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-07 16:18:27 +0200 |
commit | ce29516ea38478b6a10ec9a747ee626d0d67a0cb (patch) | |
tree | 66f930a80951e96a57e9f07af4c8186e39977d79 /src/main/java/at/hannibal2/skyhanni | |
parent | d3cd3c4ff4c51a8f047d396fb5edbb7cf523ca84 (diff) | |
download | skyhanni-ce29516ea38478b6a10ec9a747ee626d0d67a0cb.tar.gz skyhanni-ce29516ea38478b6a10ec9a747ee626d0d67a0cb.tar.bz2 skyhanni-ce29516ea38478b6a10ec9a747ee626d0d67a0cb.zip |
Backend: Renderable Vertical Container (#1318)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt | 32 |
1 files changed, 28 insertions, 4 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 92d5a4cf9..b9666fe12 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt @@ -511,19 +511,43 @@ interface Renderable { val renderables = content override val width = renderables.sumOf { it.width } + spacing * (renderables.size - 1) - override val height = renderables.maxOf { it.height } + override val height = renderables.maxOfOrNull { it.height } ?: 0 override val horizontalAlign = horizontalAlign override val verticalAlign = verticalAlign override fun render(posX: Int, posY: Int) { - var xOffset = 0 + var xOffset = posX renderables.forEach { - it.renderYAligned(xOffset, 0, height) + it.renderYAligned(xOffset, posY, height) xOffset += it.width + spacing - GlStateManager.translate(it.width.toFloat(), 0f, 0f) + GlStateManager.translate((it.width + spacing).toFloat(), 0f, 0f) } GlStateManager.translate(-width.toFloat() - spacing.toFloat(), 0f, 0f) } } + + fun verticalContainer( + content: List<Renderable>, + spacing: Int = 0, + horizontalAlign: HorizontalAlignment = HorizontalAlignment.LEFT, + verticalAlign: VerticalAlignment = VerticalAlignment.TOP, + ) = object : Renderable { + val renderables = content + + override val width = renderables.maxOfOrNull { it.width } ?: 0 + override val height = renderables.sumOf { it.height } + spacing * (renderables.size - 1) + override val horizontalAlign = horizontalAlign + override val verticalAlign = verticalAlign + + override fun render(posX: Int, posY: Int) { + var yOffset = posY + renderables.forEach { + it.renderXAligned(yOffset, posX, width) + yOffset += it.height + spacing + GlStateManager.translate(0f, (it.height + spacing).toFloat(), 0f) + } + GlStateManager.translate(0f, -height.toFloat() - spacing.toFloat(), 0f) + } + } } } |