Class: Gtk::Text

Inherits:
Widget
  • Object
show all
Defined in:
(unknown)

Overview

The GtkText widget is a single-line text entry widget.

GtkText is the common implementation of single-line text editing that is shared between [classGtk.Entry], [classGtk.PasswordEntry], [classGtk.SpinButton], and other widgets. In all of these, GtkText is used as the delegate for the [ifaceGtk.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 [methodGtk.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 [methodGtk.Text.set_invisible_char].

If you are looking to add icons or progress display in an entry, look at [classGtk.Entry]. There other alternatives for more specialized use cases, such as [classGtk.SearchEntry].

If you need multi-line editable text, look at [classGtk.TextView].

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

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.

Instance Method Summary collapse

Methods inherited from Widget

#accessible_role, #accessible_role=, #action_set_enabled, #activate, #activate_action, #activate_action_variant, #activate_default, #activate_signal, #activate_signal=, #activate_signal_from_name=, #add_binding, #add_binding_action, #add_binding_signal, #add_controller, #add_css_class, #add_mnemonic_label, #add_shortcut, #add_tick_callback, #allocate, #allocated_baseline, #allocated_height, #allocated_width, #baseline, #bind_template_callback_full, #bind_template_child_full, #can_focus, #can_focus=, #can_focus?, #can_target, #can_target=, #can_target?, #child_focus, #child_visible, #child_visible=, #clipboard, #compute_bounds, #compute_expand, #compute_point, #compute_transform, #contains, #create_pango_context, #create_pango_layout, #css_classes, #css_classes=, #css_name, #css_name=, #cursor, #cursor=, #cursor_from_name=, default_direction, default_direction=, #direction, #direction=, #display, #dispose_template, #drag_check_threshold, #error_bell, #first_child, #focus_child, #focus_child=, #focus_on_click, #focus_on_click=, #focus_on_click?, #focusable, #focusable=, #focusable?, #font_map, #font_map=, #font_options, #font_options=, #frame_clock, #get_allocation, #get_ancestor, #get_color, #get_preferred_size, #get_size, #get_size_request, #get_template_child, #grab_focus, #halign, #halign=, #has_css_class, #has_default, #has_default=, #has_default?, #has_focus, #has_focus=, #has_focus?, #has_tooltip, #has_tooltip=, #has_tooltip?, #has_visible_focus, #height, #height_request, #height_request=, #hexpand, #hexpand=, #hexpand?, #hexpand_set, #hexpand_set=, #hexpand_set?, #hide, #in_destruction, #init_template, #insert_action_group, #insert_after, #insert_before, #install_action, #install_property_action, #is_ancestor, #is_drawable, #is_focus, #is_sensitive, #is_visible, #keynav_failed, #last_child, #layout_manager, #layout_manager=, #layout_manager_type, #layout_manager_type=, #list_mnemonic_labels, #map, #mapped, #margin_bottom, #margin_bottom=, #margin_end, #margin_end=, #margin_start, #margin_start=, #margin_top, #margin_top=, #measure, #mnemonic_activate, #name, #name=, #native, #next_sibling, #observe_children, #observe_controllers, #opacity, #opacity=, #overflow, #overflow=, #pango_context, #parent, #parent=, #pick, #prev_sibling, #primary_clipboard, #query_action, #queue_allocate, #queue_draw, #queue_resize, #realize, #realized, #receives_default, #receives_default=, #receives_default?, #remove_controller, #remove_css_class, #remove_mnemonic_label, #remove_tick_callback, #request_mode, #root, #root=, #scale_factor, #scale_factor=, #sensitive, #sensitive=, #sensitive?, #set_size_request, #set_state_flags, #settings, #should_layout, #show, #size_allocate, #snapshot_child, #state_flags, #style_context, #template=, #template_from_resource=, #template_scope=, #tooltip_markup, #tooltip_markup=, #tooltip_text, #tooltip_text=, #translate_coordinates, #trigger_tooltip_query, #unmap, #unparent, #unrealize, #unset_state_flags, #valign, #valign=, #vexpand, #vexpand=, #vexpand?, #vexpand_set, #vexpand_set=, #vexpand_set?, #visible, #visible=, #visible?, #width, #width_request, #width_request=

Constructor Details

#initialize(buffer) ⇒ Gtk::Widget

Creates a new GtkText with the specified text buffer.

Parameters:

Instance Method Details

#activates_defaultBoolean

Returns whether pressing Enter will activate the default widget for the window containing self.

See [methodGtk.Text.set_activates_default].

Returns:

  • (Boolean)

    true if the GtkText will activate the default widget

#activates_default=(activates_default) ⇒ Boolean

Whether to activate the default widget when Enter is pressed.

Parameters:

  • activates_default (Boolean)

Returns:

  • (Boolean)

    activates-default

  • (Boolean)

    activates-default

#activates_default?Boolean

Whether to activate the default widget when Enter is pressed.

Returns:

  • (Boolean)

    activates-default

#attributesPango::AttrList

A list of Pango attributes to apply to the text of the GtkText.

This is mainly useful to change the size or weight of the text.

The PangoAttribute's start_index and end_index must refer to the GtkEntryBuffer text, i.e. without the preedit string.

Returns:

  • (Pango::AttrList)

    attributes

#attributes=(attributes) ⇒ Pango::AttrList

A list of Pango attributes to apply to the text of the GtkText.

This is mainly useful to change the size or weight of the text.

The PangoAttribute's start_index and end_index must refer to the GtkEntryBuffer text, i.e. without the preedit string.

Parameters:

  • attributes (Pango::AttrList)

Returns:

  • (Pango::AttrList)

    attributes

  • (Pango::AttrList)

    attributes

#bufferGtk::EntryBuffer

The GtkEntryBuffer object which stores the text.

Returns:

#buffer=(buffer) ⇒ Gtk::EntryBuffer

The GtkEntryBuffer object which stores the text.

Parameters:

Returns:

#compute_cursor_extents(position, strong, weak) ⇒ nil

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

    the character position

  • strong (Graphene::Rect)

    location to store the strong cursor position

  • weak (Graphene::Rect)

    location to store the weak cursor position

Returns:

  • (nil)

#enable_emoji_completionBoolean

Returns whether Emoji completion is enabled for this GtkText widget.

Returns:

  • (Boolean)

    true if Emoji completion is enabled

#enable_emoji_completion=(enable_emoji_completion) ⇒ Boolean

Whether to suggest Emoji replacements.

Parameters:

  • enable_emoji_completion (Boolean)

Returns:

  • (Boolean)

    enable-emoji-completion

  • (Boolean)

    enable-emoji-completion

#enable_emoji_completion?Boolean

Whether to suggest Emoji replacements.

Returns:

  • (Boolean)

    enable-emoji-completion

#extra_menuGio::MenuModel

A menu model whose contents will be appended to the context menu.

Returns:

  • (Gio::MenuModel)

    extra-menu

#extra_menu=(extra_menu) ⇒ Gio::MenuModel

A menu model whose contents will be appended to the context menu.

Parameters:

  • extra_menu (Gio::MenuModel)

Returns:

  • (Gio::MenuModel)

    extra-menu

  • (Gio::MenuModel)

    extra-menu

#grab_focus_without_selectingBoolean

Causes self to have keyboard focus.

It behaves like [methodGtk.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:

  • (Boolean)

    true if focus is now inside self

#im_moduleString

Which IM (input method) module should be used for this self.

See [classGtk.IMMulticontext].

Setting this to a non-nil value overrides the system-wide IM module setting. See the [propertyGtk.Settings:gtk-im-module] property.

Returns:

  • (String)

    im-module

#im_module=(im_module) ⇒ String

Which IM (input method) module should be used for this self.

See [classGtk.IMMulticontext].

Setting this to a non-nil value overrides the system-wide IM module setting. See the [propertyGtk.Settings:gtk-im-module] property.

Parameters:

  • im_module (String)

Returns:

  • (String)

    im-module

  • (String)

    im-module

#input_hintsGtk::InputHints

Additional hints that allow input methods to fine-tune their behaviour.

Returns:

#input_hints=(input_hints) ⇒ Gtk::InputHints

Additional hints that allow input methods to fine-tune their behaviour.

Parameters:

Returns:

#input_purposeGtk::InputPurpose

The purpose of this text field.

This property can be used by on-screen keyboards and other input methods to adjust their behaviour.

Note that setting the purpose to %GTK_INPUT_PURPOSE_PASSWORD or %GTK_INPUT_PURPOSE_PIN is independent from setting [propertyGtk.Text:visibility].

Returns:

#input_purpose=(input_purpose) ⇒ Gtk::InputPurpose

The purpose of this text field.

This property can be used by on-screen keyboards and other input methods to adjust their behaviour.

Note that setting the purpose to %GTK_INPUT_PURPOSE_PASSWORD or %GTK_INPUT_PURPOSE_PIN is independent from setting [propertyGtk.Text:visibility].

Parameters:

Returns:

#invisible_charInteger

The character to used when masking contents (in “password mode”).

Returns:

  • (Integer)

    invisible-char

#invisible_char=(invisible_char) ⇒ Integer

The character to used when masking contents (in “password mode”).

Parameters:

  • invisible_char (Integer)

Returns:

  • (Integer)

    invisible-char

  • (Integer)

    invisible-char

#invisible_char_set=(invisible_char_set) ⇒ Boolean

Whether the invisible char has been set for the GtkText.

Parameters:

  • invisible_char_set (Boolean)

Returns:

  • (Boolean)

    invisible-char-set

  • (Boolean)

    invisible-char-set

#invisible_char_set?Boolean

Whether the invisible char has been set for the GtkText.

Returns:

  • (Boolean)

    invisible-char-set

#max_lengthInteger

Maximum number of characters that are allowed.

Zero indicates no limit.

Returns:

  • (Integer)

    max-length

#max_length=(max_length) ⇒ Integer

Maximum number of characters that are allowed.

Zero indicates no limit.

Parameters:

  • max_length (Integer)

Returns:

  • (Integer)

    max-length

  • (Integer)

    max-length

#overwrite_modeBoolean

Gets whether text is overwritten when typing in the GtkText.

See [methodGtk.Text.set_overwrite_mode].

Returns:

  • (Boolean)

    whether the text is overwritten when typing

#overwrite_mode=(overwrite_mode) ⇒ Boolean

If text is overwritten when typing in the GtkText.

Parameters:

  • overwrite_mode (Boolean)

Returns:

  • (Boolean)

    overwrite-mode

  • (Boolean)

    overwrite-mode

#overwrite_mode?Boolean

If text is overwritten when typing in the GtkText.

Returns:

  • (Boolean)

    overwrite-mode

#placeholder_textString

The text that will be displayed in the GtkText when it is empty and unfocused.

Returns:

  • (String)

    placeholder-text

#placeholder_text=(placeholder_text) ⇒ String

The text that will be displayed in the GtkText when it is empty and unfocused.

Parameters:

  • placeholder_text (String)

Returns:

  • (String)

    placeholder-text

  • (String)

    placeholder-text

#propagate_text_widthBoolean

Returns whether the GtkText will grow and shrink with the content.

Returns:

  • (Boolean)

    true if self will propagate the text width

#propagate_text_width=(propagate_text_width) ⇒ Boolean

Whether the widget should grow and shrink with the content.

Parameters:

  • propagate_text_width (Boolean)

Returns:

  • (Boolean)

    propagate-text-width

  • (Boolean)

    propagate-text-width

#propagate_text_width?Boolean

Whether the widget should grow and shrink with the content.

Returns:

  • (Boolean)

    propagate-text-width

#scroll_offsetInteger

Number of pixels scrolled of the screen to the left.

Returns:

  • (Integer)

    scroll-offset

#scroll_offset=(scroll_offset) ⇒ Integer

Number of pixels scrolled of the screen to the left.

Parameters:

  • scroll_offset (Integer)

Returns:

  • (Integer)

    scroll-offset

  • (Integer)

    scroll-offset

#tabsPango::TabArray

A list of tabstops to apply to the text of the GtkText.

Returns:

  • (Pango::TabArray)

    tabs

#tabs=(tabs) ⇒ Pango::TabArray

A list of tabstops to apply to the text of the GtkText.

Parameters:

  • tabs (Pango::TabArray)

Returns:

  • (Pango::TabArray)

    tabs

  • (Pango::TabArray)

    tabs

#text_lengthInteger

Retrieves the current length of the text in self.

This is equivalent to getting self's GtkEntryBuffer and calling [methodGtk.EntryBuffer.get_length] on it.

Returns:

  • (Integer)

    the current number of characters in GtkText, or 0 if there are none.

#truncate_multilineBoolean

Returns whether the GtkText will truncate multi-line text that is pasted into the widget

Returns:

  • (Boolean)

    true if self will truncate multi-line text

#truncate_multiline=(truncate_multiline) ⇒ Boolean

When true, pasted multi-line text is truncated to the first line.

Parameters:

  • truncate_multiline (Boolean)

Returns:

  • (Boolean)

    truncate-multiline

  • (Boolean)

    truncate-multiline

#truncate_multiline?Boolean

When true, pasted multi-line text is truncated to the first line.

Returns:

  • (Boolean)

    truncate-multiline

#unset_invisible_charnil

Unsets the invisible char.

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

Returns:

  • (nil)

#visibilityBoolean

Retrieves whether the text in self is visible.

Returns:

  • (Boolean)

    true if the text is currently visible

#visibility=(visibility) ⇒ Boolean

If false, the text is masked with the “invisible char”.

Parameters:

  • visibility (Boolean)

Returns:

  • (Boolean)

    visibility

  • (Boolean)

    visibility

#visibility?Boolean

If false, the text is masked with the “invisible char”.

Returns:

  • (Boolean)

    visibility