About all my projects
Gnome::Gtk4::Entry

Gnome::Gtk4::Entry

Description

Gnome::Gtk4::Entry is a single line text entry widget.

No caption

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().

Gnome::Gtk4::Entry has the ability to display progress or activity information behind the text. To make an entry display such information, use .set-progress-fraction() or .set-progress-pulse-step().

Additionally, Gnome::Gtk4::Entry can show icons at either side of the entry. These icons can be activatable by clicking, can be set up as drag source and can have tooltips. To add an icon, use .set-icon-from-gicon() or one of the various other functions that set an icon from an icon name or a paintable. To trigger an action when the user clicks an icon, connect to the icon-press signal. To allow DND operations from an icon, use .set-icon-drag-source(). To set a tooltip on an icon, use .set-icon-tooltip-text() or the corresponding function for markup.

Note that functionality or information that is only available by clicking on an icon in an entry may not be accessible at all to users which are not able to use a mouse or other pointing device. It is therefore recommended that any such functionality should also be available by other means, e.g. via the context menu of the entry.

CSS nodes

Gnome::Gtk4::Entry has a main node with the name entry. Depending on the properties of the entry, the style classes .read-only and .flat may appear. The style classes .warning and .error may also be used with entries.

When the entry shows icons, it adds subnodes with the name image and the style class .left or .right, depending on where the icon appears.

When the entry shows progress, it adds a subnode with the name progress. The node has the style class .pulse when the shown progress is pulsing.

For all the subnodes added to the text node in various situations, see Gnome::Gtk4::Text.

GtkEntry as GtkBuildable

The Gnome::Gtk4::Entry implementation of the Gnome::Gtk4::R-Buildable interface supports a custom `<attributes>` element, which supports any number of `<attribute>` elements. The `<attribute>` element has attributes named “name“, “value“, “start“ and “end“ and allows you to specify Gnome::Pango::N-Attribute values for this label.

An example of a UI definition fragment specifying Pango attributes:

The start and end attributes specify the range of characters to which the Pango attribute applies. If start and end are not specified, the attribute is applied to the whole text. Note that specifying ranges does not make much sense with translatable attributes. Use markup embedded in the translatable content instead.

Accessibility

Gnome::Gtk4::Entry uses the GTK_ACCESSIBLE_ROLE_TEXT_BOX role.

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-entry

Creates a new entry.

method new-entry ( --> Gnome::Gtk4::Entry \)

new-with-buffer

Creates a new entry with the specified text buffer.

method new-with-buffer ( N-Object() $buffer --> Gnome::Gtk4::Entry \)
  • $buffer; The buffer to use for the new Gnome::Gtk4::Entry..

Methods

get-activates-default

Retrieves the value set by .set-activates-default().

method get-activates-default (--> Bool )

Return value; True if the entry will activate the default widget.

get-alignment

Gets the value set by .set-alignment().

See also: xalign defined in Gnome::Gtk4::R-Editable

method get-alignment (--> Num )

Return value; the alignment.

get-attributes

Gets the attribute list of the Gnome::Gtk4::Entry.

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-completion

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

Returns the auxiliary completion object currently in use by $entry.

method get-completion (--> N-Object )

Return value; The auxiliary completion object currently in use by $entry.

get-current-icon-drag-source

Returns the index of the icon which is the source of the current DND operation, or -1.

method get-current-icon-drag-source (--> Int )

Return value; index of the icon which is the source of the current DND operation, or -1..

get-extra-menu

Gets the menu model set with .set-extra-menu().

method get-extra-menu (--> N-Object )

Return value; the menu model.

get-has-frame

Gets the value set by .set-has-frame().

method get-has-frame (--> Bool )

Return value; whether the entry has a beveled frame.

get-icon-activatable

Returns whether the icon is activatable.

method get-icon-activatable ( GtkEntryIconPosition $icon-pos --> Bool )
  • $icon-pos; Icon position.

Return value; True if the icon is activatable..

get-icon-area

Gets the area where entry’s icon at $icon-pos is drawn.

This function is useful when drawing something to the entry in a draw callback.

If the entry is not realized or has no icon at the given position, $icon-area is filled with zeros. Otherwise, $icon-area will be filled with the icon's allocation, relative to $entry's allocation.

method get-icon-area ( GtkEntryIconPosition $icon-pos, N-Object $icon-area )
  • $icon-pos; Icon position.

  • $icon-area; Return location for the icon’s area

