[enhancement] Readable name for enum sliders, improved window dragging

This commit is contained in:
Xiaro 2021-01-05 09:42:19 -05:00
parent ca20f804c6
commit 618747ad1f
No known key found for this signature in database
GPG Key ID: 996D265D6E155377
2 changed files with 8 additions and 10 deletions

View File

@ -97,17 +97,17 @@ open class WindowComponent(
val centerSplitterV = min(10.0, preDragSize.y / 3.0) val centerSplitterV = min(10.0, preDragSize.y / 3.0)
val horizontalSide = when (relativeClickPos.x) { val horizontalSide = when (relativeClickPos.x) {
in -5.0..centerSplitterH -> HAlign.LEFT in -2.0..centerSplitterH -> HAlign.LEFT
in centerSplitterH..preDragSize.x - centerSplitterH -> HAlign.CENTER in centerSplitterH..preDragSize.x - centerSplitterH -> HAlign.CENTER
in preDragSize.x - centerSplitterH..preDragSize.x + 5.0 -> HAlign.RIGHT in preDragSize.x - centerSplitterH..preDragSize.x + 2.0 -> HAlign.RIGHT
else -> null else -> null
} }
val centerSplitterVCenter = if (draggableHeight != height && horizontalSide == HAlign.CENTER) 2.5 else min(15.0, preDragSize.x / 3.0) val centerSplitterVCenter = if (draggableHeight != height && horizontalSide == HAlign.CENTER) 2.5 else min(15.0, preDragSize.x / 3.0)
val verticalSide = when (relativeClickPos.y) { val verticalSide = when (relativeClickPos.y) {
in -5.0..centerSplitterVCenter -> VAlign.TOP in -2.0..centerSplitterVCenter -> VAlign.TOP
in centerSplitterVCenter..preDragSize.y - centerSplitterV -> VAlign.CENTER in centerSplitterVCenter..preDragSize.y - centerSplitterV -> VAlign.CENTER
in preDragSize.y - centerSplitterV..preDragSize.y + 5.0 -> VAlign.BOTTOM in preDragSize.y - centerSplitterV..preDragSize.y + 2.0 -> VAlign.BOTTOM
else -> null else -> null
} }
@ -167,8 +167,8 @@ open class WindowComponent(
} }
fun isInWindow(mousePos: Vec2f): Boolean { fun isInWindow(mousePos: Vec2f): Boolean {
return visible && mousePos.x in preDragPos.x - 5.0f..preDragPos.x + preDragSize.x + 5.0f return visible && mousePos.x in preDragPos.x - 2.0f..preDragPos.x + preDragSize.x + 2.0f
&& mousePos.y in preDragPos.y - 5.0f..preDragPos.y + max(preDragSize.y * renderMinimizeProgress, draggableHeight) + 5.0f && mousePos.y in preDragPos.y - 2.0f..preDragPos.y + max(preDragSize.y * renderMinimizeProgress, draggableHeight) + 2.0f
} }
init { init {

View File

@ -5,7 +5,7 @@ import me.zeroeightsix.kami.setting.settings.impl.primitive.EnumSetting
import me.zeroeightsix.kami.util.graphics.VertexHelper import me.zeroeightsix.kami.util.graphics.VertexHelper
import me.zeroeightsix.kami.util.graphics.font.FontRenderAdapter import me.zeroeightsix.kami.util.graphics.font.FontRenderAdapter
import me.zeroeightsix.kami.util.math.Vec2f import me.zeroeightsix.kami.util.math.Vec2f
import org.kamiblue.commons.interfaces.DisplayEnum import org.kamiblue.commons.extension.readableName
import kotlin.math.floor import kotlin.math.floor
class EnumSlider(val setting: EnumSetting<*>) : Slider(setting.name, 0.0, setting.description) { class EnumSlider(val setting: EnumSetting<*>) : Slider(setting.name, 0.0, setting.description) {
@ -40,7 +40,7 @@ class EnumSlider(val setting: EnumSetting<*>) : Slider(setting.name, 0.0, settin
private fun roundInput(valueIn: Double) = floor(valueIn * enumValues.size).toInt().coerceIn(0, enumValues.size - 1) private fun roundInput(valueIn: Double) = floor(valueIn * enumValues.size).toInt().coerceIn(0, enumValues.size - 1)
override fun onRender(vertexHelper: VertexHelper, absolutePos: Vec2f) { override fun onRender(vertexHelper: VertexHelper, absolutePos: Vec2f) {
val valueText = tryGetDisplayName(setting.value) val valueText = setting.value.readableName()
protectedWidth = FontRenderAdapter.getStringWidth(valueText, 0.75f).toDouble() protectedWidth = FontRenderAdapter.getStringWidth(valueText, 0.75f).toDouble()
super.onRender(vertexHelper, absolutePos) super.onRender(vertexHelper, absolutePos)
@ -48,6 +48,4 @@ class EnumSlider(val setting: EnumSetting<*>) : Slider(setting.name, 0.0, settin
val posY = renderHeight - 2.0f - FontRenderAdapter.getFontHeight(0.75f) val posY = renderHeight - 2.0f - FontRenderAdapter.getFontHeight(0.75f)
FontRenderAdapter.drawString(valueText, posX, posY, color = GuiColors.text, scale = 0.75f) FontRenderAdapter.drawString(valueText, posX, posY, color = GuiColors.text, scale = 0.75f)
} }
private fun tryGetDisplayName(enum: Enum<*>) = if (enum is DisplayEnum) enum.displayName else enum.name
} }