The `GtkText` widget is a single-line text entry widget.
`GtkText` is the common implementation of single-line text editing that is shared between `GtkEntry`, `GtkPasswordEntry`, `GtkSpinButton`
and other widgets. In all of these, `GtkText` is used as the delegate for the [[email protected]] implementation.
A fairly large set of key bindings are supported by default. If the entered text is longer than the allocation of the widget, the widget
will scroll so that the cursor position is visible.
When using an entry for passwords and other sensitive information, it can be put into “password mode” using [
[email protected]_visibility]. In this mode, entered text is displayed using a “invisible” character. By default, GTK picks the best
invisible character that is available in the current font, but it can be changed with [[email protected]_invisible_char].
If you are looking to add icons or progress display in an entry, look at `GtkEntry`. There other alternatives for more specialized use
cases, such as `GtkSearchEntry`.
If you need multi-line editable text, look at `GtkTextView`.
CSS nodes
``` text[.read-only] ├── placeholder ├── undershoot.left ├── undershoot.right ├── [selection] ├── [
block-cursor] ╰── [window.popup] ```
`GtkText` has a main node with the name text. Depending on the properties of the widget, the .read-only style class may appear.
When the entry has a selection, it adds a subnode with the name selection.
When the entry is in overwrite mode, it adds a subnode with the name block-cursor that determines how the block cursor is drawn.
The CSS node for a context menu is added as a subnode below text as well.
The undershoot nodes are used to draw the underflow indication when content is scrolled out of view. These nodes get the .left and .right
style classes added depending on where the indication is drawn.
When touch is used and touch selection handles are shown, they are using CSS nodes with name cursor-handle. They get the .top or .bottom
style class depending on where they are shown in relation to the selection. If there is just a single handle for the text cursor, it gets
the style class .insertion-cursor.
Accessibility
`GtkText` uses the gtk_accessible_role_none role, which causes it to be skipped for accessibility. This
is because `GtkText` is expected to be used as a delegate for a `GtkEditable` implementation that will be represented to accessibility.
- public bool activates_default { get; set; }
Whether to activate the default widget when Enter is pressed.
- public AttrList attributes { get; set; }
A list of Pango attributes to apply to the text of the `GtkText`.
- public EntryBuffer buffer { get; set construct; }
The `GtkEntryBuffer` object which stores the text.
- public bool enable_emoji_completion { get; set; }
Whether to suggest Emoji replacements.
- public MenuModel extra_menu { get; set; }
A menu model whose contents will be appended to the context menu.
- public string im_module { owned get; set; }
Which IM (input method) module should be used for this self.
- public InputHints input_hints { get; set; }
Additional hints that allow input methods to fine-tune their
behaviour.
- public InputPurpose input_purpose { get; set; }
The purpose of this text field.
- public uint invisible_char { get; set; }
The character to used when masking contents (in “password mode”).
- public bool invisible_char_set { get; set; }
Whether the invisible char has been set for the `GtkText`.
- public int max_length { get; set; }
Maximum number of characters that are allowed.
- public bool overwrite_mode { get; set; }
If text is overwritten when typing in the `GtkText`.
- public string placeholder_text { get; set; }
The text that will be displayed in the `GtkText` when it is empty and
unfocused.
- public bool propagate_text_width { get; set; }
Whether the widget should grow and shrink with the content.
- public int scroll_offset { get; }
Number of pixels scrolled of the screen to the left.
- public TabArray tabs { get; set; }
A list of tabstops to apply to the text of the `GtkText`.
- public bool truncate_multiline { get; set; }
When true, pasted multi-line text is
truncated to the first line.
- public bool visibility { get; set; }
If false, the text is masked with
the “invisible char”.
- public void compute_cursor_extents (size_t position, out Rect strong, out Rect @weak)
Determine the positions of the strong and weak cursors if the
insertion point in the layout is at position
.
- public bool get_activates_default ()
Returns whether pressing Enter will activate the default widget for
the window containing this.
- public unowned AttrList? get_attributes ()
Gets the attribute list that was set on the `GtkText`.
- public unowned EntryBuffer get_buffer ()
Get the `GtkEntryBuffer` object which holds the text for this widget.
- public bool get_enable_emoji_completion ()
Returns whether Emoji completion is enabled for this `GtkText` widget.
- public unowned MenuModel? get_extra_menu ()
Gets the menu model for extra items in the context menu.
- public InputHints get_input_hints ()
Gets the input hints of the `GtkText`.
- public InputPurpose get_input_purpose ()
Gets the input purpose of the `GtkText`.
- public unichar get_invisible_char ()
Retrieves the character displayed when visibility is set to false.
- public int get_max_length ()
Retrieves the maximum allowed length of the text in
this.
- public bool get_overwrite_mode ()
Gets whether text is overwritten when typing in the `GtkText`.
- public unowned string? get_placeholder_text ()
Retrieves the text that will be displayed when
this is empty and unfocused
- public bool get_propagate_text_width ()
Returns whether the `GtkText` will grow and shrink with the content.
- public unowned TabArray? get_tabs ()
Gets the tabstops that were set on the `GtkText`.
- public uint16 get_text_length ()
Retrieves the current length of the text in
this.
- public bool get_truncate_multiline ()
Returns whether the `GtkText` will truncate multi-line text that is
pasted into the widget
- public bool get_visibility ()
Retrieves whether the text in this
is visible.
- public bool grab_focus_without_selecting ()
Causes this to have keyboard focus.
- public void set_activates_default (bool activates)
If activates
is true,
pressing Enter will activate the default widget for the window containing this.
- public void set_attributes (AttrList? attrs)
Sets attributes that are applied to the text.
- public void set_buffer (EntryBuffer buffer)
Set the `GtkEntryBuffer` object which holds the text for this widget.
- public void set_enable_emoji_completion (bool enable_emoji_completion)
Sets whether Emoji completion is enabled.
- public void set_extra_menu (MenuModel? model)
Sets a menu model to add when constructing the context menu for
this.
- public void set_input_hints (InputHints hints)
Sets input hints that allow input methods to fine-tune their
behaviour.
- public void set_input_purpose (InputPurpose purpose)
Sets the input purpose of the `GtkText`.
- public void set_invisible_char (unichar ch)
Sets the character to use when in “password mode”.
- public void set_max_length (int length)
Sets the maximum allowed length of the contents of the widget.
- public void set_overwrite_mode (bool overwrite)
Sets whether the text is overwritten when typing in the `GtkText`.
- public void set_placeholder_text (string? text)
Sets text to be displayed in this
when it is empty.
- public void set_propagate_text_width (bool propagate_text_width)
Sets whether the `GtkText` should grow and shrink with the content.
- public void set_tabs (TabArray? tabs)
Sets tabstops that are applied to the text.
- public void set_truncate_multiline (bool truncate_multiline)
Sets whether the `GtkText` should truncate multi-line text that is
pasted into the widget.
- public void set_visibility (bool visible)
Sets whether the contents of the `GtkText` are visible or not.
- public void unset_invisible_char ()
Unsets the invisible char.