remove continuous scroll bar panel
This commit is contained in:
parent
b4c07d331d
commit
8f2f599f38
@ -1,139 +0,0 @@
|
|||||||
package ru.dbotthepony.mc.otm.client.screen.panels
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack
|
|
||||||
import ru.dbotthepony.mc.otm.client.render.*
|
|
||||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
|
||||||
import java.util.function.Consumer
|
|
||||||
import java.util.function.Supplier
|
|
||||||
import kotlin.math.floor
|
|
||||||
|
|
||||||
open class ContinuousScrollBarPanel(screen: MatteryScreen<*>, parent: EditablePanel?, x: Float = 0f, y: Float = 0f, height: Float = 20f) :
|
|
||||||
EditablePanel(screen, parent, x, y, ScrollBarConstants.WIDTH, height) {
|
|
||||||
|
|
||||||
open inner class Button : EditablePanel(screen, this@ContinuousScrollBarPanel, 1f, 1f, 12f, 15f) {
|
|
||||||
var isScrolling = false
|
|
||||||
protected set
|
|
||||||
|
|
||||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
|
||||||
if (isScrolling) {
|
|
||||||
ScrollBarConstants.scrollBarButtonPress.render(stack, 0f, 0f)
|
|
||||||
} else if (isHovered) {
|
|
||||||
ScrollBarConstants.scrollBarButtonHover.render(stack, 0f, 0f)
|
|
||||||
} else {
|
|
||||||
ScrollBarConstants.scrollBarButton.render(stack, 0f, 0f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected var lastMouseY = 0.0
|
|
||||||
|
|
||||||
override fun mouseClickedInner(x: Double, y: Double, flag: Int): Boolean {
|
|
||||||
isScrolling = true
|
|
||||||
trapMouseInput = true
|
|
||||||
lastMouseY = y
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun mouseReleasedInner(x: Double, y: Double, button: Int): Boolean {
|
|
||||||
if (isScrolling) {
|
|
||||||
isScrolling = false
|
|
||||||
trapMouseInput = false
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun mouseScrolledInner(x: Double, y: Double, scroll: Double): Boolean {
|
|
||||||
return this@ContinuousScrollBarPanel.mouseScrolledInner(x, y, scroll)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun mouseDraggedInner(
|
|
||||||
x: Double,
|
|
||||||
y: Double,
|
|
||||||
button: Int,
|
|
||||||
xDelta: Double,
|
|
||||||
yDelta: Double
|
|
||||||
): Boolean {
|
|
||||||
if (isScrolling) {
|
|
||||||
val diff = y - lastMouseY
|
|
||||||
lastMouseY = y
|
|
||||||
this@ContinuousScrollBarPanel.scroll = (scroll + diff / this@ContinuousScrollBarPanel.height).toFloat()
|
|
||||||
updateScrollBarPosition()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val scrollButton = Button()
|
|
||||||
var scrollCallback: Consumer<Float>? = null
|
|
||||||
|
|
||||||
var scrollMultiplier = Supplier { 0.1f }
|
|
||||||
|
|
||||||
fun setupRowMultiplier(row_supplier: Supplier<Int>) {
|
|
||||||
scrollMultiplier = Supplier {
|
|
||||||
val rows = row_supplier.get()
|
|
||||||
|
|
||||||
if (rows < 1) {
|
|
||||||
return@Supplier 0f
|
|
||||||
}
|
|
||||||
|
|
||||||
return@Supplier 1f / rows
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var scroll = 0f
|
|
||||||
get() {
|
|
||||||
return if (field < 0f) 0f else if (field > 1f) 1f else field
|
|
||||||
}
|
|
||||||
set(scroll) {
|
|
||||||
val previous = field
|
|
||||||
field = if (scroll < 0f) 0f else if (scroll > 1f) 1f else scroll
|
|
||||||
|
|
||||||
if (previous != field) {
|
|
||||||
onScrolled(field, previous)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected open fun onScrolled(new_scroll: Float, old_scroll: Float) {
|
|
||||||
scrollCallback?.accept(new_scroll)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateScrollBarPosition() {
|
|
||||||
scrollButton.y = 1 + (height - 2 - scrollButton.height) * scroll
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun performLayout() {
|
|
||||||
super.performLayout()
|
|
||||||
updateScrollBarPosition()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun translateScrollValue(new_max: Int, old_max: Int) {
|
|
||||||
if (new_max < 1 || old_max < 1) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
scroll = scroll * old_max / new_max
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getScroll(max_rows: Int): Int {
|
|
||||||
if (max_rows <= 1)
|
|
||||||
return 0
|
|
||||||
|
|
||||||
return floor(scroll * max_rows + 0.5).toInt()
|
|
||||||
}
|
|
||||||
|
|
||||||
// public is for emulating input from outside
|
|
||||||
public override fun mouseScrolledInner(x: Double, y: Double, scroll: Double): Boolean {
|
|
||||||
this.scroll = (this.scroll - scroll * scrollMultiplier.get()).toFloat()
|
|
||||||
updateScrollBarPosition()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
|
||||||
ScrollBarConstants.scrollBarBody.render(stack, y = 2f, height = height - 4)
|
|
||||||
ScrollBarConstants.scrollBarTop.render(stack)
|
|
||||||
ScrollBarConstants.scrollBarBottom.render(stack, y = height - 2)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user