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 Command
on macOS):
Ctrl + C: Copy
Ctrl + X: Cut
Ctrl + V or Ctrl + Y: Paste/"yank"
Ctrl + Z: Undo
Ctrl + Shift + Z: Redo
Ctrl + U: Delete text from the cursor position to the beginning of the line
Ctrl + K: Delete text from the cursor position to the end of the line
Ctrl + A: Select all text
Up Arrow/Down arrow: Move the cursor to the beginning/end of the line
On macOS, some extra keyboard shortcuts are available:
Ctrl + F: Same as Right Arrow, move the cursor one character right
Ctrl + B: Same as Left Arrow, move the cursor one character left
Ctrl + P: Same as Up Arrow, move the cursor to the previous line
Ctrl + N: Same as Down Arrow, move the cursor to the next line
Ctrl + D: Same as Delete, delete the character on the right side of cursor
Ctrl + H: Same as Backspace, delete the character on the left side of the cursor
Cmd + Left arrow: Same as Home, move the cursor to the beginning of the line
Cmd + Right arrow: Same as End, move the cursor to the end of the line
Properties¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
focus_mode |
|
|
|
||
|
||
mouse_default_cursor_shape |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Methods¶
void |
append_at_cursor ( String text ) |
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 |
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_entered ( String new_text )
Emitted when the user presses @GlobalScope.KEY_ENTER on the LineEdit.
Enumerations¶
enum Align:
Align ALIGN_LEFT = 0
Aligns the text on the left-hand side of the LineEdit.
Align ALIGN_CENTER = 1
Centers the text in the middle of the LineEdit.
Align ALIGN_RIGHT = 2
Aligns the text on the right-hand side of the LineEdit.
Align ALIGN_FILL = 3
Stretches whitespaces to fit the LineEdit's width.
Cuts (copies and clears) the selected text.
Copies the selected text.
Pastes the clipboard text over the selected text (or at the cursor'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.
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 HTML5 or below iOS version 11.0. Instead, this will behave identically to KEYBOARD_TYPE_DEFAULT.
VirtualKeyboardType KEYBOARD_TYPE_URL = 7
Virtual keyboard with additional keys to assist with typing URLs.
Property Descriptions¶
Align align = 0
Text alignment as defined in the Align enum.
bool caret_blink = false
If true
, the caret (visual cursor) blinks.
float caret_blink_speed = 0.65
Duration (in seconds) of a caret's blinking cycle.
int caret_position = 0
The cursor's position inside the LineEdit. When set, the text may scroll to accommodate it.
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 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.
int max_length = 0
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.
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.
float placeholder_alpha = 0.6
Opacity of the placeholder_text. From 0
to 1
.
String placeholder_text = ""
Text shown when the LineEdit is empty. It is not the LineEdit's default value (see text).
Texture 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 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.
String text = ""
String value of the LineEdit.
Note: Changing text using this property won't emit the text_changed signal.
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 append_at_cursor ( String text )
Adds text
after the cursor. If the resulting value is longer than max_length, nothing happens.
void clear ( )
Erases the LineEdit's text.
void delete_char_at_cursor ( )
Deletes one character at the cursor's current position (equivalent to pressing the Delete
key).
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.
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 CanvasItem.visible property.
int get_scroll_offset ( ) const
Returns the scroll offset due to caret_position, 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.
Executes a given action as defined in the MenuItems enum.
void select ( int from=0, int to=-1 )
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".
void select_all ( )
Selects the whole String.
Theme Property Descriptions¶
Color clear_button_color = Color( 0.88, 0.88, 0.88, 1 )
Color used as default tint for the clear button.
Color clear_button_color_pressed = Color( 1, 1, 1, 1 )
Color used for the clear button when it's pressed.
Color cursor_color = Color( 0.94, 0.94, 0.94, 1 )
Color of the LineEdit's visual cursor (caret).
Color font_color = Color( 0.88, 0.88, 0.88, 1 )
Default font color.
Color font_color_selected = Color( 0, 0, 0, 1 )
Font color for selected text (inside the selection rectangle).
Color font_color_uneditable = Color( 0.88, 0.88, 0.88, 0.5 )
Font color when editing is disabled.
Color selection_color = Color( 0.49, 0.49, 0.49, 1 )
Color of the selection rectangle.
int minimum_spaces = 12
Minimum horizontal space for the text (not counting the clear button and content margins). This value is measured in count of space characters (i.e. this amount of space characters can be displayed without scrolling).
Font font
Font used for the text.
Texture clear
Texture for the clear button. See clear_button_enabled.
StyleBox focus
Background used when LineEdit has GUI focus.
StyleBox normal
Default background for the LineEdit.
StyleBox read_only
Background used when LineEdit is in read-only mode (editable is set to false
).