Fix scroll bar button going NaN when there is nothing to scroll
This commit is contained in:
parent
1e4f33c1bc
commit
ef22c80a5b
@ -21,7 +21,7 @@ open class DiscreteScrollBarPanel(
|
|||||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||||
if (isScrolling) {
|
if (isScrolling) {
|
||||||
ScrollBarConstants.scrollBarButtonPress.render(stack, 0f, 0f)
|
ScrollBarConstants.scrollBarButtonPress.render(stack, 0f, 0f)
|
||||||
} else if (isHovered) {
|
} else if (isHovered && maxScroll.invoke(this@DiscreteScrollBarPanel) > 0) {
|
||||||
ScrollBarConstants.scrollBarButtonHover.render(stack, 0f, 0f)
|
ScrollBarConstants.scrollBarButtonHover.render(stack, 0f, 0f)
|
||||||
} else {
|
} else {
|
||||||
ScrollBarConstants.scrollBarButton.render(stack, 0f, 0f)
|
ScrollBarConstants.scrollBarButton.render(stack, 0f, 0f)
|
||||||
@ -32,6 +32,10 @@ open class DiscreteScrollBarPanel(
|
|||||||
private var rememberY = 0.0
|
private var rememberY = 0.0
|
||||||
|
|
||||||
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
||||||
|
if (maxScroll.invoke(this@DiscreteScrollBarPanel) <= 0) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
if (button == InputConstants.MOUSE_BUTTON_LEFT) {
|
if (button == InputConstants.MOUSE_BUTTON_LEFT) {
|
||||||
isScrolling = true
|
isScrolling = true
|
||||||
trapMouseInput = true
|
trapMouseInput = true
|
||||||
@ -104,8 +108,15 @@ open class DiscreteScrollBarPanel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
open fun updateScrollButtonPosition() {
|
open fun updateScrollButtonPosition() {
|
||||||
|
val maxScroll = this.maxScroll.invoke(this)
|
||||||
|
|
||||||
|
if (maxScroll <= 0) {
|
||||||
|
scrollButton.y = 1f
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val availableHeight = height - scrollButton.height - 2f
|
val availableHeight = height - scrollButton.height - 2f
|
||||||
scrollButton.y = 1f + availableHeight * (scroll.toFloat() / maxScroll.invoke(this))
|
scrollButton.y = 1f + availableHeight * (scroll.toFloat() / maxScroll)
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun scrollChanged(oldScroll: Int, newScroll: Int) {
|
open fun scrollChanged(oldScroll: Int, newScroll: Int) {
|
||||||
|
Loading…
Reference in New Issue
Block a user