Class TextFieldComponent
java.lang.Object
de.gurkenlabs.litiengine.gui.GuiComponent
de.gurkenlabs.litiengine.gui.ImageComponent
de.gurkenlabs.litiengine.gui.TextFieldComponent
- All Implemented Interfaces:
IRenderable, Tweenable, MouseListener, MouseMotionListener, MouseWheelListener, EventListener
- Direct Known Subclasses:
Spinner
A single-line text input GUI component. Supports input filtering through a regex format, a maximum length, a flickering
caret while focused, and confirmation listeners that fire when the user presses
ENTER/ESC or clicks outside the component.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringRegex matching signed decimal numbers including scientific notation.static final StringRegex matching positive integers up to 10 digits.Fields inherited from class ImageComponent
BACKGROUND_DISABLED_INDEX, BACKGROUND_HOVER_INDEX, BACKGROUND_INDEX, BACKGROUND_PRESSED_INDEXFields inherited from class GuiComponent
ICON_FONT -
Constructor Summary
ConstructorsConstructorDescriptionTextFieldComponent(double x, double y, double width, double height, String text) Constructs a newTextFieldComponent. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns whether this component is currently in a state in which it should accept user input.Gets the string rendered as the caret while the field is focused.Gets the regex pattern used to filter typed input.intGets the maximum number of characters allowed in the field, or0if unlimited.getText()Gets the entire Text associated with this GuiComponent.Gets only the non-cropped bits of Text visible on this GuiComponent.m To retrieve only the entire text associated with this GuiComponent, useGuiComponent.getText().voidhandleTypedKey(KeyEvent event) Handles a key typed event by dispatching to the relevant editing routine (backspace, accept, or normal typing).voidonChangeConfirmed(Consumer<String> cons) Registers a callback that is invoked with the current text whenever the user confirms the input (by pressingENTER/ESCor clicking outside the component).voidrender(Graphics2D g) Renders the component using the provided Graphics2D context.voidSets the string rendered as the caret while the field is focused.voidsetFlickerDelay(int flickerDelayMillis) Sets the delay (in milliseconds) between caret flicker toggles.voidSets the regex pattern used to filter typed input.voidsetMaxLength(int maxLength) Sets the maximum number of characters allowed in the field.voidSets the text.Methods inherited from class ImageComponent
getBackground, getHorizontalImagePadding, getImage, getImageAlign, getImageScaleInterpolation, getImageScaleMode, getImageValign, getSpritesheet, getSpritesheetScaleFactor, getSpritesheetScaleInterpolation, getSpritesheetScaleMode, getVerticalImagePadding, rescaleImage, setHeight, setHorizontalImagePadding, setImage, setImageAlign, setImageScaleInterpolation, setImageScaleMode, setImageValign, setSpritesheet, setSpritesheet, setSpritesheet, setSpritesheetScaleFactor, setSpritesheetScaleInterpolation, setSpritesheetScaleMode, setVerticalImagePadding, setWidthMethods inherited from class GuiComponent
addRenderedListener, addRenderListener, getAppearance, getAppearanceDisabled, getAppearanceHovered, getBoundingBox, getCenterX, getCenterY, getClickConsumer, getComponentId, getComponents, getCurrentAppearance, getFocusedComponent, getFont, getHeight, getHoverConsumer, getHoverSound, getLocation, getMouseDraggedConsumer, getMouseEnterConsumer, getMouseLeaveConsumer, getMouseMovedConsumer, getMousePressedConsumer, getMouseReleasedConsumer, getMouseWheelConsumer, getName, getShape, getTag, getTextAlign, getTextAngle, getTextShadowColor, getTextShadowRadius, getTextValign, getTextX, getTextY, getTweenValues, getWidth, getX, getY, hasAutomaticLineBreaks, hasInputFocus, hasTextAntialiasing, hasTextShadow, initializeComponents, isAutoScaling, isEnabled, isFocusable, isForwardMouseEvents, isHovered, isPressed, isSelected, isSuspended, isVisible, mouseClicked, mouseDragged, mouseEntered, mouseEventShouldBeForwarded, mouseExited, mouseMoved, mousePressed, mouseReleased, mouseWheelMoved, onClicked, onHovered, onMouseDragged, onMouseEnter, onMouseLeave, onMouseMoved, onMousePressed, onMouseReleased, onMouseWheelScrolled, onResolutionChanged, onTextChanged, prepare, removeListener, removeListener, setAutomaticLineBreaks, setAutoScaling, setDimension, setEnabled, setFocusable, setFont, setFontSize, setForwardMouseEvents, setHovered, setHoverSound, setLocation, setLocation, setName, setSelected, setTag, setTextAlign, setTextAngle, setTextAntialiasing, setTextShadow, setTextShadowColor, setTextShadowRadius, setTextValign, setTextX, setTextY, setTweenValues, setVisible, setX, setY, suspend, toggleSelection, toggleSuspension
-
Field Details
-
DOUBLE_FORMAT
Regex matching signed decimal numbers including scientific notation.- See Also:
-
INTEGER_FORMAT
Regex matching positive integers up to 10 digits.- See Also:
-
-
Constructor Details
-
TextFieldComponent
Constructs a newTextFieldComponent.- Parameters:
x- the x coordinate of the componenty- the y coordinate of the componentwidth- the width of the componentheight- the height of the componenttext- the initial text content
-
-
Method Details
-
getFormat
Gets the regex pattern used to filter typed input.- Returns:
- the format pattern, or
nullif no filter is set
-
setFormat
Sets the regex pattern used to filter typed input.- Parameters:
format- the format pattern, ornullto disable filtering
-
getCursor
Gets the string rendered as the caret while the field is focused.- Returns:
- the caret string
-
setCursor
Sets the string rendered as the caret while the field is focused.- Parameters:
newCursor- the caret string
-
getMaxLength
public int getMaxLength()Gets the maximum number of characters allowed in the field, or0if unlimited.- Returns:
- the maximum length
-
setMaxLength
public void setMaxLength(int maxLength) Sets the maximum number of characters allowed in the field.- Parameters:
maxLength- the maximum length, or0for unlimited
-
getText
Description copied from class:GuiComponentGets the entire Text associated with this GuiComponent. Parts of the Text may get cropped and can therefore be invisible. To retrieve only the visible part of the text, useGuiComponent.getTextToRender(Graphics2D g).- Overrides:
getTextin classGuiComponent- Returns:
- the entire text on this GuiComponent
-
setText
Description copied from class:GuiComponentSets the text.- Overrides:
setTextin classGuiComponent- Parameters:
text- the new text
-
getTextToRender
Description copied from class:GuiComponentGets only the non-cropped bits of Text visible on this GuiComponent.m To retrieve only the entire text associated with this GuiComponent, useGuiComponent.getText().- Overrides:
getTextToRenderin classGuiComponent- Parameters:
g- The graphics object to render on.- Returns:
- the text to render
-
handleTypedKey
Handles a key typed event by dispatching to the relevant editing routine (backspace, accept, or normal typing).- Parameters:
event- the key event
-
canHandleInput
public boolean canHandleInput()Returns whether this component is currently in a state in which it should accept user input.- Returns:
trueif input can be handled
-
onChangeConfirmed
-
render
Description copied from class:ImageComponentRenders the component using the provided Graphics2D context. If the component is suspended or not visible, the method returns immediately. Otherwise, it renders the background image (if available) and the main image (if available), and then calls the superclass's render method.- Specified by:
renderin interfaceIRenderable- Overrides:
renderin classImageComponent- Parameters:
g- The Graphics2D context used for rendering.- See Also:
-
setFlickerDelay
public void setFlickerDelay(int flickerDelayMillis) Sets the delay (in milliseconds) between caret flicker toggles.- Parameters:
flickerDelayMillis- the flicker delay
-