public class UITextField extends UIComponent<UITextField> implements IScrollable
Modifier and Type | Class and Description |
---|---|
class |
UITextField.CursorPosition
This class determines a position inside the text divides in lines.
|
ITransformable.Alpha, ITransformable.Brightness, ITransformable.Color, ITransformable.Position<T>, ITransformable.Rotate, ITransformable.Scale, ITransformable.Size<T>, ITransformable.Translate
Modifier and Type | Field and Description |
---|---|
protected boolean |
autoSelectOnFocus
Whether this
UITextField should auto select the text when gaining focus. |
protected int |
bgColor
Background color of this
UITextField . |
protected int |
charOffset
Number of character offset out of this
UITextField when drawn. |
protected int |
cursorColor
Cursor color for this
UITextField . |
protected UITextField.CursorPosition |
cursorPosition
Current cursor position.
|
protected GuiShape |
cursorShape
Shape used to draw the cursor of this
UITextField . |
protected boolean |
editable
Whether this
UITextField is editable. |
protected float |
fontScale
Font scale used to draw the text *.
|
protected GuiIcon |
iconTextfield
Icon used to draw this
UITextField . |
protected GuiIcon |
iconTextfieldDisabled
Icon used to draw this
UITextField when disabled. |
protected int |
lineOffset
Number of line offset out of this
UITextField when drawn. |
protected java.util.List<java.lang.String> |
lines
Different lines if
multiLine is true . |
protected int |
lineSpacing
Space used between each line.
|
protected boolean |
multiLine
Whether this
UITextField handles multiline text. |
protected UISlimScrollbar |
scrollBar
Scrollbar of the textfield
|
protected int |
selectColor
Selection color for this
UITextField . |
protected boolean |
selectingText
Whether currently selecting text.
|
protected UITextField.CursorPosition |
selectionPosition
Current selection cursor position.
|
protected GuiShape |
selectShape
Shape used to draw the selection box.
|
protected long |
startTimer
Cursor blink timer.
|
protected java.lang.StringBuilder |
text
Current text of this
UITextField . |
protected int |
textColor
Color of the text for this
UITextField . |
protected boolean |
textShadow
Text shadow
|
Constructor and Description |
---|
UITextField(MalisisGui gui,
boolean multiLine)
Instantiates a new empty
UITextField . |
UITextField(MalisisGui gui,
java.lang.String text)
Instantiates a new single lined
UITextField . |
UITextField(MalisisGui gui,
java.lang.String text,
boolean multiLine)
Instantiates a new
UITextField . |
Modifier and Type | Method and Description |
---|---|
void |
addText(java.lang.String str)
Adds text at current cursor position.
|
protected void |
buildLines()
Builds the lines for this
UITextField . |
protected void |
createShape(MalisisGui gui)
Creates the shapes used by this
UITextField . |
void |
deleteFromCursor(int amount)
Deletes the specified amount of characters.
|
void |
deleteSelectedText()
Deletes the text currently selected.
|
void |
deleteWord(boolean backwards)
Deletes the text from current cursor position to the next space.
|
void |
drawBackground(GuiRenderer renderer,
int mouseX,
int mouseY,
float partialTick)
Draws the background.
|
void |
drawCursor(GuiRenderer renderer)
Draws the cursor of this
UITextField . |
void |
drawForeground(GuiRenderer renderer,
int mouseX,
int mouseY,
float partialTick)
Draws the foreground.
|
void |
drawSelectionBox(GuiRenderer renderer)
Draw the selection box of this
UITextField . |
void |
drawText(GuiRenderer renderer)
Draws the text of this
UITextField . |
int |
getContentHeight()
Gets the content height.
|
int |
getContentWidth()
Gets the content width.
|
int |
getCursorColor() |
UITextField.CursorPosition |
getCursorPosition()
Gets the current cursor position.
|
float |
getFontScale()
Gets the font scale used by this
UITextField . |
int |
getHorizontalPadding()
Gets the horizontal padding.
|
int |
getLineHeight()
Gets the line height of this
UITextField . |
int |
getLineSpacing()
Gets the line spacing used when drawing.
|
float |
getOffsetX() |
float |
getOffsetY() |
java.lang.String |
getPropertyString()
Gets the property string.
|
UISlimScrollbar |
getScrollbar()
Gets the
UISlimScrollbar of this UITextField . |
float |
getScrollStep() |
int |
getSelectColor() |
java.lang.String |
getSelectedText()
Gets the currently selected text.
|
UITextField.CursorPosition |
getSelectionPosition()
Gets the selection position.
|
java.lang.String |
getText()
Gets the text of this
UITextField . |
int |
getTextColor() |
int |
getVerticalPadding()
Gets the vertical padding.
|
int |
getVisibleLines()
Gets the number of visible lines inside this
UITextField . |
protected boolean |
handleCtrlKeyDown(int keyCode)
Handles the key typed while a control key is pressed.
|
boolean |
isEditable() |
boolean |
isTextShadow() |
boolean |
onButtonPress(int x,
int y,
MouseButton button) |
boolean |
onButtonRelease(int x,
int y,
MouseButton button) |
protected void |
onCursorUpdated()
Called when a cursor is updated.
|
boolean |
onDoubleClick(int x,
int y,
MouseButton button) |
boolean |
onDrag(int lastX,
int lastY,
int x,
int y,
MouseButton button) |
boolean |
onKeyTyped(char keyChar,
int keyCode)
Called when a key is typed while this
UIComponent is focused or hovered. |
void |
selectWord() |
void |
selectWord(int position) |
UITextField |
setAutoSelectOnFocus(boolean auto)
Sets whether this
UITextField should automatically select its text when focused. |
UITextField |
setCursorColor(int cursorColor) |
void |
setCursorPosition(int x,
int y)
Sets the position of the cursor at the specified cooridnates.
|
UITextField |
setEditable(boolean editable) |
void |
setFocused(boolean focused)
Sets the focused.
|
UITextField |
setFontScale(float fontScale)
Sets the font scale for this
UITextField . |
void |
setLineOffset(int line)
Sets the line offset.
|
UITextField |
setLineSpacing(int lineSpacing)
Sets the line spacing for this
UITextField . |
void |
setOffsetX(float offsetX,
int delta)
Sets the offset x.
|
void |
setOffsetY(float offsetY,
int delta)
Sets the offset y.
|
UITextField |
setOptions(int textColor,
int bgColor,
int cursorColor,
int selectColor,
boolean textShadow) |
UITextField |
setSelectColor(int selectColor) |
UITextField |
setSize(int width,
int height)
Sets the size of this
UITextField . |
void |
setText(java.lang.String text)
Sets the text of this
UITextField and place the cursor at the end. |
UITextField |
setTextColor(int color) |
UITextField |
setTextShadow(boolean textShadow) |
protected void |
startSelecting()
Starts selecting text if Shift key is pressed.
|
protected boolean |
validateText(java.lang.String text)
Checks against if text is valid.
|
addControlComponent, componentX, componentY, draw, fireEvent, getAlpha, getAnchor, getComponentAt, getGui, getHeight, getName, getParent, getRawHeight, getRawWidth, getTooltip, getWidth, getX, getY, getZIndex, isDisabled, isFocused, isHovered, isInsideBounds, isRelativeHeight, isRelativeWidth, isVisible, onAddedToScreen, onClick, onMouseMove, onRightClick, onScrollWheel, parentX, parentY, register, relativeX, relativeY, removeAllControlComponents, removeControlComponent, screenX, screenY, setAlpha, setAnchor, setDisabled, setHovered, setName, setParent, setPosition, setPosition, setTooltip, setTooltip, setVisible, setZIndex, toString, unregister
protected java.lang.StringBuilder text
UITextField
.protected java.util.List<java.lang.String> lines
multiLine
is true
.protected boolean multiLine
UITextField
handles multiline text.protected int charOffset
UITextField
when drawn.protected int lineOffset
UITextField
when drawn. Always 0 if multiLine
is falseprotected int lineSpacing
protected float fontScale
protected boolean selectingText
protected UITextField.CursorPosition cursorPosition
protected UITextField.CursorPosition selectionPosition
protected long startTimer
protected boolean autoSelectOnFocus
UITextField
should auto select the text when gaining focus.protected boolean editable
UITextField
is editable.protected UISlimScrollbar scrollBar
protected int textColor
UITextField
.protected int bgColor
UITextField
.protected int cursorColor
UITextField
.protected int selectColor
UITextField
.protected boolean textShadow
protected GuiShape cursorShape
UITextField
.protected GuiShape selectShape
protected GuiIcon iconTextfield
UITextField
.protected GuiIcon iconTextfieldDisabled
UITextField
when disabled.public UITextField(MalisisGui gui, java.lang.String text, boolean multiLine)
UITextField
.gui
- the guitext
- the textmultiLine
- whether the textfield handles multiple linespublic UITextField(MalisisGui gui, java.lang.String text)
UITextField
.gui
- the guitext
- the textpublic UITextField(MalisisGui gui, boolean multiLine)
UITextField
.gui
- the guimultiLine
- the multi lineprotected void createShape(MalisisGui gui)
UITextField
.gui
- the guipublic java.lang.String getText()
UITextField
.public void setText(java.lang.String text)
UITextField
and place the cursor at the end.text
- the new textpublic java.lang.String getSelectedText()
public int getTextColor()
public UITextField setTextColor(int color)
public int getCursorColor()
public UITextField setCursorColor(int cursorColor)
public int getSelectColor()
public UITextField setSelectColor(int selectColor)
public boolean isTextShadow()
public UITextField setTextShadow(boolean textShadow)
public UITextField setOptions(int textColor, int bgColor, int cursorColor, int selectColor, boolean textShadow)
public UITextField setSize(int width, int height)
setSize
in interface ITransformable.Size<UITextField>
setSize
in class UIComponent<UITextField>
width
- the widthheight
- the heightpublic void setFocused(boolean focused)
setFocused
in class UIComponent<UITextField>
focused
- the new focusedpublic UITextField setFontScale(float fontScale)
UITextField
.fontScale
- the font scaleUITextField
public float getFontScale()
UITextField
.public int getLineSpacing()
public UITextField setLineSpacing(int lineSpacing)
UITextField
.lineSpacing
- the lineSpacing to setUITextField
public void setLineOffset(int line)
line
- the new line offsetpublic UITextField.CursorPosition getCursorPosition()
public UITextField.CursorPosition getSelectionPosition()
public void setCursorPosition(int x, int y)
x
- the x coordinatey
- the y coordinatepublic UITextField setAutoSelectOnFocus(boolean auto)
UITextField
should automatically select its text
when focused.auto
- the autoUITextField
public boolean isEditable()
public UITextField setEditable(boolean editable)
public UISlimScrollbar getScrollbar()
UISlimScrollbar
of this UITextField
.public int getContentWidth()
getContentWidth
in interface IScrollable
public int getContentHeight()
getContentHeight
in interface IScrollable
public float getOffsetX()
getOffsetX
in interface IScrollable
public void setOffsetX(float offsetX, int delta)
setOffsetX
in interface IScrollable
offsetX
- the offset xdelta
- the deltapublic float getOffsetY()
getOffsetY
in interface IScrollable
public void setOffsetY(float offsetY, int delta)
setOffsetY
in interface IScrollable
offsetY
- the offset ydelta
- the deltapublic float getScrollStep()
getScrollStep
in interface IScrollable
public int getVerticalPadding()
getVerticalPadding
in interface IScrollable
public int getHorizontalPadding()
getHorizontalPadding
in interface IScrollable
public int getVisibleLines()
UITextField
.public int getLineHeight()
UITextField
.protected void buildLines()
UITextField
.protected boolean validateText(java.lang.String text)
text
- the textpublic void addText(java.lang.String str)
str
- the textpublic void deleteSelectedText()
public void deleteFromCursor(int amount)
amount
- the amount of characters to deletepublic void deleteWord(boolean backwards)
backwards
- whether to look left for the next spacepublic void selectWord()
public void selectWord(int position)
protected void onCursorUpdated()
protected void startSelecting()
public boolean onButtonPress(int x, int y, MouseButton button)
onButtonPress
in class UIComponent<UITextField>
public boolean onButtonRelease(int x, int y, MouseButton button)
onButtonRelease
in class UIComponent<UITextField>
public boolean onDrag(int lastX, int lastY, int x, int y, MouseButton button)
onDrag
in class UIComponent<UITextField>
public boolean onDoubleClick(int x, int y, MouseButton button)
onDoubleClick
in class UIComponent<UITextField>
public boolean onKeyTyped(char keyChar, int keyCode)
UIComponent
UIComponent
is focused or hovered.onKeyTyped
in class UIComponent<UITextField>
keyChar
- the key charkeyCode
- the key codeprotected boolean handleCtrlKeyDown(int keyCode)
keyCode
- the key codepublic void drawBackground(GuiRenderer renderer, int mouseX, int mouseY, float partialTick)
drawBackground
in class UIComponent<UITextField>
renderer
- the renderermouseX
- the mouse xmouseY
- the mouse ypartialTick
- the partial tickpublic void drawForeground(GuiRenderer renderer, int mouseX, int mouseY, float partialTick)
drawForeground
in class UIComponent<UITextField>
renderer
- the renderermouseX
- the mouse xmouseY
- the mouse ypartialTick
- the partial tickpublic void drawText(GuiRenderer renderer)
UITextField
.renderer
- the rendererpublic void drawCursor(GuiRenderer renderer)
UITextField
.renderer
- the rendererpublic void drawSelectionBox(GuiRenderer renderer)
UITextField
.renderer
- the rendererpublic java.lang.String getPropertyString()
getPropertyString
in class UIComponent<UITextField>