
Gnome::Gtk4::Text
Description
The Gnome::Gtk4::Text widget is a single-line text entry widget.
Gnome::Gtk4::Text is the common implementation of single-line text editing that is shared between Gnome::Gtk4::Entry, Gnome::Gtk4::PasswordEntry, Gnome::Gtk4::SpinButton, and other widgets. In all of these, Gnome::Gtk4::Text is used as the delegate for the Gnome::Gtk4::R-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 .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 .set-invisible-char()
.
If you are looking to add icons or progress display in an entry, look at Gnome::Gtk4::Entry. There other alternatives for more specialized use cases, such as Gnome::Gtk4::SearchEntry.
If you need multi-line editable text, look at Gnome::Gtk4::TextView.
CSS nodes
Gnome::Gtk4::Text 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 with the name popup.
The undershoot nodes are used to draw the underflow indication when content is scrolled out of view. These nodes get the `.left` or `.right` style class 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
Gnome::Gtk4::Text uses the GTK_ACCESSIBLE_ROLE_NONE
role, which causes it to be skipped for accessibility. This is because Gnome::Gtk4::Text is expected to be used as a delegate for a Gnome::Gtk4::R-Editable implementation that will be represented to accessibility.
Class initialization
new
:native-object
Create an object using a native object from elsewhere. See also Gnome::N::TopLevelSupportClass.
multi method new ( N-Object :$native-object! )
new-text
Creates a new Gnome::Gtk4::Text.
method new-text ( --> Gnome::Gtk4::Text \)
new-with-buffer
Creates a new Gnome::Gtk4::Text with the specified text buffer.
method new-with-buffer ( N-Object() $buffer --> Gnome::Gtk4::Text \)
$buffer; The buffer to use for the new Gnome::Gtk4::Text..
Methods
compute-cursor-extents
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.
method compute-cursor-extents ( Int() $position, N-Object $strong, N-Object $weak )
$position; the character position.
$strong; location to store the strong cursor position
$weak; location to store the weak cursor position
get-activates-default
Returns whether pressing Enter will activate the default widget for the window containing $self
.
See .set-activates-default()
.
method get-activates-default (--> Bool )
Return value; True
if the Gnome::Gtk4::Text will activate the default widget.
get-attributes
Gets the attribute list that was set on the Gnome::Gtk4::Text.
See .set-attributes()
.
method get-attributes (--> N-Object )
Return value; the attribute list.
get-buffer
Get the Gnome::Gtk4::EntryBuffer object which holds the text for this widget.
method get-buffer (--> N-Object )
Return value; A Gnome::Gtk4::EntryBuffer object..
get-enable-emoji-completion
Returns whether Emoji completion is enabled for this Gnome::Gtk4::Text widget.
method get-enable-emoji-completion (--> Bool )
Return value; True
if Emoji completion is enabled.
get-extra-menu
Gets the menu model for extra items in the context menu.
See .set-extra-menu()
.
method get-extra-menu (--> N-Object )
Return value; the menu model.
get-input-hints
Gets the input hints of the Gnome::Gtk4::Text.
method get-input-hints (--> UInt )
Return value; No documentation about its value and use.
get-input-purpose
Gets the input purpose of the Gnome::Gtk4::Text.
method get-input-purpose (--> GtkInputPurpose )
Return value; No documentation about its value and use.
get-invisible-char
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 .set-invisible-char()
.
method get-invisible-char (--> UInt )
Return value; the current invisible char, or 0, if $text
does not show invisible text at all..
get-max-length
Retrieves the maximum allowed length of the text in $self
.
See .set-max-length()
.
This is equivalent to getting $self
's Gnome::Gtk4::EntryBuffer and calling .get-max-length() in class Gnome::Gtk4::EntryBuffer
on it.
method get-max-length (--> Int )
Return value; the maximum allowed number of characters in Gnome::Gtk4::Text, or 0 if there is no maximum..
get-overwrite-mode
Gets whether text is overwritten when typing in the Gnome::Gtk4::Text.
See .set-overwrite-mode()
.
method get-overwrite-mode (--> Bool )
Return value; whether the text is overwritten when typing.
get-placeholder-text
Retrieves the text that will be displayed when $self
is empty and unfocused
If no placeholder text has been set, undefined will be returned.
method get-placeholder-text (--> Str )
Return value; the placeholder text.
get-propagate-text-width
Returns whether the Gnome::Gtk4::Text will grow and shrink with the content.
method get-propagate-text-width (--> Bool )
Return value; True
if $self
will propagate the text width.
get-tabs
Gets the tabstops that were set on the Gnome::Gtk4::Text.
See .set-tabs()
.
method get-tabs (--> N-Object )
Return value; the tabstops.
get-text-length
Retrieves the current length of the text in $self
.
This is equivalent to getting $self
's Gnome::Gtk4::EntryBuffer and calling .get-length() in class Gnome::Gtk4::EntryBuffer
on it.
method get-text-length (--> UInt )
Return value; the current number of characters in Gnome::Gtk4::Text, or 0 if there are none..
get-truncate-multiline
Returns whether the Gnome::Gtk4::Text will truncate multi-line text that is pasted into the widget
method get-truncate-multiline (--> Bool )
Return value; True
if $self
will truncate multi-line text.
get-visibility
Retrieves whether the text in $self
is visible.
method get-visibility (--> Bool )
Return value; True
if the text is currently visible.
grab-focus-without-selecting
Causes $self
to have keyboard focus.
It behaves like .grab-focus() in class Gnome::Gtk4::Widget
, 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.
method grab-focus-without-selecting (--> Bool )
Return value; True
if focus is now inside $self
.
set-activates-default
If $activates
is True
, pressing Enter will activate the default widget for the window containing $self
.
This usually means that the dialog containing the Gnome::Gtk4::Text will be closed, since the default widget is usually one of the dialog buttons.
method set-activates-default ( Bool() $activates )
$activates;
True
to activate window’s default widget on Enter keypress.
set-attributes
Sets attributes that are applied to the text.
method set-attributes ( N-Object $attrs )
$attrs; a Gnome::Pango::N-AttrList
set-buffer
Set the Gnome::Gtk4::EntryBuffer object which holds the text for this widget.
method set-buffer ( N-Object() $buffer )
$buffer; a Gnome::Gtk4::EntryBuffer.
set-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.
method set-enable-emoji-completion ( Bool() $enable-emoji-completion )
$enable-emoji-completion;
True
to enable Emoji completion.
set-extra-menu
Sets a menu model to add when constructing the context menu for $self
.
method set-extra-menu ( N-Object() $model )
$model; a Gnome::Gio::MenuModel.
set-input-hints
Sets input hints that allow input methods to fine-tune their behaviour.
method set-input-hints ( UInt $hints )
$hints; the hints.
set-input-purpose
Sets the input purpose of the Gnome::Gtk4::Text.
This can be used by on-screen keyboards and other input methods to adjust their behaviour.
method set-input-purpose ( GtkInputPurpose $purpose )
$purpose; the purpose.
set-invisible-char
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.
method set-invisible-char ( UInt() $ch )
$ch; a Unicode character.
set-max-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 Gnome::Gtk4::EntryBuffer and calling .set-max-length() in class Gnome::Gtk4::EntryBuffer
on it.
method set-max-length ( Int() $length )
$length; the maximum length of the Gnome::Gtk4::Text, or 0 for no maximum. (other than the maximum length of entries.) The value passed in will be clamped to the range 0-65536..
set-overwrite-mode
Sets whether the text is overwritten when typing in the Gnome::Gtk4::Text.
method set-overwrite-mode ( Bool() $overwrite )
$overwrite; new value.
set-placeholder-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 Gnome::Gtk4::Text.
method set-placeholder-text ( Str $text )
$text; a string to be displayed when
$self
is empty and unfocused.
set-propagate-text-width
Sets whether the Gnome::Gtk4::Text should grow and shrink with the content.
method set-propagate-text-width ( Bool() $propagate-text-width )
$propagate-text-width;
True
to propagate the text width.
set-tabs
Sets tabstops that are applied to the text.
method set-tabs ( N-Object $tabs )
$tabs; a Gnome::Pango::N-TabArray
set-truncate-multiline
Sets whether the Gnome::Gtk4::Text should truncate multi-line text that is pasted into the widget.
method set-truncate-multiline ( Bool() $truncate-multiline )
$truncate-multiline;
True
to truncate multi-line text.
set-visibility
Sets whether the contents of the Gnome::Gtk4::Text 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 .set-invisible-char()
.
Note that you probably want to set 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
.
method set-visibility ( Bool() $visible )
$visible;
True
if the contents of the Gnome::Gtk4::Text are displayed as plaintext.
unset-invisible-char
Unsets the invisible char.
After calling this, the default invisible char is used again.
method unset-invisible-char ( )
Signals
activate
Emitted when the user hits the <kbd>Enter</kbd> key.
The default bindings for this signal are all forms of the <kbd>Enter</kbd> key.
method handler ( Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::Text :$_widget, *C<user>-options )
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::Text object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.
backspace
Emitted when the user asks for it.
This is a [keybinding signal](class.SignalAction.html).
The default bindings for this signal are <kbd>Backspace</kbd> and <kbd>Shift</kbd>+<kbd>Backspace</kbd>.
method handler ( Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::Text :$_widget, *C<user>-options )
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::Text object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.
copy-clipboard
Emitted to copy the selection to the clipboard.
This is a [keybinding signal](class.SignalAction.html).
The default bindings for this signal are <kbd>Ctrl</kbd>+<kbd>c</kbd> and <kbd>Ctrl</kbd>+<kbd>Insert</kbd>.
method handler ( Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::Text :$_widget, *C<user>-options )
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::Text object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.
cut-clipboard
Emitted to cut the selection to the clipboard.
This is a [keybinding signal](class.SignalAction.html).
The default bindings for this signal are <kbd>Ctrl</kbd>+<kbd>x</kbd> and <kbd>Shift</kbd>+<kbd>Delete</kbd>.
method handler ( Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::Text :$_widget, *C<user>-options )
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::Text object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.
delete-from-cursor
Emitted when the user initiates a text deletion.
This is a [keybinding signal](class.SignalAction.html).
If the $type
is GTK_DELETE_CHARS
, GTK deletes the selection if there is one, otherwise it deletes the requested number of characters.
The default bindings for this signal are <kbd>Delete</kbd> for deleting a character and <kbd>Ctrl</kbd>+<kbd>Delete</kbd> for deleting a word.
method handler ( $type, gint $count, Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::Text :$_widget, *C<user>-options )
$type; the granularity of the deletion, as a
enumeration GtkDeleteType defined in Gnome::Gtk4::T-enums
.$count; the number of
$type
units to delete.$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::Text object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.
insert-at-cursor
Emitted when the user initiates the insertion of a fixed string at the cursor.
This is a [keybinding signal](class.SignalAction.html).
This signal has no default bindings.
method handler ( Str $string, Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::Text :$_widget, *C<user>-options )
$string; the string to insert.
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::Text object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.
insert-emoji
Emitted to present the Emoji chooser for the widget.
This is a [keybinding signal](class.SignalAction.html).
The default bindings for this signal are <kbd>Ctrl</kbd>+<kbd>.</kbd> and <kbd>Ctrl</kbd>+<kbd>;</kbd>
method handler ( Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::Text :$_widget, *C<user>-options )
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::Text object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.
move-cursor
Emitted when the user initiates a cursor movement.
If the cursor is not visible in $self
, this signal causes the viewport to be moved instead.
This is a [keybinding signal](class.SignalAction.html).
Applications should not connect to it, but may emit it with g_signal_emit_by_name() if they need to control the cursor programmatically.
The default bindings for this signal come in two variants, the variant with the <kbd>Shift</kbd> modifier extends the selection, the variant without it does not. There are too many key combinations to list them all here.
<kbd>←</kbd>, <kbd>→</kbd>, <kbd>↑</kbd>, <kbd>↓</kbd> move by individual characters/lines
<kbd>Ctrl</kbd>+<kbd>←</kbd>, etc. move by words/paragraphs
<kbd>Home</kbd> and <kbd>End</kbd> move to the ends of the buffer
method handler ( $step, gint $count, gboolean $extend, Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::Text :$_widget, *C<user>-options )
$step; the granularity of the move, as a
enumeration GtkMovementStep defined in Gnome::Gtk4::T-enums
.$count; the number of
$step
units to move.$extend;
True
if the move should extend the selection.$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::Text object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.
paste-clipboard
Emitted to paste the contents of the clipboard.
This is a [keybinding signal](class.SignalAction.html).
The default bindings for this signal are <kbd>Ctrl</kbd>+<kbd>v</kbd> and <kbd>Shift</kbd>+<kbd>Insert</kbd>.
method handler ( Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::Text :$_widget, *C<user>-options )
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::Text object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.
preedit-changed
Emitted when the preedit text changes.
If an input method is used, the typed text will not immediately be committed to the buffer. So if you are interested in the text, connect to this signal.
method handler ( Str $preedit, Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::Text :$_widget, *C<user>-options )
$preedit; the current preedit string.
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::Text object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.
toggle-overwrite
Emitted to toggle the overwrite mode of the Gnome::Gtk4::Text.
This is a [keybinding signal](class.SignalAction.html).
The default bindings for this signal is <kbd>Insert</kbd>.
method handler ( Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::Text :$_widget, *C<user>-options )
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::Text object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.