Skip to main content

TextEdit

Struct TextEdit 

#[non_exhaustive]
pub struct TextEdit { pub value: String, pub cursor: usize, pub highlight: usize, pub max_length: usize, pub multiline: bool, }
Expand description

The text of a field and where its cursor and selection are, in characters (EditBox.value, cursorPos, highlightPos, maxLength).

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§value: String

The text.

§cursor: usize

The cursor, in characters from the start.

§highlight: usize

The other end of the selection; the same as cursor when nothing is selected.

§max_length: usize

The most characters the text may have (EditBox.setMaxLength, 32 by default).

§multiline: bool

MultiLineEditBox: line breaks are kept and words split at any whitespace.

Implementations§

§

impl TextEdit

pub fn new(max_length: usize) -> TextEdit

An empty field that takes up to max_length characters.

pub fn set_value(&mut self, value: &str)

EditBox.setValue: the text, cut to the maximum length, with the cursor at its end.

pub fn selected(&self) -> (usize, usize)

The selection’s start and end, in characters (kept within the text).

pub fn selected_text(&self) -> String

EditBox.getHighlighted: the selected text.

pub fn insert_text(&mut self, text: &str)

EditBox.insertText: text, filtered as StringUtil.filterText does, replaces the selection, cut to what the maximum length leaves room for.

pub fn delete_chars(&mut self, n: isize)

EditBox.deleteChars: n characters after the cursor (before it when negative), or the selection when there is one.

pub fn word_position(&self, dir: isize) -> usize

EditBox.getWordPosition(dir) from the cursor.

pub fn word_position_from(&self, dir: isize, from: usize) -> usize

EditBox.getWordPosition(dir, from), or MultilineTextField’s word for a multi-line field.

pub fn set_cursor(&mut self, pos: usize, select: bool)

EditBox.moveCursorTo: the cursor to pos (kept within the text), the selection’s anchor with it unless select.

pub fn move_cursor_to_end(&mut self, select: bool)

EditBox.moveCursorToEnd.

pub fn select_all(&mut self)

Ctrl+A: the cursor at the end and everything selected.

pub fn word_at(&self, pos: usize) -> (usize, usize)

The word around character pos (EditBox.selectWord, a double click): its start and end.

pub fn key(&mut self, key: EditKey, ctrl: bool, shift: bool) -> bool

EditBox.keyPressed’s editing keys. True when the key edits or moves (the caller then scrolls to the cursor and restarts its blink).

Trait Implementations§

§

impl Clone for TextEdit

§

fn clone(&self) -> TextEdit

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for TextEdit

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for TextEdit

§

fn default() -> TextEdit

Returns the “default value” for a type. Read more
§

impl Eq for TextEdit

§

impl PartialEq for TextEdit

§

fn eq(&self, other: &TextEdit) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl StructuralPartialEq for TextEdit

§

impl Wire for TextEdit

§

const MIN: usize

Minimum encoded size, used to reject impossible collection lengths.
§

fn put(&self, out: &mut Writer)

Encodes this value, recording failures on the writer.
§

fn put_owned(self, out: &mut Writer)

Consumes owned data when a resource’s ownership must cross the boundary.
§

fn take(input: &mut Reader<'_>) -> Result<TextEdit, WireError>

Decodes one value, leaving any following bytes for the caller.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> Put for T
where T: Wire,

§

fn put_to(&self, out: &mut Writer)

Writes it.
§

impl<T> Record for T
where T: Wire,

§

fn encode(&self, out: &mut Writer)

Writes the argument into a hook call.
§

fn apply(&mut self, bytes: &[u8]) -> Result<(), WireError>

Applies one complete reply, refusing malformed or trailing bytes atomically.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.