TextField
Editable text input with focus, cursor, placeholder, and change callbacks.
Module: graphite
Editable text input with focus, cursor, placeholder, and change callbacks.
Declaration
export class TextField extends UIObject { ... }Extends: UIObject
Constructors
Creates a new text field.
constructor();Creates a new text field.
constructor(
font: Font,
maximumWidth: number,
position: Position2d,
text: string,
placeholder: string,
);Properties
text
The text.
text: string;placeholder
The placeholder.
placeholder: string;font
The font.
font: Font;position
The position in world space.
position: Position3d;fontSize
The font size.
fontSize: number;padding
The padding.
padding: Size2d;maximumWidth
The maximum width.
maximumWidth: number;textColor
The text color.
textColor: Color;placeholderColor
The placeholder color.
placeholderColor: Color;backgroundColor
The background color.
backgroundColor: Color;borderColor
The border color.
borderColor: Color;focusedBorderColor
The focused border color.
focusedBorderColor: Color;cursorColor
The cursor color.
cursorColor: Color;Methods
getSize
Returns the current dimensions.
override getSize(): Size2d;getScreenPosition
Returns the UI element's screen-space position.
override getScreenPosition(): Position2d;setScreenPosition
Sets the UI element's screen-space position.
override setScreenPosition(position: Position2d): void;getText
Returns text.
getText(): string;isFocused
Reports whether focused.
isFocused(): boolean;getCursorIndex
Returns cursor index.
getCursorIndex(): number;style
Returns the element's style.
style(): UIStyle;setText
Sets text.
setText(text: string): TextField;setPlaceholder
Sets placeholder.
setPlaceholder(placeholder: string): TextField;setPadding
Sets padding.
setPadding(padding: Size2d): TextField;setMaximumWidth
Sets maximum width.
setMaximumWidth(width: number): TextField;setFontSize
Sets font size.
setFontSize(size: number): TextField;setStyle
Applies a style to the element.
setStyle(style: UIStyle): TextField;setOnChange
Registers the text-change callback and returns this text field for chaining.
setOnChange(callback: TextField.ChangeCallback): TextField;focus
Gives keyboard focus to the text field.
focus(): void;blur
Removes keyboard focus from the text field.
blur(): void;