get-icon-at-pos

Finds the icon at the given position and return its index.

The position’s coordinates are relative to the $entry’s top left corner. If $x, $y doesn’t lie inside an icon, -1 is returned. This function is intended for use in a query-tooltip defined in Widget signal handler.

method get-icon-at-pos ( Int() $x, Int() $y --> Int )
  • $x; the x coordinate of the position to find, relative to $entry.

  • $y; the y coordinate of the position to find, relative to $entry.

Return value; the index of the icon at the given position, or -1.

get-icon-gicon

Retrieves the Gnome::Gio::R-Icon used for the icon.

undefined will be returned if there is no icon or if the icon was set by some other method (e.g., by Gnome::Gdk4::R-Paintable or icon name).

method get-icon-gicon ( GtkEntryIconPosition $icon-pos --> N-Object )
  • $icon-pos; Icon position.

Return value; A Gnome::Gio::R-Icon.

get-icon-name

Retrieves the icon name used for the icon.

undefined is returned if there is no icon or if the icon was set by some other method (e.g., by Gnome::Gdk4::R-Paintable or gicon).

method get-icon-name ( GtkEntryIconPosition $icon-pos --> Str )
  • $icon-pos; Icon position.

Return value; An icon name.

get-icon-paintable

Retrieves the Gnome::Gdk4::R-Paintable used for the icon.

If no Gnome::Gdk4::R-Paintable was used for the icon, undefined is returned.

method get-icon-paintable ( GtkEntryIconPosition $icon-pos --> N-Object )
  • $icon-pos; Icon position.

Return value; A Gnome::Gdk4::R-Paintable if no icon is set for this position or the icon set is not a Gnome::Gdk4::R-Paintable..

get-icon-sensitive

Returns whether the icon appears sensitive or insensitive.

method get-icon-sensitive ( GtkEntryIconPosition $icon-pos --> Bool )
  • $icon-pos; Icon position.

Return value; True if the icon is sensitive..

get-icon-storage-type

Gets the type of representation being used by the icon to store image data.

If the icon has no image data, the return value will be GTK_IMAGE_EMPTY.

method get-icon-storage-type ( GtkEntryIconPosition $icon-pos --> GtkImageType )
  • $icon-pos; Icon position.

Return value; image representation being used.

get-icon-tooltip-markup

Gets the contents of the tooltip on the icon at the specified position in $entry.

method get-icon-tooltip-markup ( GtkEntryIconPosition $icon-pos --> Str )
  • $icon-pos; the icon position.

Return value; the tooltip text.

get-icon-tooltip-text

Gets the contents of the tooltip on the icon at the specified position in $entry.

method get-icon-tooltip-text ( GtkEntryIconPosition $icon-pos --> Str )
  • $icon-pos; the icon position.

Return value; the tooltip text.

get-input-hints

Gets the input hints of this Gnome::Gtk4::Entry.

method get-input-hints (--> UInt )

Return value; the input hints.

get-input-purpose

Gets the input purpose of the Gnome::Gtk4::Entry.

method get-input-purpose (--> GtkInputPurpose )

Return value; the input purpose.

get-invisible-char

Retrieves the character displayed in place of the actual text in “password mode”.

method get-invisible-char (--> UInt )

Return value; the current invisible char, or 0, if the entry does not show invisible text at all..

get-max-length

Retrieves the maximum allowed length of the text in $entry.

See .set-max-length().

method get-max-length (--> Int )

Return value; the maximum allowed number of characters in Gnome::Gtk4::Entry, or 0 if there is no maximum..

get-overwrite-mode

Gets whether the Gnome::Gtk4::Entry is in 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 $entry is empty and unfocused

method get-placeholder-text (--> Str )

Return value; a pointer to the placeholder text as a string. This string points to internally allocated storage in the widget and must not be freed, modified or stored. If no placeholder text has been set, undefined will be returned..

get-progress-fraction

Returns the current fraction of the task that’s been completed.

See .set-progress-fraction().

method get-progress-fraction (--> Num )

Return value; a fraction from 0.0 to 1.0.

get-progress-pulse-step

Retrieves the pulse step set with .set-progress-pulse-step().

method get-progress-pulse-step (--> Num )

Return value; a fraction from 0.0 to 1.0.

get-tabs

Gets the tabstops of the Gnome::Gtk4::Entry.

See .set-tabs().

method get-tabs (--> N-Object )

Return value; the tabstops.

get-text-length

Retrieves the current length of the text in $entry.

