mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 01:16:46 -04:00
proper size of chat box
This commit is contained in:
parent
84cfc5603f
commit
6dce7a4ecd
@ -45,7 +45,8 @@ class ChatBoxHUDElement(hudRenderer: HUDRenderer) : HUDElement(hudRenderer) {
|
||||
}
|
||||
|
||||
override fun screenChangeResizeCallback(screenDimensions: Vec2i) {
|
||||
layout.fakeX = screenDimensions.x
|
||||
layout.fakeX = screenDimensions.x - 2 // 1 pixel padding on every side
|
||||
inputField.fakeX = layout.fakeX
|
||||
}
|
||||
|
||||
fun openChat() {
|
||||
|
@ -15,7 +15,9 @@ package de.bixilon.minosoft.gui.rendering.hud.elements.input
|
||||
|
||||
import de.bixilon.minosoft.config.key.KeyCodes
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
||||
import de.bixilon.minosoft.gui.rendering.font.Font
|
||||
import de.bixilon.minosoft.gui.rendering.hud.elements.primitive.ImageElement
|
||||
import de.bixilon.minosoft.gui.rendering.hud.elements.primitive.Layout
|
||||
import de.bixilon.minosoft.gui.rendering.hud.elements.primitive.TextElement
|
||||
import de.bixilon.minosoft.util.MMath
|
||||
@ -26,11 +28,11 @@ open class TextField(
|
||||
z: Int = 0,
|
||||
font: Font,
|
||||
defaultText: String = "",
|
||||
val maxLength: Int = 256,
|
||||
var maxLength: Int = 256,
|
||||
) : Layout(start, z), KeyConsumer, MouseConsumer {
|
||||
override var focused: Boolean = true
|
||||
private var textBuilder: StringBuilder = StringBuilder(defaultText)
|
||||
private val textElement = TextElement(ChatComponent.valueOf(raw = text), font)
|
||||
private val textElement = TextElement(ChatComponent.valueOf(raw = text), font, background = false)
|
||||
private var position = text.length
|
||||
|
||||
var text: String
|
||||
@ -43,6 +45,7 @@ open class TextField(
|
||||
|
||||
init {
|
||||
addChild(textElement)
|
||||
addChild(ImageElement(Vec2i(0, 0), null, Vec2i(-1), z, RenderConstants.TEXT_BACKGROUND_COLOR))
|
||||
}
|
||||
|
||||
fun clearText() {
|
||||
|
@ -33,7 +33,7 @@ abstract class Element(
|
||||
|
||||
val cache = HUDCacheMesh(initialCacheSize)
|
||||
open var parent: Element? = null
|
||||
var size: Vec2i = Vec2i()
|
||||
open var size: Vec2i = Vec2i()
|
||||
|
||||
abstract fun recalculateSize()
|
||||
|
||||
|
@ -52,7 +52,19 @@ class ImageElement(
|
||||
override fun prepareCache(start: Vec2i, scaleFactor: Float, matrix: Mat4, z: Int) {
|
||||
val ourStart = addToStart(start, this.start * scaleFactor)
|
||||
val modelStart = matrix * Vec4(RenderConstants.PIXEL_UV_PIXEL_ADD + ourStart, 1.0f, 1.0f)
|
||||
val ourEnd = addToEnd(start, this.end * scaleFactor)
|
||||
val realEnd = Vec2i(
|
||||
x = if (end.x == -1) {
|
||||
parent!!.size.x
|
||||
} else {
|
||||
end.x * scaleFactor
|
||||
},
|
||||
y = if (end.y == -1) {
|
||||
parent!!.size.y
|
||||
} else {
|
||||
end.y * scaleFactor
|
||||
}
|
||||
)
|
||||
val ourEnd = addToEnd(start, realEnd)
|
||||
val modelEnd = matrix * Vec4(RenderConstants.PIXEL_UV_PIXEL_ADD + ourEnd, 1.0f, 1.0f)
|
||||
|
||||
val uvStart = textureLike?.uvStart ?: Vec2()
|
||||
|
@ -20,6 +20,11 @@ open class Layout(
|
||||
start: Vec2i,
|
||||
val z: Int,
|
||||
) : Element(start) {
|
||||
override var size: Vec2i
|
||||
get() = Vec2i(fakeX ?: super.size.x, fakeY ?: super.size.y)
|
||||
set(value) {
|
||||
super.size = value
|
||||
}
|
||||
private val children: MutableList<Element> = mutableListOf()
|
||||
var fakeX: Int? = null
|
||||
var fakeY: Int? = null
|
||||
@ -80,7 +85,6 @@ open class Layout(
|
||||
}
|
||||
if (changed) {
|
||||
clearCache()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,9 +46,10 @@ class TextElement(
|
||||
|
||||
private fun prepare() {
|
||||
clear()
|
||||
size = if (text.message.isBlank()) {
|
||||
Vec2i(0, Font.CHAR_HEIGHT)
|
||||
if (text.message.isBlank()) {
|
||||
fakeY = Font.CHAR_HEIGHT
|
||||
} else {
|
||||
fakeY = null
|
||||
val textSize = Vec2i(0, 0)
|
||||
text.prepareRender(Vec2i(1, 1), Vec2i(), font, this, this.z + z + 1, textSize)
|
||||
finishBatchAdd()
|
||||
@ -56,7 +57,6 @@ class TextElement(
|
||||
if (background) {
|
||||
drawBackground(textSize + 1, z)
|
||||
}
|
||||
Vec2i(textSize + 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user