Class Text

All Implemented Interfaces:
PointerInterface

public class Text extends Widget
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 [iface@Gtk.Editable] 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 [method@Gtk.Text.set_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
[method@Gtk.Text.set_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.

https://docs.gtk.org/gtk4/class.Text.html

  • Field Details

  • Constructor Details

    • Text

      public Text(PointerContainer pointer)
    • Text

      public Text()
      Creates a new `GtkText`.
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • newWithBufferText

      public static Text newWithBufferText(@Nonnull EntryBuffer buffer)
      Creates a new `GtkText` with the specified text buffer.
      Parameters:
      buffer - The buffer to use for the new `GtkText`.
      Returns:
      a new `GtkText`
    • computeCursorExtents

      public void computeCursorExtents(long position, @Nullable Rect strong, @Nullable Rect weak)
      Determine the positions of the strong and weak cursors if the
      insertion point in the layout is at @position.

      The position of each cursor is stored as a zero-width rectangle.
      The strong cursor location is the location where characters of
      the directionality equal to the base direction are inserted.
      The weak cursor location is the location where characters of
      the directionality opposite to the base direction are inserted.

      The rectangle positions are in widget coordinates.
      Parameters:
      position - the character position
      strong - location to store the strong cursor position
      weak - location to store the weak cursor position
    • getActivatesDefault

      public boolean getActivatesDefault()
      Returns whether pressing Enter will activate
      the default widget for the window containing @self.

      See [method@Gtk.Text.set_activates_default].
      Returns:
      %TRUE if the `GtkText` will activate the default widget
    • getAttributes

      public AttrList getAttributes()
      Gets the attribute list that was set on the `GtkText`.

      See [method@Gtk.Text.set_attributes].
      Returns:
      the attribute list
    • getBuffer

      public EntryBuffer getBuffer()
      Get the `GtkEntryBuffer` object which holds the text for
      this widget.
      Returns:
      A `GtkEntryBuffer` object.
    • getEnableEmojiCompletion

      public boolean getEnableEmojiCompletion()
      Returns whether Emoji completion is enabled for this
      `GtkText` widget.
      Returns:
      %TRUE if Emoji completion is enabled
    • getExtraMenu

      public MenuModel getExtraMenu()
      Gets the menu model for extra items in the context menu.

      See [method@Gtk.Text.set_extra_menu].
      Returns:
      the menu model
    • getInputHints

      public int getInputHints()
      Gets the input hints of the `GtkText`.
      Returns:
    • getInputPurpose

      public int getInputPurpose()
      Gets the input purpose of the `GtkText`.
      Returns:
    • getInvisibleChar

      public byte getInvisibleChar()
      Retrieves the character displayed when visibility is set to false.

      Note that GTK does not compute this value unless it needs it,
      so the value returned by this function is not very useful unless
      it has been explicitly set with [method@Gtk.Text.set_invisible_char].
      Returns:
      the current invisible char, or 0, if @text does not show invisible text at all.
    • getMaxLength

      public int getMaxLength()
      Retrieves the maximum allowed length of the text in @self.

      See [method@Gtk.Text.set_max_length].

      This is equivalent to getting @self's `GtkEntryBuffer` and
      calling [method@Gtk.EntryBuffer.get_max_length] on it.
      Returns:
      the maximum allowed number of characters in `GtkText`, or 0 if there is no maximum.
    • getOverwriteMode

      public boolean getOverwriteMode()
      Gets whether text is overwritten when typing in the `GtkText`.

      See [method@Gtk.Text.set_overwrite_mode].
      Returns:
      whether the text is overwritten when typing
    • getPlaceholderText

      public Str getPlaceholderText()
      Retrieves the text that will be displayed when
      @self is empty and unfocused

      If no placeholder text has been set, %NULL will be returned.
      Returns:
      the placeholder text
    • getPropagateTextWidth

      public boolean getPropagateTextWidth()
      Returns whether the `GtkText` will grow and shrink
      with the content.
      Returns:
      %TRUE if @self will propagate the text width
    • getTabs

      public TabArray getTabs()
      Gets the tabstops that were set on the `GtkText`.

      See [method@Gtk.Text.set_tabs].
      Returns:
      the tabstops
    • getTextLength

      public int getTextLength()
      Retrieves the current length of the text in @self.

      This is equivalent to getting @self's `GtkEntryBuffer`
      and calling [method@Gtk.EntryBuffer.get_length] on it.
      Returns:
      the current number of characters in `GtkText`, or 0 if there are none.
    • getTruncateMultiline

      public boolean getTruncateMultiline()
      Returns whether the `GtkText` will truncate multi-line text
      that is pasted into the widget
      Returns:
      %TRUE if @self will truncate multi-line text
    • getVisibility

      public boolean getVisibility()
      Retrieves whether the text in @self is visible.
      Returns:
      %TRUE if the text is currently visible
    • grabFocusWithoutSelecting

      public boolean grabFocusWithoutSelecting()
      Causes @self to have keyboard focus.

      It behaves like [method@Gtk.Widget.grab_focus],
      except that it doesn't select the contents of @self.
      You only want to call this on some special entries
      which the user usually doesn't want to replace all text in,
      such as search-as-you-type entries.
      Returns:
      %TRUE if focus is now inside @self
    • setActivatesDefault

      public void setActivatesDefault(boolean activates)
      If @activates is %TRUE, pressing Enter will activate
      the default widget for the window containing @self.

      This usually means that the dialog containing the `GtkText`
      will be closed, since the default widget is usually one of
      the dialog buttons.
      Parameters:
      activates - %TRUE to activate window’s default widget on Enter keypress
    • setAttributes

      public void setAttributes(@Nullable AttrList attrs)
      Sets attributes that are applied to the text.
      Parameters:
      attrs - a `PangoAttrList`
    • setBuffer

      public void setBuffer(@Nonnull EntryBuffer buffer)
      Set the `GtkEntryBuffer` object which holds the text for
      this widget.
      Parameters:
      buffer - a `GtkEntryBuffer`
    • setEnableEmojiCompletion

      public void setEnableEmojiCompletion(boolean enable_emoji_completion)
      Sets whether Emoji completion is enabled.

      If it is, typing ':', followed by a recognized keyword,
      will pop up a window with suggested Emojis matching the
      keyword.
      Parameters:
      enable_emoji_completion - %TRUE to enable Emoji completion
    • setExtraMenu

      public void setExtraMenu(@Nullable MenuModel model)
      Sets a menu model to add when constructing
      the context menu for @self.
      Parameters:
      model - a `GMenuModel`
    • setInputHints

      public void setInputHints(int hints)
      Sets input hints that allow input methods
      to fine-tune their behaviour.
      Parameters:
      hints - the hints
    • setInputPurpose

      public void setInputPurpose(int purpose)
      Sets the input purpose of the `GtkText`.

      This can be used by on-screen keyboards and other
      input methods to adjust their behaviour.
      Parameters:
      purpose - the purpose
    • setInvisibleChar

      public void setInvisibleChar(byte ch)
      Sets the character to use when in “password mode”.

      By default, GTK picks the best invisible char available in the
      current font. If you set the invisible char to 0, then the user
      will get no feedback at all; there will be no text on the screen
      as they type.
      Parameters:
      ch - a Unicode character
    • setMaxLength

      public void setMaxLength(int length)
      Sets the maximum allowed length of the contents of the widget.

      If the current contents are longer than the given length, then
      they will be truncated to fit.

      This is equivalent to getting @self's `GtkEntryBuffer` and
      calling [method@Gtk.EntryBuffer.set_max_length] on it.
      Parameters:
      length - the maximum length of the `GtkText`, or 0 for no maximum. (other than the maximum length of entries.) The value passed in will be clamped to the range 0-65536.
    • setOverwriteMode

      public void setOverwriteMode(boolean overwrite)
      Sets whether the text is overwritten when typing
      in the `GtkText`.
      Parameters:
      overwrite - new value
    • setPlaceholderText

      public void setPlaceholderText(@Nullable Str text)
      Sets text to be displayed in @self when it is empty.

      This can be used to give a visual hint of the expected
      contents of the `GtkText`.
      Parameters:
      text - a string to be displayed when @self is empty and unfocused
    • setPlaceholderText

      public void setPlaceholderText(String text)
      Sets text to be displayed in @self when it is empty.

      This can be used to give a visual hint of the expected
      contents of the `GtkText`.
      Parameters:
      text - a string to be displayed when @self is empty and unfocused
    • setPropagateTextWidth

      public void setPropagateTextWidth(boolean propagate_text_width)
      Sets whether the `GtkText` should grow and shrink with the content.
      Parameters:
      propagate_text_width - %TRUE to propagate the text width
    • setTabs

      public void setTabs(@Nullable TabArray tabs)
      Sets tabstops that are applied to the text.
      Parameters:
      tabs - a `PangoTabArray`
    • setTruncateMultiline

      public void setTruncateMultiline(boolean truncate_multiline)
      Sets whether the `GtkText` should truncate multi-line text
      that is pasted into the widget.
      Parameters:
      truncate_multiline - %TRUE to truncate multi-line text
    • setVisibility

      public void setVisibility(boolean visible)
      Sets whether the contents of the `GtkText` are visible or not.

      When visibility is set to %FALSE, characters are displayed
      as the invisible char, and will also appear that way when
      the text in the widget is copied to the clipboard.

      By default, GTK picks the best invisible character available
      in the current font, but it can be changed with
      [method@Gtk.Text.set_invisible_char].

      Note that you probably want to set [property@Gtk.Text:input-purpose]
      to %GTK_INPUT_PURPOSE_PASSWORD or %GTK_INPUT_PURPOSE_PIN to
      inform input methods about the purpose of this self,
      in addition to setting visibility to %FALSE.
      Parameters:
      visible - %TRUE if the contents of the `GtkText` are displayed as plaintext
    • unsetInvisibleChar

      public void unsetInvisibleChar()
      Unsets the invisible char.

      After calling this, the default invisible
      char is used again.
    • onActivate

      public SignalHandler onActivate(Text.OnActivate signal)
      Connect to signal "activate".
      See Text.OnActivate.onActivate() for signal description.
      Field SIGNAL_ON_ACTIVATE contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onBackspace

      public SignalHandler onBackspace(Text.OnBackspace signal)
      Connect to signal "backspace".
      See Text.OnBackspace.onBackspace() for signal description.
      Field SIGNAL_ON_BACKSPACE contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onCopyClipboard

      public SignalHandler onCopyClipboard(Text.OnCopyClipboard signal)
      Connect to signal "copy-clipboard".
      See Text.OnCopyClipboard.onCopyClipboard() for signal description.
      Field SIGNAL_ON_COPY_CLIPBOARD contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onCutClipboard

      public SignalHandler onCutClipboard(Text.OnCutClipboard signal)
      Connect to signal "cut-clipboard".
      See Text.OnCutClipboard.onCutClipboard() for signal description.
      Field SIGNAL_ON_CUT_CLIPBOARD contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onDeleteFromCursor

      public SignalHandler onDeleteFromCursor(Text.OnDeleteFromCursor signal)
      Connect to signal "delete-from-cursor".
      See Text.OnDeleteFromCursor.onDeleteFromCursor(int, int) for signal description.
      Field SIGNAL_ON_DELETE_FROM_CURSOR contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onInsertAtCursor

      public SignalHandler onInsertAtCursor(Text.OnInsertAtCursor signal)
      Connect to signal "insert-at-cursor".
      See Text.OnInsertAtCursor.onInsertAtCursor(ch.bailu.gtk.type.Str) for signal description.
      Field SIGNAL_ON_INSERT_AT_CURSOR contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onInsertEmoji

      public SignalHandler onInsertEmoji(Text.OnInsertEmoji signal)
      Connect to signal "insert-emoji".
      See Text.OnInsertEmoji.onInsertEmoji() for signal description.
      Field SIGNAL_ON_INSERT_EMOJI contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onMoveCursor

      public SignalHandler onMoveCursor(Text.OnMoveCursor signal)
      Connect to signal "move-cursor".
      See Text.OnMoveCursor.onMoveCursor(int, int, boolean) for signal description.
      Field SIGNAL_ON_MOVE_CURSOR contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onPasteClipboard

      public SignalHandler onPasteClipboard(Text.OnPasteClipboard signal)
      Connect to signal "paste-clipboard".
      See Text.OnPasteClipboard.onPasteClipboard() for signal description.
      Field SIGNAL_ON_PASTE_CLIPBOARD contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onPreeditChanged

      public SignalHandler onPreeditChanged(Text.OnPreeditChanged signal)
      Connect to signal "preedit-changed".
      See Text.OnPreeditChanged.onPreeditChanged(ch.bailu.gtk.type.Str) for signal description.
      Field SIGNAL_ON_PREEDIT_CHANGED contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onToggleOverwrite

      public SignalHandler onToggleOverwrite(Text.OnToggleOverwrite signal)
      Connect to signal "toggle-overwrite".
      See Text.OnToggleOverwrite.onToggleOverwrite() for signal description.
      Field SIGNAL_ON_TOGGLE_OVERWRITE contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • asAccessible

      public Accessible asAccessible()
      Implements interface Accessible. Call this to get access to interface functions.
      Overrides:
      asAccessible in class Widget
      Returns:
      Accessible
    • asBuildable

      public Buildable asBuildable()
      Implements interface Buildable. Call this to get access to interface functions.
      Overrides:
      asBuildable in class Widget
      Returns:
      Buildable
    • asConstraintTarget

      public ConstraintTarget asConstraintTarget()
      Implements interface ConstraintTarget. Call this to get access to interface functions.
      Overrides:
      asConstraintTarget in class Widget
      Returns:
      ConstraintTarget
    • asEditable

      public Editable asEditable()
      Implements interface Editable. Call this to get access to interface functions.
      Returns:
      Editable
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()