This is equivalent to getting $entry'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::Entry, or 0 if there are none..

get-visibility

Retrieves whether the text in $entry is visible.

See .set-visibility().

method get-visibility (--> Bool )

Return value; True if the text is currently visible.

grab-focus-without-selecting

Causes $entry to have keyboard focus.

It behaves like .grab-focus() in class Gnome::Gtk4::Widget, except that it doesn't select the contents of the entry. 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.

progress-pulse

Indicates that some progress is made, but you don’t know how much.

Causes the entry’s progress indicator to enter “activity mode”, where a block bounces back and forth. Each call to .progress-pulse() causes the block to move by a little bit (the amount of movement per pulse is determined by .set-progress-pulse-step()).

method progress-pulse ( )

reset-im-context

Reset the input method context of the entry if needed.

This can be necessary in the case where modifying the buffer would confuse on-going input method behavior.

method reset-im-context ( )

set-activates-default

Sets whether pressing Enter in the $entry will activate the default widget for the window containing the entry.

This usually means that the dialog containing the entry will be closed, since the default widget is usually one of the dialog buttons.

method set-activates-default ( Bool() $setting )
  • $setting; True to activate window’s default widget on Enter keypress.

set-alignment

Sets the alignment for the contents of the entry.

This controls the horizontal positioning of the contents when the displayed text is shorter than the width of the entry.

See also: xalign defined in Gnome::Gtk4::R-Editable

method set-alignment ( Num() $xalign )
  • $xalign; The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts.

set-attributes

Sets a Gnome::Pango::N-AttrList.

The attributes in the list are applied to the entry text.

Since the attributes will be applied to text that changes as the user types, it makes most sense to use attributes with unlimited extent.

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-completion

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

Sets $completion to be the auxiliary completion object to use with $entry.

All further configuration of the completion mechanism is done on $completion using the Gnome::Gtk4::EntryCompletion API. Completion is disabled if $completion is set to undefined.

method set-completion ( N-Object() $completion )
  • $completion; The Gnome::Gtk4::EntryCompletion.

set-extra-menu

Sets a menu model to add when constructing the context menu for $entry.

method set-extra-menu ( N-Object() $model )
  • $model; a Gnome::Gio::MenuModel.

set-has-frame

Sets whether the entry has a beveled frame around it.

method set-has-frame ( Bool() $setting )
  • $setting; new value.

set-icon-activatable

Sets whether the icon is activatable.

method set-icon-activatable ( GtkEntryIconPosition $icon-pos, Bool() $activatable )
  • $icon-pos; Icon position.

  • $activatable; True if the icon should be activatable.

set-icon-drag-source

Sets up the icon at the given position as drag source.

This makes it so that GTK will start a drag operation when the user clicks and drags the icon.

method set-icon-drag-source ( GtkEntryIconPosition $icon-pos, N-Object() $provider, UInt $actions )
  • $icon-pos; icon position.

  • $provider; a Gnome::Gdk4::ContentProvider.

  • $actions; a bitmask of the allowed drag actions.

set-icon-from-gicon

Sets the icon shown in the entry at the specified position from the current icon theme.

If the icon isn’t known, a “broken image” icon will be displayed instead.

If $icon is undefined, no icon will be shown in the specified position.

method set-icon-from-gicon ( GtkEntryIconPosition $icon-pos, N-Object() $icon )
  • $icon-pos; The position at which to set the icon.

  • $icon; The icon to set.

set-icon-from-icon-name

Sets the icon shown in the entry at the specified position from the current icon theme.

If the icon name isn’t known, a “broken image” icon will be displayed instead.

If $icon-name is undefined, no icon will be shown in the specified position.

method set-icon-from-icon-name ( GtkEntryIconPosition $icon-pos, Str $icon-name )
  • $icon-pos; The position at which to set the icon.

  • $icon-name; An icon name.

set-icon-from-paintable

Sets the icon shown in the specified position using a Gnome::Gdk4::R-Paintable.

If $paintable is undefined, no icon will be shown in the specified position.

method set-icon-from-paintable ( GtkEntryIconPosition $icon-pos, N-Object() $paintable )
  • $icon-pos; Icon position.

  • $paintable; A Gnome::Gdk4::R-Paintable.

set-icon-sensitive

Sets the sensitivity for the specified icon.

method set-icon-sensitive ( GtkEntryIconPosition $icon-pos, Bool() $sensitive )
  • $icon-pos; Icon position.

  • $sensitive; Specifies whether the icon should appear sensitive or insensitive.

