Skip to main content

HasSelectableText

Trait HasSelectableText 

pub trait HasSelectableText {
    // Required methods
    fn selected_text(&self, tree: &Tree) -> Option<String>;
    fn select_all(&self, tree: &mut Tree);
    fn is_focused(&self, tree: &Tree) -> bool;
    fn context_menu_position(&self, tree: &Tree) -> Option<Point>;
    fn set_context_menu_position(&self, tree: &mut Tree, pos: Option<Point>);

    // Provided methods
    fn is_editable(&self) -> bool { ... }
    fn copy_to_clipboard(&self, tree: &Tree, clipboard: &mut dyn Clipboard) { ... }
    fn delete_selection(&self, _tree: &mut Tree) -> Option<String> { ... }
    fn paste_text(&self, _tree: &mut Tree, _text: &str) -> Option<String> { ... }
}
Expand description

Implement this on a widget to enable context menu support for text selection (Copy, Select All, and optionally Cut / Paste) in libcosmic

Required Methods§

fn selected_text(&self, tree: &Tree) -> Option<String>

Returns the currently selected text, if any.

fn select_all(&self, tree: &mut Tree)

Selects all text.

fn is_focused(&self, tree: &Tree) -> bool

Returns true if the widget is currently focused.

fn context_menu_position(&self, tree: &Tree) -> Option<Point>

Returns the position where the context menu should appear

fn set_context_menu_position(&self, tree: &mut Tree, pos: Option<Point>)

Sets or clears the context menu position.

Provided Methods§

fn is_editable(&self) -> bool

Returns true if the widget is editable (enables Cut / Paste).

fn copy_to_clipboard(&self, tree: &Tree, clipboard: &mut dyn Clipboard)

Copies the selection to the clipboard.

fn delete_selection(&self, _tree: &mut Tree) -> Option<String>

Deletes the selected text and returns the new full content. Only called when is_editable is true.

fn paste_text(&self, _tree: &mut Tree, _text: &str) -> Option<String>

Inserts text at the cursor (replacing any selection) and returns the new full content. Only called when is_editable is true.

Implementors§

§

impl<Highlighter, Message, Theme, Renderer> HasSelectableText for TextEditor<'_, Highlighter, Message, Theme, Renderer>
where Highlighter: Highlighter, Theme: Catalog, Renderer: Renderer,

§

impl<Theme, Renderer> HasSelectableText for Text<'_, Theme, Renderer>
where Theme: Catalog, Renderer: Renderer,