Struct gtk4::Text [−][src]
pub struct Text(_);
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 builder-pattern struct instance to construct Text
objects.
This method returns an instance of TextBuilder
which can be used to create Text
objects.
This is supported on crate feature v4_4
only.
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
.
Returns
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 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.
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 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 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
should grow and shrink with the content.
propagate_text_width
true
to propagate the text width
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
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
.
Whether the invisible char has been set for the Text
.
Number of pixels scrolled of the screen to the left.
pub fn connect_activates_default_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_enable_emoji_completion_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_invisible_char_set_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_placeholder_text_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_propagate_text_width_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_truncate_multiline_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
Emitted when the user hits the Enter key.
The default bindings for this signal are all forms
of the <kbd>
Enter</kbd>
key.
Emitted when the user asks for it.
This is a keybinding signal.
The default bindings for this signal are
<kbd>
Backspace</kbd>
and <kbd>
Shift</kbd>
-<kbd>
Backspace</kbd>
.
Emitted to copy the selection to the clipboard.
This is a keybinding signal.
The default bindings for this signal are
<kbd>
Ctrl</kbd>
-<kbd>
c</kbd>
and
<kbd>
Ctrl</kbd>
-<kbd>
Insert</kbd>
.
Emitted to cut the selection to the clipboard.
This is a keybinding signal.
The default bindings for this signal are
<kbd>
Ctrl</kbd>
-<kbd>
x</kbd>
and
<kbd>
Shift</kbd>
-<kbd>
Delete</kbd>
.
pub fn connect_delete_from_cursor<F: Fn(&Text, DeleteType, i32) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_delete_from_cursor<F: Fn(&Text, DeleteType, i32) + 'static>(
&self,
f: F
) -> SignalHandlerId
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 <kbd>
Delete</kbd>
for deleting a character and <kbd>
Ctrl</kbd>
-<kbd>
Delete</kbd>
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
<kbd>
Ctrl</kbd>
-<kbd>
.</kbd>
and
<kbd>
Ctrl</kbd>
-<kbd>
;</kbd>
pub fn connect_move_cursor<F: Fn(&Text, MovementStep, i32, bool) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_move_cursor<F: Fn(&Text, MovementStep, i32, bool) + 'static>(
&self,
f: F
) -> SignalHandlerId
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 <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>
,<kbd>
End</kbd>
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
<kbd>
Ctrl</kbd>
-<kbd>
v</kbd>
and <kbd>
Shift</kbd>
-<kbd>
Insert</kbd>
.
pub fn connect_populate_popup<F: Fn(&Text, &Widget) + 'static>(
&self,
f: F
) -> SignalHandlerId
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 <kbd>
Insert</kbd>
.
Trait Implementations
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
Returns the type identifier of Self
.
Auto Trait Implementations
impl RefUnwindSafe for Text
impl UnwindSafe for Text
Blanket Implementations
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 true
if the object is an instance of (can be cast to) T
.
pub fn set_property<'a, N, V>(
&self,
property_name: N,
value: V
) -> Result<(), BoolError> where
N: Into<&'a str>,
V: ToValue,
pub fn set_property_from_value<'a, N>(
&self,
property_name: N,
value: &Value
) -> Result<(), BoolError> where
N: Into<&'a str>,
pub fn set_properties_from_value(
&self,
property_values: &[(&str, Value)]
) -> Result<(), BoolError>
pub fn has_property<'a, N>(&self, property_name: N, type_: Option<Type>) -> bool where
N: Into<&'a str>,
pub fn find_property<'a, N>(&self, property_name: N) -> Option<ParamSpec> where
N: Into<&'a str>,
Safety Read more
Safety Read more
Safety Read more
Safety Read more
pub fn connect<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
N: Into<&'a str>,
F: 'static + Fn(&[Value]) -> Option<Value> + Send + Sync,
Same as connect
but takes a SignalId
instead of a signal name.
pub fn connect_local<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
N: Into<&'a str>,
F: 'static + Fn(&[Value]) -> Option<Value>,
Same as connect_local
but takes a SignalId
instead of a signal name.
pub unsafe fn connect_unsafe<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
N: Into<&'a str>,
F: Fn(&[Value]) -> Option<Value>,
Same as connect_unsafe
but takes a SignalId
instead of a signal name.
Emit signal by signal id.
Same as emit
but takes Value
for the arguments.
Emit signal by its name.
Same as emit_by_name
but takes Value
for the arguments.
Emit signal with details by signal id.
Same as emit_with_details
but takes Value
for the arguments.
pub fn connect_notify<F>(&self, name: Option<&str>, f: F) -> SignalHandlerId where
F: 'static + Fn(&T, &ParamSpec) + Send + Sync,
pub fn connect_notify_local<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerId where
F: 'static + Fn(&T, &ParamSpec),
pub unsafe fn connect_notify_unsafe<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerId where
F: Fn(&T, &ParamSpec),
pub fn bind_property<'a, O, N, M>(
&'a self,
source_property: N,
target: &'a O,
target_property: M
) -> BindingBuilder<'a> where
O: ObjectType,
N: Into<&'a str>,
M: Into<&'a str>,
Returns a SendValue
clone of self
.