Struct rat_input::masked_input::MaskedInputState

source ·
pub struct MaskedInputState {
    pub cursor: Position,
    pub area: Rect,
    pub mouse: MouseFlags,
    pub value: InputMaskCore,
    pub non_exhaustive: NonExhaustive,
}
Expand description

State of the input-mask.

Fields§

§cursor: Position

The position of the cursor in screen coordinates. Can be directly used for [Frame::set_cursor()]

§area: Rect

Area

§mouse: MouseFlags

Mouse selection in progress.

§value: InputMaskCore

Editing core.

§non_exhaustive: NonExhaustive

Construct with ..Default::default()

Implementations§

source§

impl MaskedInputState

source

pub fn new() -> Self

source

pub fn new_with_symbols(sym: NumberSymbols) -> Self

source

pub fn reset(&mut self)

Reset to empty.

source

pub fn offset(&self) -> usize

Offset shown.

source

pub fn set_offset(&mut self, offset: usize)

Offset shown. This is corrected if the cursor wouldn’t be visible.

source

pub fn set_cursor(&mut self, cursor: usize, extend_selection: bool)

Set the cursor position, reset selection.

source

pub fn set_default_cursor(&mut self)

Place cursor at decimal separator, if any. 0 otherwise.

source

pub fn cursor(&self) -> usize

Cursor position

source

pub fn set_display_mask<S: Into<String>>(&mut self, s: S)

Set the display mask. This text is used for parts that have no valid input yet. Part means consecutive characters of the input mask with the same mask type.

There is a default representation for each mask type if this is not set.

If the length differs from the mask, the difference will be ignored / filled with defaults.

source

pub fn display_mask(&self) -> String

Display mask.

source

pub fn set_mask<S: AsRef<str>>(&mut self, s: S) -> Result<(), Error>

Set the input mask. This overwrites the display mask and the value with a default representation of the mask.

The result value contains all punctuation and the value given as ‘display’ below. See compact_value().

  • 0: can enter digit, display as 0

  • 9: can enter digit, display as space

  • #: digit, plus or minus sign, display as space

  • +: sign. display ‘+’ for positive

  • -: sign. display ’ ’ for positive

  • . and ,: decimal and grouping separators

  • H: must enter a hex digit, display as 0

  • h: can enter a hex digit, display as space

  • O: must enter an octal digit, display as 0

  • o: can enter an octal digit, display as space

  • D: must enter a decimal digit, display as 0

  • d: can enter a decimal digit, display as space

  • l: can enter letter, display as space

  • a: can enter letter or digit, display as space

  • c: can enter character or space, display as space

  • _: anything, display as space

  • : ; - /: separator characters move the cursor when entered.

  • \: escapes the following character and uses it as a separator.

  • all other ascii characters a reserved.

Inspired by https://support.microsoft.com/en-gb/office/control-data-entry-formats-with-input-masks-e125997a-7791-49e5-8672-4a47832de8da

source

pub fn mask(&self) -> String

Display mask.

source

pub fn debug_mask(&self) -> String

Mask with some debug information.

source

pub fn set_num_symbols(&mut self, sym: NumberSymbols)

Set symbols for number display.

These are only used for rendering and to map user input. The value itself uses “.”, “,” and “-”.

source

pub fn default_value(&self) -> String

Create a default value according to the mask.

source

pub fn set_value<S: Into<String>>(&mut self, s: S)

Set the value.

No checks if the value conforms to the mask. If the value is too short it will be filled with space. if the value is too long it will be truncated.

source

pub fn value(&self) -> &str

Value with all punctuation and default values according to the mask type.

source

pub fn value_parts(&self) -> Vec<String>

Value split along any separators

source

pub fn compact_value(&self) -> String

Value without optional whitespace and grouping separators. Might be easier to parse.

source

pub fn as_str(&self) -> &str

Value.

source

pub fn is_empty(&self) -> bool

source

pub fn len(&self) -> usize

Length in grapheme count.

source

pub fn has_selection(&self) -> bool

Selection

source

pub fn set_selection(&mut self, anchor: usize, cursor: usize)

Selection

source

pub fn select_all(&mut self)

Selection

source

pub fn selection(&self) -> Range<usize>

Selection

source

pub fn selection_str(&self) -> &str

Selection

source

pub fn set_offset_relative_cursor( &mut self, rpos: isize, extend_selection: bool )

Set the cursor position from a visual position relative to the origin.

source

pub fn visual_cursor(&self) -> Position

The current text cursor as a absolute screen position.

source

pub fn prev_word_boundary(&self) -> usize

Previous word boundary.

source

pub fn next_word_boundary(&self) -> usize

Next word boundary.

source

pub fn move_to_next(&mut self, extend_selection: bool)

Move to the next char.

source

pub fn move_to_prev(&mut self, extend_selection: bool)

Move to the previous char.

source

pub fn insert_char(&mut self, c: char) -> Result<(), Error>

Insert a char at the current position.

source

pub fn remove_selection(&mut self, selection: Range<usize>) -> Result<(), Error>

Remove the selected range. The text will be replaced with the default value as defined by the mask.

source

pub fn delete_prev_char(&mut self) -> Result<(), Error>

Delete the char before the cursor.

source

pub fn delete_next_char(&mut self) -> Result<(), Error>

Delete the char after the cursor.

Trait Implementations§

source§

impl Clone for MaskedInputState

source§

fn clone(&self) -> MaskedInputState

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for MaskedInputState

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for MaskedInputState

source§

fn default() -> Self

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

impl HandleEvent<Event, FocusKeys, Result<Outcome, Error>> for MaskedInputState

source§

fn handle( &mut self, event: &Event, _keymap: FocusKeys ) -> Result<Outcome, Error>

Handle an event. Read more
source§

impl HandleEvent<Event, MouseOnly, Result<Outcome, Error>> for MaskedInputState

source§

fn handle( &mut self, event: &Event, _keymap: MouseOnly ) -> Result<Outcome, Error>

Handle an event. Read more

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> 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.

source§

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

§

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>,

§

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>,

§

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.