Trait gtk4::prelude::EditableExt

source ·
pub trait EditableExt: IsA<Editable> + Sealed + 'static {
Show 38 methods // Provided methods fn delegate_get_accessible_platform_state( &self, state: AccessiblePlatformState ) -> bool { ... } fn delete_selection(&self) { ... } fn delete_text(&self, start_pos: i32, end_pos: i32) { ... } fn finish_delegate(&self) { ... } fn alignment(&self) -> f32 { ... } fn chars(&self, start_pos: i32, end_pos: i32) -> GString { ... } fn delegate(&self) -> Option<Editable> { ... } fn is_editable(&self) -> bool { ... } fn enables_undo(&self) -> bool { ... } fn max_width_chars(&self) -> i32 { ... } fn position(&self) -> i32 { ... } fn selection_bounds(&self) -> Option<(i32, i32)> { ... } fn text(&self) -> GString { ... } fn width_chars(&self) -> i32 { ... } fn init_delegate(&self) { ... } fn insert_text(&self, text: &str, position: &mut i32) { ... } fn select_region(&self, start_pos: i32, end_pos: i32) { ... } fn set_alignment(&self, xalign: f32) { ... } fn set_editable(&self, is_editable: bool) { ... } fn set_enable_undo(&self, enable_undo: bool) { ... } fn set_max_width_chars(&self, n_chars: i32) { ... } fn set_position(&self, position: i32) { ... } fn set_text(&self, text: &str) { ... } fn set_width_chars(&self, n_chars: i32) { ... } fn cursor_position(&self) -> i32 { ... } fn selection_bound(&self) -> i32 { ... } fn xalign(&self) -> f32 { ... } fn set_xalign(&self, xalign: f32) { ... } fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { ... } fn connect_delete_text<F: Fn(&Self, i32, i32) + 'static>( &self, f: F ) -> SignalHandlerId { ... } fn connect_cursor_position_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId { ... } fn connect_editable_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId { ... } fn connect_enable_undo_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId { ... } fn connect_max_width_chars_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId { ... } fn connect_selection_bound_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId { ... } fn connect_text_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId { ... } fn connect_width_chars_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId { ... } fn connect_xalign_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId { ... }
}
Expand description

Trait containing all Editable methods.

§Implementors

EditableLabel, Editable, Entry, PasswordEntry, SearchEntry, SpinButton, Text

Provided Methods§

source

fn delegate_get_accessible_platform_state( &self, state: AccessiblePlatformState ) -> bool

Available on crate feature v4_10 only.

Retrieves the accessible platform state from the editable delegate.

This is an helper function to retrieve the accessible state for Editable interface implementations using a delegate pattern.

You should call this function in your editable widget implementation of the vfunc::Gtk::Accessible::get_platform_state virtual function, for instance:

⚠️ The following code is in c ⚠️

static void
accessible_interface_init (GtkAccessibleInterface *iface)
{
  iface->get_platform_state = your_editable_get_accessible_platform_state;
}

static gboolean
your_editable_get_accessible_platform_state (GtkAccessible *accessible,
                                             GtkAccessiblePlatformState state)
{
  return gtk_editable_delegate_get_accessible_platform_state (GTK_EDITABLE (accessible), state);
}

Note that the widget which is the delegate must be a direct child of this widget, otherwise your implementation of vfunc::Gtk::Accessible::get_platform_state might not even be called, as the platform change will originate from the parent of the delegate, and, as a result, will not work properly.

So, if you can’t ensure the direct child condition, you should give the delegate the AccessibleRole::TextBox role, or you can change your tree to allow this function to work.

§state

what kind of accessible state to retrieve

source

fn delete_selection(&self)

Deletes the currently selected text of the editable.

This call doesn’t do anything if there is no selected text.

source

fn delete_text(&self, start_pos: i32, end_pos: i32)

Deletes a sequence of characters.

The characters that are deleted are those characters at positions from @start_pos up to, but not including @end_pos. If @end_pos is negative, then the characters deleted are those from @start_pos to the end of the text.

Note that the positions are specified in characters, not bytes.

§start_pos

start position

§end_pos

end position

source

fn finish_delegate(&self)

Undoes the setup done by init_delegate().

This is a helper function that should be called from dispose, before removing the delegate object.

source

fn alignment(&self) -> f32

Gets the alignment of the editable.

§Returns

the alignment

source

fn chars(&self, start_pos: i32, end_pos: i32) -> GString

Retrieves a sequence of characters.

The characters that are retrieved are those characters at positions from @start_pos up to, but not including @end_pos. If @end_pos is negative, then the characters retrieved are those characters from @start_pos to the end of the text.

Note that positions are specified in characters, not bytes.

§start_pos

start of text

§end_pos

end of text

§Returns

a pointer to the contents of the widget as a string. This string is allocated by the Editable implementation and should be freed by the caller.

source

fn delegate(&self) -> Option<Editable>

Gets the Editable that @self is delegating its implementation to.

Typically, the delegate is a Text widget.

§Returns

the delegate Editable

source

fn is_editable(&self) -> bool

Retrieves whether @self is editable.

§Returns

