From 2beaf74843cfacf677df0080aeab989dbb15d691 Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Tue, 4 May 2021 18:18:48 +0200 Subject: [PATCH] Complete the scroll function --- .../username404/snowygui/gui/elements/ClickBox.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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 6841574..8bd7206 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 @@ -43,10 +43,14 @@ class ClickBox( } init { height = 8 } } + var barStage: Int = 1; private set fun scroll(supplied: Double) { with(buttonsProgressBar) { if ((height != 8 || (supplied < 0)) && ((height != originalHeight) || (supplied > 0))) { height -= supplied.toInt() + if (buttons.count() != 0) (height / buttons.count()).let { + if (it > 0) barStage = it + } } } } @@ -87,10 +91,12 @@ class ClickBox( x = this@ClickBox.x + this@ClickBox.width - 3 y = this@ClickBox.y + this@ClickBox.height + 3 }.display(poseStack) - buttons.values.forEachIndexed { num, it -> - it.apply { - it.x = this@ClickBox.x + 3 - it.y = this@ClickBox.y + 5 + height + (num * 9) + buttons.values.forEachIndexed { num, button -> + val fullHeight = (y + height.toDouble())..(y + height + 80.0) + button.also { + it.x = x + 3 + it.y = y + 3 + height + (((num + 1) - barStage) * 9) + it.hidden = if ((num + 1) <= 8) ((it.y) !in fullHeight) else ((it.y + it.height) !in fullHeight) }.display(poseStack) } } else null