Struct gtk4::Text

source ·
#[repr(transparent)]
pub struct Text { /* private fields */ }
Expand description

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

Text is the common implementation of single-line text editing that is shared between Entry, PasswordEntry, SpinButton and other widgets. In all of these, Text is used as the delegate for the 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 Entry. There other alternatives for more specialized use cases, such as SearchEntry.

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

CSS nodes

text[.read-only]
├── placeholder
├── undershoot.left
├── undershoot.right
├── [selection]
├── [block-cursor]
╰── [window.popup]

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

Text uses the AccessibleRole::None role, which causes it to be skipped for accessibility. This is because Text is expected to be used as a delegate for a Editable implementation that will be represented to accessibility.

Implements

WidgetExt, glib::ObjectExt, AccessibleExt, BuildableExt, ConstraintTargetExt, EditableExt, WidgetExtManual, AccessibleExtManual, EditableExtManual

Implementations§

Creates a new Text.

Returns

a new Text.

Creates a new Text with the specified text buffer.

buffer

The buffer to use for the new Text.

Returns

a new Text

Creates a new builder-pattern struct instance to construct Text objects.

This method returns an instance of TextBuilder which can be used to create Text objects.

Available on crate feature v4_4 only.

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.

position

the character position

Returns
strong

location to store the strong cursor position

weak

location to store the weak cursor position

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

See set_activates_default().

Returns

true if the Text will activate the default widget

Gets the attribute list that was set on the Text.

See set_attributes().

Returns

the attribute list

Get the EntryBuffer object which holds the text for this widget.

Returns

A EntryBuffer object.

Returns whether Emoji completion is enabled for this Text widget.

Returns

true if Emoji completion is enabled

Gets the menu model for extra items in the context menu.

See set_extra_menu().

Returns

the menu model

Gets the input hints of the Text.

Gets the input purpose of the Text.

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

Returns

the current invisible char, or 0, if @text does not show invisible text at all.

Retrieves the maximum allowed length of the text in @self.

See set_max_length().

This is equivalent to getting @self’s EntryBuffer and calling EntryBufferExtManual::max_length() on it.

Returns

the maximum allowed number of characters in Text, or 0 if there is no maximum.

Gets whether text is overwritten when typing in the Text.

See set_overwrite_mode().

Returns

whether the text is overwritten when typing

Retrieves the text that will be displayed when @self is empty and unfocused

If no placeholder text has been set, None will be returned.

Returns

the placeholder text

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

Returns

true if @self will propagate the text width

Gets the tabstops that were set on the Text.

See set_tabs().

Returns

the tabstops

Retrieves the current length of the text in @self.

This is equivalent to getting @self’s EntryBuffer and calling EntryBufferExtManual::length() on it.

Returns

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

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

Returns

true if @self will truncate multi-line text

Retrieves whether the text in @self is visible.

Returns

true if the text is currently visible

Causes @self to have keyboard focus.

It behaves like WidgetExt::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

If @activates is true, pressing Enter will activate the default widget for the window containing @self.

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

activates

true to activate window’s default widget on Enter keypress

Sets attributes that are applied to the text.

attrs

a pango::AttrList

Set the EntryBuffer object which holds the text for this widget.

buffer

a EntryBuffer

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.

enable_emoji_completion

true to enable Emoji completion

Sets a menu model to add when constructing the context menu for @self.

model

a GMenuModel

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

hints

the hints

Sets the input purpose of the Text.

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

purpose

the purpose

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.

ch

a Unicode character

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 EntryBuffer and calling EntryBufferExtManual::set_max_length() on it.

length

the maximum length of the 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.

Sets whether the text is overwritten when typing in the Text.

overwrite

new value

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

text

a string to be displayed when @self is empty and unfocused

Sets whether the Text should grow and shrink with the content.

propagate_text_width

true to propagate the text width

Sets tabstops that are applied to the text.

tabs

a pango::TabArray

Sets whether the Text should truncate multi-line text that is pasted into the widget.

truncate_multiline

true to truncate multi-line text

Sets whether the contents of the 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 property::Text::input-purpose to InputPurpose::Password or InputPurpose::Pin to inform input methods about the purpose of this self, in addition to setting visibility to false.

visible

true if the contents of the Text are displayed as plaintext

Unsets the invisible char.

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

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

See IMMulticontext.

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

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

See IMMulticontext.

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

Whether the invisible char has been set for the Text.

Number of pixels scrolled of the screen to the left.

Emitted when the user hits the Enter key.

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

Emitted when the user asks for it.

This is a keybinding signal.

The default bindings for this signal are Backspace and Shift-Backspace.

Emitted to copy the selection to the clipboard.

This is a keybinding signal.

The default bindings for this signal are Ctrl-c and Ctrl-Insert.

Emitted to cut the selection to the clipboard.