true if @self is editable.

source

fn enables_undo(&self) -> bool

Gets if undo/redo actions are enabled for @self

§Returns

true if undo is enabled

source

fn max_width_chars(&self) -> i32

Retrieves the desired maximum width of @self, in characters.

§Returns

the maximum width of the entry, in characters

source

fn position(&self) -> i32

Retrieves the current position of the cursor relative to the start of the content of the editable.

Note that this position is in characters, not in bytes.

§Returns

the cursor position

source

fn selection_bounds(&self) -> Option<(i32, i32)>

Retrieves the selection bound of the editable.

@start_pos will be filled with the start of the selection and @end_pos with end. If no text was selected both will be identical and false will be returned.

Note that positions are specified in characters, not bytes.

§Returns

true if there is a non-empty selection, false otherwise

§start_pos

location to store the starting position

§end_pos

location to store the end position

source

fn text(&self) -> GString

Retrieves the contents of @self.

The returned string is owned by GTK and must not be modified or freed.

§Returns

a pointer to the contents of the editable

source

fn width_chars(&self) -> i32

Gets the number of characters of space reserved for the contents of the editable.

§Returns

number of chars to request space for, or negative if unset

source

fn init_delegate(&self)

Sets up a delegate for Editable.

This is assuming that the get_delegate vfunc in the Editable interface has been set up for the @self’s type.

This is a helper function that should be called in instance init, after creating the delegate object.

source

fn insert_text(&self, text: &str, position: &mut i32)

Inserts @length bytes of @text into the contents of the widget, at position @position.

Note that the position is in characters, not in bytes. The function updates @position to point after the newly inserted text.

§text

the text to insert

§length

the length of the text in bytes, or -1

§position

location of the position text will be inserted at

source

fn select_region(&self, start_pos: i32, end_pos: i32)

Selects a region of text.

The characters that are selected are those characters at positions from @start_pos up to, but not including @end_pos. If @end_pos is negative, then the characters selected are those characters from @start_pos to the end of the text.

Note that positions are specified in characters, not bytes.

§start_pos

start of region

§end_pos

end of region

source

fn set_alignment(&self, xalign: f32)

Sets the alignment for the contents of the editable.

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

§xalign

The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts

source

fn set_editable(&self, is_editable: bool)

Determines if the user can edit the text in the editable widget.

§is_editable

true if the user is allowed to edit the text in the widget

source

fn set_enable_undo(&self, enable_undo: bool)

If enabled, changes to @self will be saved for undo/redo actions.

This results in an additional copy of text changes and are not stored in secure memory. As such, undo is forcefully disabled when visibility is set to false.

§enable_undo

if undo/redo should be enabled

source

fn set_max_width_chars(&self, n_chars: i32)

Sets the desired maximum width in characters of @self.

§n_chars

the new desired maximum width, in characters

source

fn set_position(&self, position: i32)

Sets the cursor position in the editable to the given value.

The cursor is displayed before the character with the given (base 0) index in the contents of the editable. The value must be less than or equal to the number of characters in the editable. A value of -1 indicates that the position should be set after the last character of the editable. Note that @position is in characters, not in bytes.

§position

the position of the cursor

source

fn set_text(&self, text: &str)

Sets the text in the editable to the given value.

This is replacing the current contents.

§text

the text to set

source

fn set_width_chars(&self, n_chars: i32)

Changes the size request of the editable to be about the right size for @n_chars characters.

Note that it changes the size request, the size can still be affected by how you pack the widget into containers. If @n_chars is -1, the size reverts to the default size.

§n_chars

width in chars

source

fn cursor_position(&self) -> i32

The current position of the insertion cursor in chars.

source

fn selection_bound(&self) -> i32

The position of the opposite end of the selection from the cursor in chars.

source

fn xalign(&self) -> f32

The horizontal alignment, from 0 (left) to 1 (right).

Reversed for RTL layouts.

source

fn set_xalign(&self, xalign: f32)

The horizontal alignment, from 0 (left) to 1 (right).

Reversed for RTL layouts.

source

fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId

Emitted at the end of a single user-visible operation on the contents.

E.g., a paste operation that replaces the contents of the selection will cause only one signal emission (even though it is implemented by first deleting the selection, then inserting the new content, and may cause multiple ::notify::text signals to be emitted).

source

fn connect_delete_text<F: Fn(&Self, i32, i32) + 'static>( &self, f: F ) -> SignalHandlerId

Emitted when text is deleted from the widget by the user.

The default handler for this signal will normally be responsible for deleting the text, so by connecting to this signal and then stopping the signal with g_signal_stop_emission(), it is possible to modify the range of deleted text, or prevent it from being deleted entirely.

The @start_pos and @end_pos parameters are interpreted as for delete_text().

§start_pos

the starting position

§end_pos

the end position

source

fn connect_cursor_position_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId

source

fn connect_editable_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId

source

fn connect_enable_undo_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId

source

fn connect_max_width_chars_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId

source

fn connect_selection_bound_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId

source

fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId

source

fn connect_width_chars_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId

source

fn connect_xalign_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId

Object Safety§

This trait is not object safe.

Implementors§