Class LineEdit
- Namespace
- Godot
- Assembly
- GodotSharp.dll
LineEdit provides an input field for editing a single line of text. It features many built-in shortcuts that are always 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:
- Cmd + F: Same as Right Arrow, move the caret one character right
- Cmd + B: Same as Left Arrow, move the caret one character left
- Cmd + P: Same as Up Arrow, move the caret to the previous line
- Cmd + N: Same as Down Arrow, move the caret to the next line
- Cmd + D: Same as Delete, delete the character on the right side of caret
- Cmd + H: Same as Backspace, delete the character on the left side of the caret
- Cmd + A: Same as Home, move the caret to the beginning of the line
- Cmd + 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
public class LineEdit : Control, IDisposable
- Inheritance
-
LineEdit
- Implements
- Inherited Members
Constructors
LineEdit()
public LineEdit()
Properties
Alignment
Text alignment as defined in the HorizontalAlignment enum.
public HorizontalAlignment Alignment { get; set; }
Property Value
CaretBlink
If true
, makes the caret blink.
public bool CaretBlink { get; set; }
Property Value
CaretBlinkInterval
The interval at which the caret blinks (in seconds).
public float CaretBlinkInterval { get; set; }
Property Value
CaretColumn
The caret's column position inside the LineEdit. When set, the text may scroll to accommodate it.
public int CaretColumn { get; set; }
Property Value
CaretForceDisplayed
If true
, the LineEdit will always show the caret, even if focus is lost.
public bool CaretForceDisplayed { get; set; }
Property Value
CaretMidGrapheme
Allow moving caret, selecting and removing the individual composite character components.
Note: Backspace is always removing individual composite character components.
public bool CaretMidGrapheme { get; set; }
Property Value
ClearButtonEnabled
If true
, the LineEdit will show a clear button if Text is not empty, which can be used to clear the text quickly.
public bool ClearButtonEnabled { get; set; }
Property Value
ContextMenuEnabled
If true
, the context menu will appear when right-clicked.
public bool ContextMenuEnabled { get; set; }
Property Value
DeselectOnFocusLossEnabled
If true
, the selected text will be deselected when focus is lost.
public bool DeselectOnFocusLossEnabled { get; set; }
Property Value
DragAndDropSelectionEnabled
If true
, allow drag and drop of selected text.
public bool DragAndDropSelectionEnabled { get; set; }
Property Value
DrawControlChars
If true
, control characters are displayed.
public bool DrawControlChars { get; set; }
Property Value
Editable
If false
, existing text cannot be modified and new text cannot be added.
public bool Editable { get; set; }
Property Value
ExpandToTextLength
If true
, the LineEdit width will increase to stay longer than the Text. It will not compress if the Text is shortened.
public bool ExpandToTextLength { get; set; }
Property Value
Flat
If true
, the LineEdit doesn't display decoration.
public bool Flat { get; set; }
Property Value
Language
Language code used for line-breaking and text shaping algorithms. If left empty, current locale is used instead.
public string Language { get; set; }
Property Value
MaxLength
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 MaxLength 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 TextChangeRejected signal is emitted with the truncated substring as parameter.
Example:
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.
public int MaxLength { get; set; }
Property Value
MiddleMousePasteEnabled
If false
, using middle mouse button to paste clipboard will be disabled.
Note: This method is only implemented on Linux.
public bool MiddleMousePasteEnabled { get; set; }
Property Value
PlaceholderText
public string PlaceholderText { get; set; }
Property Value
RightIcon
Sets the icon that will appear in the right end of the LineEdit if there's no Text, or always, if ClearButtonEnabled is set to false
.
public Texture2D RightIcon { get; set; }
Property Value
Secret
If true
, every character is replaced with the secret character (see SecretCharacter).
public bool Secret { get; set; }
Property Value
SecretCharacter
The character to use to mask secret input. Only a single character can be used as the secret character. If it is longer than one character, only the first one will be used. If it is empty, a space will be used instead.
public string SecretCharacter { get; set; }
Property Value
SelectAllOnFocus
If true
, the LineEdit will select the whole text when it gains focus.
public bool SelectAllOnFocus { get; set; }
Property Value
SelectingEnabled
If false
, it's impossible to select the text using mouse nor keyboard.
public bool SelectingEnabled { get; set; }
Property Value
ShortcutKeysEnabled
If false
, using shortcuts will be disabled.
public bool ShortcutKeysEnabled { get; set; }
Property Value
StructuredTextBidiOverride
Set BiDi algorithm override for the structured text.
public TextServer.StructuredTextParser StructuredTextBidiOverride { get; set; }
Property Value
StructuredTextBidiOverrideOptions
Set additional options for BiDi override.
public Array StructuredTextBidiOverrideOptions { get; set; }
Property Value
Text
String value of the LineEdit.
Note: Changing text using this property won't emit the TextChanged signal.
public string Text { get; set; }
Property Value
TextDirection
Base text writing direction.
public Control.TextDirection TextDirection { get; set; }
Property Value
VirtualKeyboardEnabled
If true
, the native virtual keyboard is shown when focused on platforms that support it.
public bool VirtualKeyboardEnabled { get; set; }
Property Value
VirtualKeyboardType
Specifies the type of virtual keyboard to show.
public LineEdit.VirtualKeyboardTypeEnum VirtualKeyboardType { get; set; }
Property Value
Methods
Clear()
public void Clear()
DeleteCharAtCaret()
Deletes one character at the caret's current position (equivalent to pressing Delete).
public void DeleteCharAtCaret()
DeleteText(int, int)
Deletes a section of the Text going from position fromColumn
to toColumn
. Both parameters should be within the text's length.
public void DeleteText(int fromColumn, int toColumn)
Parameters
Deselect()
Clears the current selection.
public void Deselect()
GetMenu()
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 LineEdit.MenuItems). For example:
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(Time.GetDateStringFromSystem());
}
}
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 Visible property.
public PopupMenu GetMenu()
Returns
GetScrollOffset()
Returns the scroll offset due to CaretColumn, as a number of characters.
public float GetScrollOffset()
Returns
GetSelectedText()
Returns the text inside the selection.
public string GetSelectedText()
Returns
GetSelectionFromColumn()
Returns the selection begin column.
public int GetSelectionFromColumn()
Returns
GetSelectionToColumn()
Returns the selection end column.
public int GetSelectionToColumn()
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
HasSelection()
Returns true
if the user has selected text.
public bool HasSelection()
Returns
InsertTextAtCaret(string)
Inserts text
at the caret. If the resulting value is longer than MaxLength, nothing happens.
public void InsertTextAtCaret(string text)
Parameters
text
string
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
IsMenuVisible()
Returns whether the menu is visible. Use this instead of get_menu().visible
to improve performance (so the creation of the menu is avoided).
public bool IsMenuVisible()
Returns
MenuOption(int)
Executes a given action as defined in the LineEdit.MenuItems enum.
public void MenuOption(int option)
Parameters
option
int
Select(int, int)
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".
public void Select(int from = 0, int to = -1)
Parameters
SelectAll()
Selects the whole string.
public void SelectAll()
Events
TextChangeRejected
Emitted when appending text that overflows the MaxLength. The appended text is truncated to fit MaxLength, and the part that couldn't fit is passed as the rejectedSubstring
argument.
public event LineEdit.TextChangeRejectedEventHandler TextChangeRejected
Event Type
TextChanged
Emitted when the text changes.
public event LineEdit.TextChangedEventHandler TextChanged
Event Type
TextSubmitted
public event LineEdit.TextSubmittedEventHandler TextSubmitted