set-icon-tooltip-markup

Sets $tooltip as the contents of the tooltip for the icon at the specified position. $tooltip is assumed to be marked up with Pango Markup.

Use undefined for $tooltip to remove an existing tooltip.

See also .set-tooltip-markup() in class Gnome::Gtk4::Widget and .set-icon-tooltip-text().

method set-icon-tooltip-markup ( GtkEntryIconPosition $icon-pos, Str $tooltip )
  • $icon-pos; the icon position.

  • $tooltip; the contents of the tooltip for the icon.

set-icon-tooltip-text

Sets $tooltip as the contents of the tooltip for the icon at the specified position.

Use undefined for $tooltip to remove an existing tooltip.

See also .set-tooltip-text() in class Gnome::Gtk4::Widget and .set-icon-tooltip-markup().

If you unset the widget tooltip via .set-tooltip-text() in class Gnome::Gtk4::Widget or .set-tooltip-markup() in class Gnome::Gtk4::Widget, this sets has-tooltip defined in Gnome::Gtk4::Widget to False, which suppresses icon tooltips too. You can resolve this by then calling .set-has-tooltip() in class Gnome::Gtk4::Widget to set has-tooltip defined in Gnome::Gtk4::Widget back to True, or setting at least one non-empty tooltip on any icon achieves the same result.

method set-icon-tooltip-text ( GtkEntryIconPosition $icon-pos, Str $tooltip )
  • $icon-pos; the icon position.

  • $tooltip; the contents of the tooltip for the icon.

set-input-hints

Set additional hints which allow input methods to fine-tune their behavior.

method set-input-hints ( UInt $hints )
  • $hints; the hints.

set-input-purpose

Sets the input purpose which can be used by input methods to adjust their behavior.

method set-input-purpose ( GtkInputPurpose $purpose )
  • $purpose; the purpose.

set-invisible-char

Sets the character to use in place of the actual text in “password mode”.

See .set-visibility() for how to enable “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. The length is in characters.

This is equivalent to getting $entry's Gnome::Gtk4::EntryBuffer and calling .set-max-length() in class Gnome::Gtk4::EntryBuffer on it.

method set-max-length ( Int() $max )
  • $max; the maximum length of the entry, 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::Entry.

method set-overwrite-mode ( Bool() $overwrite )
  • $overwrite; new value.

set-placeholder-text

Sets text to be displayed in $entry when it is empty.

This can be used to give a visual hint of the expected contents of the Gnome::Gtk4::Entry.

method set-placeholder-text ( Str $text )
  • $text; a string to be displayed when $entry is empty and unfocused.

set-progress-fraction

Causes the entry’s progress indicator to “fill in” the given fraction of the bar.

The fraction should be between 0.0 and 1.0, inclusive.

method set-progress-fraction ( Num() $fraction )
  • $fraction; fraction of the task that’s been completed.

set-progress-pulse-step

Sets the fraction of total entry width to move the progress bouncing block for each pulse.

Use .progress-pulse() to pulse the progress.

method set-progress-pulse-step ( Num() $fraction )
  • $fraction; fraction between 0.0 and 1.0.

set-tabs

Sets a Gnome::Pango::N-TabArray.

The tabstops in the array are applied to the entry text.

method set-tabs ( N-Object $tabs )
  • $tabs; a Gnome::Pango::N-TabArray

set-visibility

Sets whether the contents of the entry 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 entry widget is copied elsewhere.

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 entry, in addition to setting visibility to False.

method set-visibility ( Bool() $visible )
  • $visible; True if the contents of the entry are displayed as plaintext.

unset-invisible-char

Unsets the invisible char, so that the default invisible char is used again. See .set-invisible-char().

method unset-invisible-char ( )

Signals

activate

Emitted when the entry is activated.

The keybindings for this signal are all forms of the Enter key.

method handler (
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::Entry :$_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::Entry 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.

icon-press

Emitted when an activatable icon is clicked.

method handler (
   $icon-pos,
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::Entry :$_widget,
  *C<user>-options
)
  • $icon-pos; The position of the clicked icon.

  • $_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::Entry 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.

icon-release

Emitted on the button release from a mouse click over an activatable icon.

method handler (
   $icon-pos,
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::Entry :$_widget,
  *C<user>-options
)
  • $icon-pos; The position of the clicked icon.

  • $_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::Entry 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.