Struct unsegen::widget::builtin::lineedit::LineEdit[][src]

pub struct LineEdit { /* fields omitted */ }
Expand description

A user-editable line of text.

In addition to the current text, the LineEdit has a concept of a cursor whose position can change, but is always on a grapheme cluster in the current text.

Implementations

impl LineEdit[src]

pub fn new() -> Self[src]

Create empty LineEdit

pub fn get(&self) -> &str[src]

Get the current content.

pub fn set(&mut self, text: impl Into<String>)[src]

Set (and overwrite) the current content. The cursor will be placed at the very end of the line.

pub fn move_cursor_to_end_of_line(&mut self)[src]

Move the cursor to the end, i.e., behind the last grapheme cluster.

pub fn move_cursor_to_beginning_of_line(&mut self)[src]

Move the cursor to the beginning, i.e., onto the first grapheme cluster.

pub fn move_cursor_right(&mut self) -> Result<(), ()>[src]

Move the cursor one grapheme cluster to the right if possible.

pub fn move_cursor_left(&mut self) -> Result<(), ()>[src]

Move the cursor one grapheme cluster to the left if possible.

pub fn insert(&mut self, text: &str)[src]

Insert text directly before the current cursor position

pub fn cursor_pos(&self) -> usize[src]

Returns the byte position of the cursor in the current text (obtainable by get)

pub fn set_cursor_pos(&mut self, pos: usize) -> Result<(), ()>[src]

Set the cursor by specifying its position as the byte position in the displayed string.

If the byte position does not correspond to (the start of) a grapheme cluster in the string or the end of the string, an error is returned and the cursor position is left unchanged.

Examples:

use unsegen::widget::builtin::LineEdit;

let mut l = LineEdit::new();
l.set("löl");
assert!(l.set_cursor_pos(0).is_ok()); // |löl
assert!(l.set_cursor_pos(1).is_ok()); // l|öl
assert!(l.set_cursor_pos(2).is_err());
assert!(l.set_cursor_pos(3).is_ok()); // lö|l
assert!(l.set_cursor_pos(4).is_ok()); // löl|
assert!(l.set_cursor_pos(5).is_err());

pub fn as_widget<'a>(&'a self) -> LineEditWidget<'a>[src]

Prepare for drawing as a Widget.

Trait Implementations

impl Editable for LineEdit[src]

fn delete_forwards(&mut self) -> OperationResult[src]

In the sense of pressing the “Delete” key.

fn delete_backwards(&mut self) -> OperationResult[src]

In the sense of pressing the “Backspace” key.

fn go_to_beginning_of_line(&mut self) -> OperationResult[src]

In the sense of pressing the “Home” key.

fn go_to_end_of_line(&mut self) -> OperationResult[src]

In the sense of pressing the “End” key.

fn clear(&mut self) -> OperationResult[src]

Remove all content.

impl Navigatable for LineEdit[src]

Note that there is no concept of moving up or down for a LineEdit.

impl Writable for LineEdit[src]

fn write(&mut self, c: char) -> OperationResult[src]

Process the provided char and report if it was processed successfully.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.