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 |
delete_text ( int from_column, int to_column ) |
void |
deselect ( ) |
get_menu ( ) 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 ( ) |
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¶
Cuts (copies and clears) the selected text.
Copies the selected text.
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.
Erases the whole LineEdit text.
Selects the whole LineEdit text.
Undoes the previous action.
Reverse the last undo action.
ID of "Text Writing Direction" submenu.
Sets text direction to inherited.
Sets text direction to automatic.
Sets text direction to left-to-right.
Sets text direction to right-to-left.
Toggles control character display.
ID of "Insert Control Character" submenu.
Inserts left-to-right mark (LRM) character.
Inserts right-to-left mark (RLM) character.
Inserts start of left-to-right embedding (LRE) character.
Inserts start of right-to-left embedding (RLE) character.
Inserts start of left-to-right override (LRO) character.
Inserts start of right-to-left override (RLO) character.
Inserts pop direction formatting (PDF) character.
Inserts Arabic letter mark (ALM) character.
Inserts left-to-right isolate (LRI) character.
Inserts right-to-left isolate (RLI) character.
Inserts first strong isolate (FSI) character.
Inserts pop direction isolate (PDI) character.
Inserts zero width joiner (ZWJ) character.
Inserts zero width non-joiner (ZWNJ) character.
Inserts word joiner (WJ) character.
Inserts soft hyphen (SHY) character.
Represents the size of the MenuItems enum.
enum VirtualKeyboardType:
VirtualKeyboardType KEYBOARD_TYPE_DEFAULT = 0
Default text virtual keyboard.
VirtualKeyboardType KEYBOARD_TYPE_MULTILINE = 1
Multiline virtual keyboard.
VirtualKeyboardType KEYBOARD_TYPE_NUMBER = 2
Virtual number keypad, useful for PIN entry.
VirtualKeyboardType KEYBOARD_TYPE_NUMBER_DECIMAL = 3
Virtual number keypad, useful for entering fractional numbers.
VirtualKeyboardType KEYBOARD_TYPE_PHONE = 4
Virtual phone number keypad.
VirtualKeyboardType KEYBOARD_TYPE_EMAIL_ADDRESS = 5
Virtual keyboard with additional keys to assist with typing email addresses.
VirtualKeyboardType KEYBOARD_TYPE_PASSWORD = 6
Virtual keyboard for entering a password. On most platforms, this should disable autocomplete and autocapitalization.
Note: This is not supported on Web. Instead, this behaves identically to KEYBOARD_TYPE_DEFAULT.
VirtualKeyboardType KEYBOARD_TYPE_URL = 7
Virtual keyboard with additional keys to assist with typing URLs.
Property Descriptions¶
HorizontalAlignment alignment = 0
void set_horizontal_alignment ( HorizontalAlignment value )
HorizontalAlignment get_horizontal_alignment ( )
Text alignment as defined in the HorizontalAlignment enum.
bool caret_blink = false
If true
, the caret (text cursor) blinks.
float caret_blink_interval = 0.65
Duration (in seconds) of a caret's blinking cycle.
int caret_column = 0
The caret's column position inside the LineEdit. When set, the text may scroll to accommodate it.
bool caret_force_displayed = false
If true
, the LineEdit will always show the caret, even if focus is lost.
bool caret_mid_grapheme = true
Allow moving caret, selecting and removing the individual composite character components.
Note: Backspace is always removing individual composite character components.
bool clear_button_enabled = false
If true
, the LineEdit will show a clear button if text
is not empty, which can be used to clear the text quickly.
If true
, the context menu will appear when right-clicked.
bool deselect_on_focus_loss_enabled = true
If true
, the selected text will be deselected when focus is lost.
bool draw_control_chars = false
If true
, control characters are displayed.
bool editable = true
If false
, existing text cannot be modified and new text cannot be added.
bool expand_to_text_length = false
If true
, the LineEdit width will increase to stay longer than the text. It will not compress if the text is shortened.
bool flat = false
If true
, the LineEdit don't display decoration.
String language = ""
Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead.
int max_length = 0
Maximum number 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 = true
If false
, using middle mouse button to paste clipboard will be disabled.
Note: This method is only implemented on Linux.
String placeholder_text = ""
Text shown when the LineEdit is empty. It is not the LineEdit's default value (see text).
Texture2D 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 = false
If true
, every character is replaced with the secret character (see secret_character).
String secret_character = "•"
The character to use to mask secret input (defaults to "•"). Only a single character can be used as the secret character.
bool select_all_on_focus = false
If true
, the LineEdit will select the whole text when it gains focus.
bool selecting_enabled = true
If false
, it's impossible to select the text using mouse nor keyboard.
bool shortcut_keys_enabled = true
If false
, using shortcuts will be disabled.
StructuredTextParser structured_text_bidi_override = 0
void set_structured_text_bidi_override ( StructuredTextParser value )
StructuredTextParser get_structured_text_bidi_override ( )
Set BiDi algorithm override for the structured text.
Array structured_text_bidi_override_options = []
void set_structured_text_bidi_override_options ( Array value )
Array get_structured_text_bidi_override_options ( )
Set additional options for BiDi override.
String text = ""
String value of the LineEdit.
Note: Changing text using this property won't emit the text_changed signal.
TextDirection text_direction = 0
void set_text_direction ( TextDirection value )
TextDirection get_text_direction ( )
Base text writing direction.
bool virtual_keyboard_enabled = true
If true
, the native virtual keyboard is shown when focused on platforms that support it.
VirtualKeyboardType virtual_keyboard_type = 0
void set_virtual_keyboard_type ( VirtualKeyboardType value )
VirtualKeyboardType get_virtual_keyboard_type ( )
Specifies the type of virtual keyboard to show.
Method Descriptions¶
void clear ( )
Erases the LineEdit's text.
void delete_char_at_caret ( )
Deletes one character at the caret's current position (equivalent to pressing Delete).
void delete_text ( int from_column, int to_column )
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.
You can add custom menu items or remove standard ones. Make sure your IDs don't conflict with the standard ones (see MenuItems). For example:
func _ready():
var menu = get_menu()
# Remove all items after "Redo".
menu.item_count = menu.get_item_index(MENU_REDO) + 1
# Add custom items.
menu.add_separator()
menu.add_item("Insert Date", MENU_MAX + 1)
# Connect callback.
menu.id_pressed.connect(_on_item_pressed)
func _on_item_pressed(id):
if id == MENU_MAX + 1:
insert_text_at_caret(Time.get_date_string_from_system())
public override void _Ready()
{
var menu = GetMenu();
// Remove all items after "Redo".
menu.ItemCount = menu.GetItemIndex(LineEdit.MenuItems.Redo) + 1;
// Add custom items.
menu.AddSeparator();
menu.AddItem("Insert Date", LineEdit.MenuItems.Max + 1);
// Add event handler.
menu.IdPressed += OnItemPressed;
}
public void OnItemPressed(int id)
{
if (id == LineEdit.MenuItems.Max + 1)
{
InsertTextAtCaret(