LineEdit¶
Inherits: Control < CanvasItem < Node < Object
Control that provides single-line string editing.
Description¶
LineEdit provides a single-line string editor, used for text fields.
It features many built-in shortcuts which will always be available (Ctrl here maps to Cmd on macOS):
Ctrl + C: Copy
Ctrl + X: Cut
Ctrl + V or Ctrl + Y: Paste/"yank"
Ctrl + Z: Undo
Ctrl + ~: Swap input direction.
Ctrl + Shift + Z: Redo
Ctrl + U: Delete text from the caret position to the beginning of the line
Ctrl + K: Delete text from the caret position to the end of the line
Ctrl + A: Select all text
Up Arrow/Down Arrow: Move the caret to the beginning/end of the line
On macOS, some extra keyboard shortcuts are available:
Ctrl + F: Same as Right Arrow, move the caret one character right
Ctrl + B: Same as Left Arrow, move the caret one character left
Ctrl + P: Same as Up Arrow, move the caret to the previous line
Ctrl + N: Same as Down Arrow, move the caret to the next line
Ctrl + D: Same as Delete, delete the character on the right side of caret
Ctrl + H: Same as Backspace, delete the character on the left side of the caret
Ctrl + A: Same as Home, move the caret to the beginning of the line
Ctrl + E: Same as End, move the caret to the end of the line
Cmd + Left Arrow: Same as Home, move the caret to the beginning of the line
Cmd + Right Arrow: Same as End, move the caret to the end of the line
Properties¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
focus_mode |
|
|
|
||
|
||
|
||
mouse_default_cursor_shape |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Methods¶
void |
clear ( ) |
void |
|
void |
|
void |
delete_text ( int from_column, int to_column ) |
void |
deselect ( ) |
get_menu ( ) const |
|
get_opentype_feature ( String tag ) const |
|
get_scroll_offset ( ) const |
|
get_selection_from_column ( ) const |
|
get_selection_to_column ( ) const |
|
has_selection ( ) const |
|
void |
insert_text_at_caret ( String text ) |
is_menu_visible ( ) const |
|
void |
menu_option ( int option ) |
void |
|
void |
select_all ( ) |
void |
set_opentype_feature ( String tag, int value ) |
Theme Properties¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Signals¶
text_change_rejected ( String rejected_substring )
Emitted when appending text that overflows the max_length. The appended text is truncated to fit max_length, and the part that couldn't fit is passed as the rejected_substring
argument.
text_changed ( String new_text )
Emitted when the text changes.
text_submitted ( String new_text )
Emitted when the user presses @GlobalScope.KEY_ENTER on the LineEdit
.
Enumerations¶
MENU_CUT = 0 --- Cuts (copies and clears) the selected text.
MENU_COPY = 1 --- Copies the selected text.
MENU_PASTE = 2 --- Pastes the clipboard text over the selected text (or at the caret's position).
Non-printable escape characters are automatically stripped from the OS clipboard via String.strip_escapes.
MENU_CLEAR = 3 --- Erases the whole
LineEdit
text.MENU_SELECT_ALL = 4 --- Selects the whole
LineEdit
text.MENU_UNDO = 5 --- Undoes the previous action.
MENU_REDO = 6 --- Reverse the last undo action.
MENU_DIR_INHERITED = 7 --- Sets text direction to inherited.
MENU_DIR_AUTO = 8 --- Sets text direction to automatic.
MENU_DIR_LTR = 9 --- Sets text direction to left-to-right.
MENU_DIR_RTL = 10 --- Sets text direction to right-to-left.
MENU_DISPLAY_UCC = 11 --- Toggles control character display.
MENU_INSERT_LRM = 12 --- Inserts left-to-right mark (LRM) character.
MENU_INSERT_RLM = 13 --- Inserts right-to-left mark (RLM) character.
MENU_INSERT_LRE = 14 --- Inserts start of left-to-right embedding (LRE) character.
MENU_INSERT_RLE = 15 --- Inserts start of right-to-left embedding (RLE) character.
MENU_INSERT_LRO = 16 --- Inserts start of left-to-right override (LRO) character.
MENU_INSERT_RLO = 17 --- Inserts start of right-to-left override (RLO) character.
MENU_INSERT_PDF = 18 --- Inserts pop direction formatting (PDF) character.
MENU_INSERT_ALM = 19 --- Inserts Arabic letter mark (ALM) character.
MENU_INSERT_LRI = 20 --- Inserts left-to-right isolate (LRI) character.
MENU_INSERT_RLI = 21 --- Inserts right-to-left isolate (RLI) character.
MENU_INSERT_FSI = 22 --- Inserts first strong isolate (FSI) character.
MENU_INSERT_PDI = 23 --- Inserts pop direction isolate (PDI) character.
MENU_INSERT_ZWJ = 24 --- Inserts zero width joiner (ZWJ) character.
MENU_INSERT_ZWNJ = 25 --- Inserts zero width non-joiner (ZWNJ) character.
MENU_INSERT_WJ = 26 --- Inserts word joiner (WJ) character.
MENU_INSERT_SHY = 27 --- Inserts soft hyphen (SHY) character.
MENU_MAX = 28 --- Represents the size of the MenuItems enum.
Property Descriptions¶
HorizontalAlignment alignment
Default |
|
Setter |
set_horizontal_alignment(value) |
Getter |
get_horizontal_alignment() |
Text alignment as defined in the HorizontalAlignment enum.
bool caret_blink
Default |
|
Setter |
set_caret_blink_enabled(value) |
Getter |
is_caret_blink_enabled() |
If true
, the caret (text cursor) blinks.
float caret_blink_speed
Default |
|
Setter |
set_caret_blink_speed(value) |
Getter |
get_caret_blink_speed() |
Duration (in seconds) of a caret's blinking cycle.
int caret_column
Default |
|
Setter |
set_caret_column(value) |
Getter |
get_caret_column() |
The caret's column position inside the LineEdit
. When set, the text may scroll to accommodate it.
bool caret_force_displayed
Default |
|
Setter |
set_caret_force_displayed(value) |
Getter |
is_caret_force_displayed() |
If true
, the LineEdit
will always show the caret, even if focus is lost.
bool caret_mid_grapheme
Default |
|
Setter |
set_caret_mid_grapheme_enabled(value) |
Getter |
is_caret_mid_grapheme_enabled() |
Allow moving caret, selecting and removing the individual composite character components.
Note: Backspace is always removing individual composite character components.
bool clear_button_enabled
Default |
|
Setter |
set_clear_button_enabled(value) |
Getter |
is_clear_button_enabled() |
If true
, the LineEdit
will show a clear button if text
is not empty, which can be used to clear the text quickly.
Default |
|
Setter |
set_context_menu_enabled(value) |
Getter |
is_context_menu_enabled() |
If true
, the context menu will appear when right-clicked.
bool deselect_on_focus_loss_enabled
Default |
|
Setter |
set_deselect_on_focus_loss_enabled(value) |
Getter |
is_deselect_on_focus_loss_enabled() |
If true
, the selected text will be deselected when focus is lost.
bool draw_control_chars
Default |
|
Setter |
set_draw_control_chars(value) |
Getter |
get_draw_control_chars() |
If true
, control characters are displayed.
bool editable
Default |
|
Setter |
set_editable(value) |
Getter |
is_editable() |
If false
, existing text cannot be modified and new text cannot be added.
bool expand_to_text_length
Default |
|
Setter |
set_expand_to_text_length_enabled(value) |
Getter |
is_expand_to_text_length_enabled() |
If true
, the LineEdit
width will increase to stay longer than the text. It will not compress if the text is shortened.
bool flat
Default |
|
Setter |
set_flat(value) |
Getter |
is_flat() |
If true
, the LineEdit
don't display decoration.
String language
Default |
|
Setter |
set_language(value) |
Getter |
get_language() |
Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead.
int max_length
Default |
|
Setter |
set_max_length(value) |
Getter |
get_max_length() |
Maximum amount of characters that can be entered inside the LineEdit
. If 0
, there is no limit.
When a limit is defined, characters that would exceed max_length are truncated. This happens both for existing text contents when setting the max length, or for new text inserted in the LineEdit
, including pasting. If any input text is truncated, the text_change_rejected signal is emitted with the truncated substring as parameter.
Example:
text = "Hello world"
max_length = 5
# `text` becomes "Hello".
max_length = 10
text += " goodbye"
# `text` becomes "Hello good".
# `text_change_rejected` is emitted with "bye" as parameter.
Text = "Hello world";
MaxLength = 5;
// `Text` becomes "Hello".
MaxLength = 10;
Text += " goodbye";
// `Text` becomes "Hello good".
// `text_change_rejected` is emitted with "bye" as parameter.
bool middle_mouse_paste_enabled
Default |
|
Setter |
set_middle_mouse_paste_enabled(value) |
Getter |
is_middle_mouse_paste_enabled() |
If false
, using middle mouse button to paste clipboard will be disabled.
Note: This method is only implemented on Linux.
String placeholder_text
Default |
|
Setter |
set_placeholder(value) |
Getter |
get_placeholder() |
Text shown when the LineEdit
is empty. It is not the LineEdit
's default value (see text).
Texture2D right_icon
Setter |
set_right_icon(value) |
Getter |
get_right_icon() |
Sets the icon that will appear in the right end of the LineEdit
if there's no text, or always, if clear_button_enabled is set to false
.
bool secret
Default |
|
Setter |
set_secret(value) |
Getter |
is_secret() |
If true
, every character is replaced with the secret character (see secret_character).
String secret_character
Default |
|
Setter |
set_secret_character(value) |
Getter |
get_secret_character() |
The character to use to mask secret input (defaults to "*"). Only a single character can be used as the secret character.
bool selecting_enabled
Default |
|
Setter |
set_selecting_enabled(value) |
Getter |
is_selecting_enabled() |
If false
, it's impossible to select the text using mouse nor keyboard.
bool shortcut_keys_enabled
Default |
|
Setter |
set_shortcut_keys_enabled(value) |
Getter |
is_shortcut_keys_enabled() |
If false
, using shortcuts will be disabled.
StructuredTextParser structured_text_bidi_override
Default |
|
Setter |
set_structured_text_bidi_override(value) |
Getter |
get_structured_text_bidi_override() |
Set BiDi algorithm override for the structured text.
Array structured_text_bidi_override_options
Default |
|
Setter |
set_structured_text_bidi_override_options(value) |
Getter |
get_structured_text_bidi_override_options() |
Set additional options for BiDi override.
String text
Default |
|
Setter |
set_text(value) |
Getter |
get_text() |
String value of the LineEdit
.
Note: Changing text using this property won't emit the text_changed signal.
TextDirection text_direction
Default |
|
Setter |
set_text_direction(value) |
Getter |
get_text_direction() |
Base text writing direction.
bool virtual_keyboard_enabled
Default |
|
Setter |
set_virtual_keyboard_enabled(value) |
Getter |
is_virtual_keyboard_enabled() |
If true
, the native virtual keyboard is shown when focused on platforms that support it.
Method Descriptions¶
void clear ( )
Erases the LineEdit
's text.
void clear_opentype_features ( )
Removes all OpenType features.
void delete_char_at_caret ( )
Deletes one character at the caret's current position (equivalent to pressing Delete).
Deletes a section of the text going from position from_column
to to_column
. Both parameters should be within the text's length.
void deselect ( )
Clears the current selection.
Returns the PopupMenu of this LineEdit
. By default, this menu is displayed when right-clicking on the LineEdit
.
Warning: This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their Window.visible property.
Returns OpenType feature tag
.
int get_scroll_offset ( ) const
Returns the scroll offset due to caret_column, as a number of characters.
int get_selection_from_column ( ) const
Returns the selection begin column.
int get_selection_to_column ( ) const
Returns the selection end column.
bool has_selection ( ) const
Returns true
if the user has selected text.
void insert_text_at_caret ( String text )
Inserts text
at the caret. If the resulting value is longer than max_length, nothing happens.
Returns whether the menu is visible. Use this instead of get_menu().visible
to improve performance (so the creation of the menu is avoided).
Executes a given action as defined in the MenuItems enum.
Selects characters inside LineEdit
between from
and to
. By default, from
is at the beginning and to
at the end.
text = "Welcome"
select() # Will select "Welcome".
select(4) # Will select "ome".
select(2, 5) # Will select "lco".
Text = "Welcome";
Select(); // Will select "Welcome".
Select(4); // Will select "ome".
Select(2, 5); // Will select "lco".
void select_all ( )
Selects the whole String.
Returns OpenType feature tag
. More info: OpenType feature tags.
Theme Property Descriptions¶
Color caret_color
Default |
|
Color of the LineEdit
's caret (text cursor). This can be set to a fully transparent color to hide the caret entirely.
Color clear_button_color
Default |
|
Color used as default tint for the clear button.
Color clear_button_color_pressed
Default |
|
Color used for the clear button when it's pressed.
Color font_color
Default |
|
Default font color.
Color font_outline_color
Default |
|
The tint of text outline of the LineEdit
.
Color font_placeholder_color
Default |
|
Font color for placeholder_text.
Color font_selected_color
Default |
|
Font color for selected text (inside the selection rectangle).
Color font_uneditable_color
Default |
|
Font color when editing is disabled.
Color selection_color
Default |
|
Color of the selection rectangle.
int caret_width
Default |
|
The caret's width in pixels. Greater values can be used to improve accessibility by ensuring the caret is easily visible, or to ensure consistency with a large font size.
int minimum_character_width
Default |
|
Minimum horizontal space for the text (not counting the clear button and content margins). This value is measured in count of 'M' characters (i.e. this amount of 'M' characters can be displayed without scrolling).
int outline_size
Default |
|
The size of the text outline.
Font font
Font used for the text.
int font_size
Font size of the LineEdit
's text.
Texture2D clear
Texture for the clear button. See clear_button_enabled.
StyleBox focus
Background used when LineEdit
has GUI focus. The focus
StyleBox is displayed over the base StyleBox, so a partially transparent StyleBox should be used to ensure the base StyleBox remains visible. A StyleBox that represents an outline or an underline works well for this purpose. To disable the focus visual effect, assign a StyleBoxEmpty resource. Note that disabling the focus visual effect will harm keyboard/controller navigation usability, so this is not recommended for accessibility reasons.
StyleBox normal
Default background for the LineEdit
.
StyleBox read_only
Background used when LineEdit
is in read-only mode (editable is set to false
).