This is a keybinding signal.

The default bindings for this signal are Ctrl-x and Shift-Delete.

Emitted when the user initiates a text deletion.

This is a keybinding signal.

If the @type_ is DeleteType::Chars, GTK deletes the selection if there is one, otherwise it deletes the requested number of characters.

The default bindings for this signal are Delete for deleting a character and Ctrl-Delete for deleting a word.

type_

the granularity of the deletion, as a DeleteType

count

the number of @type_ units to delete

Emitted when the user initiates the insertion of a fixed string at the cursor.

This is a keybinding signal.

This signal has no default bindings.

string

the string to insert

Emitted to present the Emoji chooser for the widget.

This is a keybinding signal.

The default bindings for this signal are Ctrl-. and Ctrl-;

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.

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 Shift modifier extends the selection, the variant without it does not. There are too many key combinations to list them all here.

  • , , , move by individual characters/lines
  • Ctrl-, etc. move by words/paragraphs
  • Home, End move to the ends of the buffer
step

the granularity of the move, as a MovementStep

count

the number of @step units to move

extend

true if the move should extend the selection

Emitted to paste the contents of the clipboard.

This is a keybinding signal.

The default bindings for this signal are Ctrl-v and Shift-Insert.

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.

preedit

the current preedit string

Emitted to toggle the overwrite mode of the Text.

This is a keybinding signal.

The default bindings for this signal is Insert.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Returns the type identifier of Self.

Auto Trait Implementations§

Blanket Implementations§

Updates an array of accessible properties. Read more
Updates an array of accessible relations. Read more
Updates an array of accessible states. Read more
Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Upcasts an object to a superclass or interface T. Read more
Upcasts an object to a reference of its superclass or interface T. Read more
Tries to downcast to a subclass or interface implementor T. Read more
Tries to downcast to a reference of its subclass or interface implementor T. Read more
Tries to cast to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already. Read more
Tries to cast to reference to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already. Read more
Casts to T unconditionally. Read more
Casts to &T unconditionally. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Returns true if the object is an instance of (can be cast to) T.
Returns the type of the object.
Returns the ObjectClass of the object. Read more
Returns the class of the object.
Returns the class of the object in the given type T. Read more
Returns the interface T of the object. Read more
Sets the property property_name of the object to value value. Read more
Sets the property property_name of the object to value value. Read more
Sets multiple properties of the object at once. Read more
Sets multiple properties of the object at once. Read more
Gets the property property_name of the object and cast it to the type V. Read more
Gets the property property_name of the object. Read more
Check if the object has a property property_name of the given type_. Read more
Get the type of the property property_name of this object. Read more
Get the ParamSpec of the property property_name of this object.
Return all ParamSpec of the properties of this object.
Freeze all property notifications until the return guard object is dropped. Read more
Set arbitrary data on this object with the given key. Read more
Return previously set arbitrary data of this object with the given key. Read more
Retrieve previously set arbitrary data of this object with the given key. Read more
Set arbitrary data on this object with the given key. Read more
Return previously set arbitrary data of this object with the given key. Read more
Retrieve previously set arbitrary data of this object with the given key. Read more
Block a given signal handler. Read more
Unblock a given signal handler.
Stop emission of the currently emitted signal.
Stop emission of the currently emitted signal by the (possibly detailed) signal name.
Connect to the signal signal_name on this object. Read more
Connect to the signal signal_id on this object. Read more
Connect to the signal signal_name on this object. Read more
Connect to the signal signal_id on this object. Read more
Connect to the signal signal_name on this object. Read more
Connect to the signal signal_id on this object. Read more
Connect a closure to the signal signal_name on this object. Read more
Connect a closure to the signal signal_id on this object. Read more
Limits the lifetime of closure to the lifetime of the object. When the object’s reference count drops to zero, the closure will be invalidated. An invalidated closure will ignore any calls to invoke_with_values, or invoke when using Rust closures.
Emit signal by signal id. Read more
Same as Self::emit but takes Value for the arguments.
Emit signal by its name. Read more
Emit signal by its name. Read more
Emit signal by its name with details. Read more
Emit signal by its name with details. Read more
Emit signal by signal id with details. Read more
Emit signal by signal id with details. Read more
Disconnect a previously connected signal handler.
Connect to the notify signal of the object. Read more
Connect to the notify signal of the object. Read more
Connect to the notify signal of the object. Read more
Notify that the given property has changed its value. Read more
Notify that the given property has changed its value. Read more
Downgrade this object to a weak reference.
Add a callback to be notified when the Object is disposed.
Add a callback to be notified when the Object is disposed. Read more
Bind property source_property on this object to the target_property on the target object. Read more
Returns the strong reference count of this object.
Runs the dispose mechanism of the object. Read more
Ensures that the type has been registered with the type system.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.