diff options
author | Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> | 2024-02-19 16:28:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-19 16:28:15 +0100 |
commit | 87b5d2fa37d0dec89b8838aa6f3f9cfa46891d09 (patch) | |
tree | 13f47eb88c13ee38f8a2568de1feabc77e3c8225 /src/main/java/at | |
parent | 35df2ab2aa2056b61034757fe61554e7075dedd1 (diff) | |
download | skyhanni-87b5d2fa37d0dec89b8838aa6f3f9cfa46891d09.tar.gz skyhanni-87b5d2fa37d0dec89b8838aa6f3f9cfa46891d09.tar.bz2 skyhanni-87b5d2fa37d0dec89b8838aa6f3f9cfa46891d09.zip |
Added Horizontal Container Renderable. #986
Diffstat (limited to 'src/main/java/at')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt | 45 |
1 files changed, 44 insertions, 1 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 5224cef0f..5316b68cc 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt @@ -7,6 +7,8 @@ import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.NEUItems.renderOnScreen import at.hannibal2.skyhanni.utils.RenderUtils.HorizontalAlignment import at.hannibal2.skyhanni.utils.RenderUtils.VerticalAlignment +import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXAligned +import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderYAligned import io.github.moulberry.moulconfig.gui.GuiScreenElementWrapper import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.client.Minecraft @@ -242,7 +244,6 @@ interface Renderable { unhovered.render(posX, posY) isHovered = false } - } } @@ -320,5 +321,47 @@ interface Renderable { } } + + fun horizontalContainer( + content: List<Renderable>, + spacing: Int = 0, + horizontalAlign: HorizontalAlignment = HorizontalAlignment.LEFT, + verticalAlign: VerticalAlignment = VerticalAlignment.TOP, + ) = object : Renderable { + val renderables = content + + override val width = renderables.sumOf { it.width } + spacing * (renderables.size - 1) + override val height = renderables.maxOf { it.height } + override val horizontalAlign = horizontalAlign + override val verticalAlign = verticalAlign + + override fun render(posX: Int, posY: Int) { + var xOffset = 0 + renderables.forEach { + it.renderYAligned(xOffset, 0, height) + xOffset += it.width + spacing + GlStateManager.translate(it.width.toFloat(), 0f, 0f) + } + GlStateManager.translate(-width.toFloat() - spacing.toFloat(), 0f, 0f) + } + } + + fun fixedSizeLine( + content: Renderable, + width: Int, + horizontalAlign: HorizontalAlignment = HorizontalAlignment.LEFT, + verticalAlign: VerticalAlignment = VerticalAlignment.TOP, + ) = object : Renderable { + val render = content + + override val width = width + override val height = render.height + override val horizontalAlign = horizontalAlign + override val verticalAlign = verticalAlign + + override fun render(posX: Int, posY: Int) { + render.renderXAligned(0, 0, width) + } + } } } |