Use isDragging instead of a private variable in ClickGui.kt

This commit is contained in:
Username404 2021-06-27 13:24:13 +02:00
parent a5b1c45a86
commit 05dcbee261
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
1 changed files with 3 additions and 4 deletions

View File

@ -7,7 +7,6 @@ import fr.username404.snowygui.gui.elements.ClickBox
import org.lwjgl.glfw.GLFW import org.lwjgl.glfw.GLFW
object ClickGui: SnowyScreen() { object ClickGui: SnowyScreen() {
private var GuiDragging: Boolean = false
override val components = mutableSetOf<Element>() override val components = mutableSetOf<Element>()
val clickBoxes get() = components.filterIsInstance<ClickBox>() val clickBoxes get() = components.filterIsInstance<ClickBox>()
@ -19,11 +18,11 @@ object ClickGui: SnowyScreen() {
override fun mouseDragged(d: Double, e: Double, i: Int, f: Double, g: Double): Boolean { override fun mouseDragged(d: Double, e: Double, i: Int, f: Double, g: Double): Boolean {
if (i == GLFW.GLFW_MOUSE_BUTTON_LEFT) { if (i == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
components.forEach { components.forEach {
if (it.isWithinBounds(d, e) && !GuiDragging) { if (it.isWithinBounds(d, e) && !isDragging) {
GuiDragging = true isDragging = true
it.x = d.minus(f) + (d - (it.x + it.width)) it.x = d.minus(f) + (d - (it.x + it.width))
it.y = e.minus(g) + (e - (it.y + it.height)) it.y = e.minus(g) + (e - (it.y + it.height))
} else GuiDragging = false } else isDragging = false
} }
} }
return super.mouseDragged(d, e, i, f, g) return super.mouseDragged(d, e, i, f, g)