textbuttonlist fixed incorrect vertical placement

This commit is contained in:
Minjae Song
2018-12-09 17:11:13 +09:00
parent 32ecdc4b4d
commit eb1a3dcd14
4 changed files with 28 additions and 14 deletions

View File

@@ -30,12 +30,13 @@ open class UIItemTextButton(
val preGapX: Int = 0,
val postGapX: Int = 0,
val alignment: Alignment = Alignment.CENTRE
val alignment: Alignment = Alignment.CENTRE,
val hitboxSize: Int = UIItemTextButton.height
) : UIItem(parentUI) {
companion object {
val font = Terrarum.fontGame
val height = font.lineHeight.toInt() * 2
val height = font.lineHeight.toInt()
val defaultInactiveCol: Color = Color(0xc8c8c8_ff.toInt())
val defaultHighlightCol: Color = Color(0x00f8ff_ff)
@@ -49,7 +50,7 @@ open class UIItemTextButton(
get() = if (readFromLang) Lang[labelText] else labelText
override val height: Int = UIItemTextButton.height
override val height: Int = hitboxSize
var highlighted: Boolean = false
@@ -85,7 +86,7 @@ open class UIItemTextButton(
Alignment.LEFT -> posX.toFloat() + preGapX
Alignment.RIGHT -> width - postGapX - textW.toFloat()
},
posY.toFloat() + height / 4
posY.toFloat() + (hitboxSize - UIItemTextButton.height) / 2f
)
}

View File

@@ -20,7 +20,6 @@ class UIItemTextButtonList(
override var posY: Int,
override var width: Int,
override var height: Int,
val verticalGutter: Int = 0,
val readFromLang: Boolean = false,
val defaultSelection: Int? = null, // negative: INVALID, positive: valid, null: no select
@@ -42,7 +41,8 @@ class UIItemTextButtonList(
val backgroundBlendMode: String = BlendMode.NORMAL,
val kinematic: Boolean = false,
val alignment: UIItemTextButton.Companion.Alignment = UIItemTextButton.Companion.Alignment.CENTRE
val alignment: UIItemTextButton.Companion.Alignment = UIItemTextButton.Companion.Alignment.CENTRE,
val itemHitboxSize: Int = UIItemTextButton.height
) : UIItem(parentUI) {
val iconToTextGap = 20
@@ -56,13 +56,20 @@ class UIItemTextButtonList(
val buttons = labelsList.mapIndexed { index, s ->
val height = this.height - UIItemTextButton.height
val buttons = labelsList.mapIndexed { i, s ->
//val height = this.height - UIItemTextButton.height
val h = height.toFloat()
val ss = labelsList.size.toFloat()
val half_lh = UIItemTextButton.height / 2f
val vertOff = (i * h/ss - half_lh).roundInt()
println("$i -> $vertOff for height $height")
if (!kinematic) {
UIItemTextButton(
parentUI, s,
posX = posX,
posY = posY + verticalGutter + ((height - 2 * verticalGutter) / labelsList.size.minus(1).toFloat() * index).roundInt(),
posY = posY + vertOff,
width = width,
readFromLang = readFromLang,
activeCol = activeCol,
@@ -74,14 +81,15 @@ class UIItemTextButtonList(
inactiveCol = inactiveCol,
preGapX = pregap,
postGapX = postgap,
alignment = alignment
alignment = alignment,
hitboxSize = itemHitboxSize
)
}
else {
UIItemTextButton(
parentUI, s,
posX = posX,
posY = posY + verticalGutter + ((height - 2 * verticalGutter) / labelsList.size.minus(1).toFloat() * index).roundInt(),
posY = posY + vertOff,
width = width,
readFromLang = readFromLang,
activeCol = activeCol,
@@ -93,7 +101,8 @@ class UIItemTextButtonList(
inactiveCol = inactiveCol,
preGapX = pregap,
postGapX = postgap,
alignment = alignment
alignment = alignment,
hitboxSize = itemHitboxSize
)
}
}