SourceClass TextEdit
from egui import TextEditclass TextEdit:A text region that the user can edit the contents of.
See also Ui.text_edit_singleline and Ui.text_edit_multiline.
To fill an Ui with a TextEdit use Ui.add_sized:
You can also use TextEdit to show text that can be selected, but not edited.
To do so, pass in a &mut reference to a str, for instance:
Advanced usage
See TextEdit.show.
Other
The background color of a egui.TextEdit is egui.Visuals.text_edit_bg_color or can be set with egui.TextEdit.background_color.
Methods§
Sourcedef background_color(self, /, color: Color32) -> TextEdit§
Sourcedef char_limit(self, /, char_limit: int) -> TextEdit§
Sets the limit for the amount of characters can be entered
This only works for singleline TextEdit
Sourcedef clip_text(self, /, clip_text: bool) -> TextEdit§
When True (default), overflowing text will be clipped.
When False, widget width will expand to make all text visible.
This only works for singleline TextEdit.
Sourcedef code_editor(self, /) -> TextEdit§
Build a TextEdit focused on code editing.
By default it comes with:
- monospaced font
- focus lock (tab will insert a tab character instead of moving focus)
Sourcedef cursor_at_end(self, /, cursor_at_end: bool) -> TextEdit§
When True (default), the cursor will initially be placed at the end of the text.
When False, the cursor will initially be placed at the beginning of the text.
Sourcedef desired_rows(self, /, desired_rows: int) -> TextEdit§
Set the number of rows to show by default.
The default for singleline text is 1.
The default for multiline text is 4.
Sourcedef desired_width(self, /, desired_width: float) -> TextEdit§
Set to 0.0 to keep as small as possible.
Set to float.INFINITY to take up all available space (i.e. disable automatic word wrap).
Sourcedef font(self, /, font: TextStyle) -> TextEdit§
Pick a egui.FontId or TextStyle.
def font_id(self, /, font_id: FontId) -> TextEdit§
Sourcedef frame(self, /, frame: Frame) -> TextEdit§
Customize the Frame around the text edit.
Sourcedef hint_text(self, /, hint_text: str) -> TextEdit§
Show a faint hint text when the text field is empty.
If the hint text needs to be persisted even when the text field has input, the following workaround can be used:
Sourcedef horizontal_align(self, /, align: Align) -> TextEdit§
Set the horizontal align of the inner text.
Sourcedef id(self, /, id: Id) -> TextEdit§
Use if you want to set an explicit Id for this widget.
Sourcedef id_salt(self, /, id_salt: str) -> TextEdit§
A source for the unique Id, e.g. .id_salt("second_text_edit_field") or .id_salt(loop_index).
Sourcedef id_source(self, /, id_source: str) -> TextEdit§
A source for the unique Id, e.g. .id_source("second_text_edit_field") or .id_source(loop_index).
Sourcedef interactive(self, /, interactive: bool) -> TextEdit§
Default is True. If set to False then you cannot interact with the text (neither edit or select it).
Consider using Ui.add_enabled instead to also give the TextEdit a greyed out look.
Sourcedef layouter(self, /, layouter: TextLayouter) -> TextEdit§
Override how text is being shown inside the TextEdit.
This can be used to implement things like syntax highlighting.
This function will be called at least once per frame, so it is strongly suggested that you cache the results of any syntax highlighter so as not to waste CPU highlighting the same string every frame.
The arguments is the enclosing Ui (so you can access e.g. Context.fonts),
the text and the wrap width.
Source@staticmethod
def load_state(ctx: Context, id: Id) -> TextEditState |None§
Sourcedef lock_focus(self, /, lock_focus: bool) -> TextEdit§
When False (default), pressing TAB will move focus
to the next widget.
When True, the widget will keep the focus and pressing TAB
will insert the '\t' character.
Sourcedef margin(self, /, margin: Margin) -> TextEdit§
Override the padding around the text, which otherwise comes from the theme.
Sourcedef min_size(self, /, min_size: Vec2) -> TextEdit§
Set the minimum size of the TextEdit.
Source@staticmethod
def multiline(text: Mutable) -> TextEdit§
A TextEdit for multiple lines. Pressing enter key will create a new line by default (can be changed with return_key).
@staticmethod
def multiline_buffer(text: TextBuffer) -> TextEdit§
Sourcedef password(self, /, password: bool) -> TextEdit§
If true, hide the letters from view and prevent copying from the field.
Sourcedef prefix(self, /, prefix: str) -> TextEdit§
Add a prefix to the text edit. This will always be shown before the editable text.
Goes in front of any prefix already set, so .prefix("b").prefix("a") shows ab.
Sourcedef return_key(self, /, return_key: KeyboardShortcut |None) -> TextEdit§
Set the return key combination.
This combination will cause a newline on multiline, whereas on singleline it will cause the widget to lose focus.
This combination is optional and can be disabled by passing None into this function.
Sourcedef show(self, /, ui: Ui) -> TextEditOutput§
Show the TextEdit, returning a rich TextEditOutput.
Source@staticmethod
def singleline(text: Mutable) -> TextEdit§
No newlines (\n) allowed. Pressing enter key will result in the TextEdit losing focus (response.lost_focus).
@staticmethod
def singleline_buffer(text: TextBuffer) -> TextEdit§
Source@staticmethod
def store_state(ctx: Context, id: Id, state: TextEditState) -> None§
Sourcedef suffix(self, /, suffix: str) -> TextEdit§
Add a suffix to the text edit. This will always be shown after the editable text.
Goes after any suffix already set, so .suffix("a").suffix("b") shows ab.
Sourcedef text_color(self, /, text_color: Color32) -> TextEdit§
Sourcedef text_color_opt(self, /, text_color: Color32 |None) -> TextEdit§
Sourcedef vertical_align(self, /, align: Align) -> TextEdit§
Set the vertical align of the inner text.