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) {
|
||||
if (isScrolling) {
|
||||
ScrollBarConstants.scrollBarButtonPress.render(stack, 0f, 0f)
|
||||
} else if (isHovered) {
|
||||
} else if (isHovered && maxScroll.invoke(this@DiscreteScrollBarPanel) > 0) {
|
||||
ScrollBarConstants.scrollBarButtonHover.render(stack, 0f, 0f)
|
||||
} else {
|
||||
ScrollBarConstants.scrollBarButton.render(stack, 0f, 0f)
|
||||
@ -32,6 +32,10 @@ open class DiscreteScrollBarPanel(
|
||||
private var rememberY = 0.0
|
||||
|
||||
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
||||
if (maxScroll.invoke(this@DiscreteScrollBarPanel) <= 0) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (button == InputConstants.MOUSE_BUTTON_LEFT) {
|
||||
isScrolling = true
|
||||
trapMouseInput = true
|
||||
@ -104,8 +108,15 @@ open class DiscreteScrollBarPanel(
|
||||
}
|
||||
|
||||
open fun updateScrollButtonPosition() {
|
||||
val maxScroll = this.maxScroll.invoke(this)
|
||||
|
||||
if (maxScroll <= 0) {
|
||||
scrollButton.y = 1f
|
||||
return
|
||||
}
|
||||
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user