From a7e7e6e60ecfa071514f719029a23891399b9c6f Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Sun, 2 May 2021 14:52:48 +0200 Subject: [PATCH] Rename scrollBar to buttonsProgressBar --- .../kotlin/fr/username404/snowygui/gui/Element.kt | 5 +++-- .../username404/snowygui/gui/elements/ClickBox.kt | 15 +++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt index ba17042..9b27fd8 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt @@ -24,8 +24,9 @@ fun interface Renderable { abstract class Element( @JvmField val xOrigin: Double, @JvmField val yOrigin: Double, - var width: Int, var height: Int + val originalWidth: Int, val originalHeight: Int ): Renderable { + open var width = originalWidth; open var height = originalHeight open var x = xOrigin; open var y = yOrigin internal fun withinBounds(coordinateX: Double, coordinateY: Double): Boolean = ((coordinateX >= this.x) && (coordinateX <= (this.x + this.width))) and ((coordinateY >= this.y) && (coordinateY <= (this.y + this.height))) @@ -49,7 +50,7 @@ abstract class Element( } } } - var hidden: Boolean = false; protected set + var hidden: Boolean = false; internal set } abstract class ColoredElement( diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt index 2200d11..9edfb08 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt @@ -7,6 +7,7 @@ import fr.username404.snowygui.gui.ColoredElement import fr.username404.snowygui.gui.Renderable.Rendering.buffer import fr.username404.snowygui.gui.Renderable.Rendering.defaultRectFunc import fr.username404.snowygui.gui.Renderable.Rendering.tessellator +import fr.username404.snowygui.gui.elements.ClickButton.Companion.Type import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import net.minecraft.client.Minecraft @@ -18,16 +19,16 @@ class ClickBox( private val name: TranslatableComponent? = null ): ColoredElement(x, y, 80, 10, 0x6C9E9D, 0.5F) { val buttons = mutableMapOf() - fun addButtons(vararg collect: Pair Unit)?>, color: Int = 0x6C9E9D): ClickBox { + fun addButtons(vararg collect: Pair Unit)?>, color: Int = 0x6C9E9D, kind: Type = Type.TOGGLE): ClickBox { buttons.putAll( collect.map { - it.first to ClickButton(Title = it.first, action = it.second, color = color) + it.first to ClickButton(Title = it.first, action = it.second, color = color, kind = kind) } ) return this } @JvmField - val scrollBar: ColoredElement = object: ColoredElement( + val buttonsProgressBar: ColoredElement = object: ColoredElement( (x + width), y + height + 3, color = color, width = 3, height = 74, opacity = 0.75F @@ -42,8 +43,10 @@ class ClickBox( } } fun scroll(supplied: Double) { - with(scrollBar) { - // TODO Implement scrolling + with(buttonsProgressBar) { + if ((height != 0 || (supplied < 0)) && ((height != originalHeight) || (supplied > 0))) { + height -= supplied.toInt() + } } } @@ -79,7 +82,7 @@ class ClickBox( RenderSystem.disableBlend() val renderButtons = if (buttons.isNotEmpty()) launch { - scrollBar.apply { + buttonsProgressBar.apply { x = this@ClickBox.x + this@ClickBox.width - 3 y = this@ClickBox.y + this@ClickBox.height + 3 }.display(poseStack)