Align text vertically when not multilining
This commit is contained in:
parent
986be8fa1a
commit
c91124d25c
@ -27,6 +27,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
|||||||
import ru.dbotthepony.mc.otm.core.addAll
|
import ru.dbotthepony.mc.otm.core.addAll
|
||||||
import ru.dbotthepony.mc.otm.core.math.RGBAColor
|
import ru.dbotthepony.mc.otm.core.math.RGBAColor
|
||||||
import ru.dbotthepony.mc.otm.milliTime
|
import ru.dbotthepony.mc.otm.milliTime
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
open class TextInputPanel<out S : Screen>(
|
open class TextInputPanel<out S : Screen>(
|
||||||
screen: S,
|
screen: S,
|
||||||
@ -1049,6 +1050,8 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
if (!backgroundColor.isFullyTransparent)
|
if (!backgroundColor.isFullyTransparent)
|
||||||
drawRect(stack, 0f, 0f, width, height, backgroundColor)
|
drawRect(stack, 0f, 0f, width, height, backgroundColor)
|
||||||
|
|
||||||
|
var topPadding = dockPadding.top
|
||||||
|
|
||||||
if (multiLine) {
|
if (multiLine) {
|
||||||
val heightInLines = ((height - dockPadding.top - dockPadding.bottom) / (font.lineHeight + rowSpacing)).toInt()
|
val heightInLines = ((height - dockPadding.top - dockPadding.bottom) / (font.lineHeight + rowSpacing)).toInt()
|
||||||
|
|
||||||
@ -1061,6 +1064,8 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
scrollLines = 0
|
scrollLines = 0
|
||||||
|
|
||||||
|
topPadding += ((height - dockPadding.top - dockPadding.bottom - font.lineHeight).coerceAtLeast(0f) / 2f).roundToInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
val selectedLine = this[cursorLine]
|
val selectedLine = this[cursorLine]
|
||||||
@ -1078,7 +1083,7 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
stack.pushPose()
|
stack.pushPose()
|
||||||
stack.translate(-scrollPixels, 0f, 0f)
|
stack.translate(-scrollPixels, 0f, 0f)
|
||||||
|
|
||||||
var y = dockPadding.top
|
var y = topPadding
|
||||||
|
|
||||||
for (i in scrollLines until lines.size) {
|
for (i in scrollLines until lines.size) {
|
||||||
val line = lines[i]
|
val line = lines[i]
|
||||||
@ -1146,7 +1151,7 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
text = "_",
|
text = "_",
|
||||||
align = TextAlign.TOP_LEFT,
|
align = TextAlign.TOP_LEFT,
|
||||||
x = dockPadding.left + (if (activeLine == null) 0f else font.width(activeLine).toFloat()),
|
x = dockPadding.left + (if (activeLine == null) 0f else font.width(activeLine).toFloat()),
|
||||||
y = dockPadding.top + (cursorLine - scrollLines) * (font.lineHeight + rowSpacing),
|
y = topPadding + (cursorLine - scrollLines) * (font.lineHeight + rowSpacing),
|
||||||
color = cursorColor
|
color = cursorColor
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
@ -1156,7 +1161,7 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
text = "|",
|
text = "|",
|
||||||
align = TextAlign.TOP_LEFT,
|
align = TextAlign.TOP_LEFT,
|
||||||
x = dockPadding.left + font.width(activeLine.substring(0, cursorRow)).toFloat() - 1f,
|
x = dockPadding.left + font.width(activeLine.substring(0, cursorRow)).toFloat() - 1f,
|
||||||
y = dockPadding.top + (cursorLine - scrollLines) * (font.lineHeight + rowSpacing),
|
y = topPadding + (cursorLine - scrollLines) * (font.lineHeight + rowSpacing),
|
||||||
color = cursorColor
|
color = cursorColor
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -1171,7 +1176,7 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
text = cursorLine.toString(),
|
text = cursorLine.toString(),
|
||||||
align = TextAlign.TOP_RIGHT,
|
align = TextAlign.TOP_RIGHT,
|
||||||
x = width,
|
x = width,
|
||||||
y = dockPadding.top,
|
y = topPadding,
|
||||||
color = cursorColor
|
color = cursorColor
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1181,7 +1186,7 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
text = cursorRow.toString(),
|
text = cursorRow.toString(),
|
||||||
align = TextAlign.TOP_RIGHT,
|
align = TextAlign.TOP_RIGHT,
|
||||||
x = width - dockPadding.right,
|
x = width - dockPadding.right,
|
||||||
y = dockPadding.top + font.lineHeight + rowSpacing,
|
y = topPadding + font.lineHeight + rowSpacing,
|
||||||
color = cursorColor
|
color = cursorColor
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1191,7 +1196,7 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
text = lines.size.toString(),
|
text = lines.size.toString(),
|
||||||
align = TextAlign.TOP_RIGHT,
|
align = TextAlign.TOP_RIGHT,
|
||||||
x = width - dockPadding.right,
|
x = width - dockPadding.right,
|
||||||
y = dockPadding.top + font.lineHeight * 2f + rowSpacing * 2f,
|
y = topPadding + font.lineHeight * 2f + rowSpacing * 2f,
|
||||||
color = cursorColor
|
color = cursorColor
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user