mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
input element: editable property
This commit is contained in:
parent
d4b0e896d0
commit
82bd093d3c
@ -34,6 +34,7 @@ class TextInputElement(
|
||||
guiRenderer: GUIRenderer,
|
||||
val maxLength: Int = Int.MAX_VALUE,
|
||||
val cursorStyles: TextCursorStyles = TextCursorStyles.CLICKED,
|
||||
var editable: Boolean = true,
|
||||
) : Element(guiRenderer) {
|
||||
private val cursor = ColorElement(guiRenderer, size = Vec2i(1, Font.TOTAL_CHAR_HEIGHT))
|
||||
private val textElement = MarkTextElement(guiRenderer, "", background = false, parent = this)
|
||||
@ -54,7 +55,6 @@ class TextInputElement(
|
||||
private var pointer = 0
|
||||
private var cursorTick = 0
|
||||
|
||||
|
||||
override fun forceRender(offset: Vec2i, consumer: GUIVertexConsumer, options: GUIVertexOptions?) {
|
||||
background.render(offset, consumer, options)
|
||||
|
||||
@ -97,6 +97,9 @@ class TextInputElement(
|
||||
}
|
||||
|
||||
private fun insert(string: String) {
|
||||
if (!editable) {
|
||||
return
|
||||
}
|
||||
val insert = string.replace("\n", "").replace("\r", "").replace('§', '&')
|
||||
if (textElement.marked) {
|
||||
_value.delete(textElement.markStartPosition, textElement.markEndPosition)
|
||||
@ -111,7 +114,7 @@ class TextInputElement(
|
||||
}
|
||||
|
||||
override fun onCharPress(char: Int) {
|
||||
if (_value.length >= maxLength) {
|
||||
if (_value.length >= maxLength || !editable) {
|
||||
return
|
||||
}
|
||||
cursorTick = CURSOR_TICK_ON_ACTION
|
||||
@ -178,7 +181,7 @@ class TextInputElement(
|
||||
}
|
||||
}
|
||||
KeyCodes.KEY_BACKSPACE -> {
|
||||
if (_value.isEmpty()) {
|
||||
if (_value.isEmpty() || !editable) {
|
||||
return
|
||||
}
|
||||
if (textElement.marked) {
|
||||
@ -192,7 +195,7 @@ class TextInputElement(
|
||||
}
|
||||
}
|
||||
KeyCodes.KEY_DELETE -> {
|
||||
if (_value.isEmpty()) {
|
||||
if (_value.isEmpty() || !editable) {
|
||||
return
|
||||
}
|
||||
if (textElement.marked) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user