Struct rat_widget::text_input_mask::MaskedInputState

source ·
pub struct MaskedInputState {
    pub focus: FocusFlag,
    pub invalid: bool,
    pub area: Rect,
    pub inner: Rect,
    pub offset: u32,
    pub value: MaskedCore,
    pub mouse: MouseFlags,
    pub non_exhaustive: NonExhaustive,
}
Expand description

State & event-handling.

Fields§

§focus: FocusFlag

Current focus state.

§invalid: bool

Display as invalid.

§area: Rect

The whole area with block.

§inner: Rect

Area inside a possible block.

§offset: u32

Display offset

§value: MaskedCore

Editing core

§mouse: MouseFlags

Mouse selection in progress.

§non_exhaustive: NonExhaustive

Construct with ..Default::default()

Implementations§

source§

impl MaskedInputState

source

pub fn new() -> MaskedInputState

source

pub fn named(name: &str) -> MaskedInputState

source

pub fn with_symbols(self, sym: NumberSymbols) -> MaskedInputState

With localized symbols for number formatting.

source

pub fn with_mask<S>(self, mask: S) -> Result<MaskedInputState, Error>
where S: AsRef<str>,

With input mask.

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 set_mask<S>(&mut self, s: S) -> Result<(), Error>
where S: AsRef<str>,

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

  • SPACE: separator character 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 set_invalid(&mut self, invalid: bool)

Renders the widget in invalid style.

source

pub fn get_invalid(&self) -> bool

Renders the widget in invalid style.

source§

impl MaskedInputState

source

pub fn set_clipboard(&mut self, clip: Option<impl Clipboard + 'static>)

Clipboard

source

pub fn clipboard(&self) -> Option<&dyn Clipboard>

Clipboard

source

pub fn copy_to_clip(&mut self) -> bool

Copy to internal buffer

source

pub fn cut_to_clip(&mut self) -> bool

Cut to internal buffer

source

pub fn paste_from_clip(&mut self) -> bool

Paste from internal buffer.

source§

impl MaskedInputState

source

pub fn set_undo_buffer(&mut self, undo: Option<impl UndoBuffer + 'static>)

Set undo buffer.

source

pub fn undo_buffer(&self) -> Option<&dyn UndoBuffer>

Undo

source

pub fn undo_buffer_mut(&mut self) -> Option<&mut dyn UndoBuffer>

Undo

source

pub fn recent_replay_log(&mut self) -> Vec<UndoEntry>

Get all recent replay recordings.

source

pub fn replay_log(&mut self, replay: &[UndoEntry])

Apply the replay recording.

source

pub fn undo(&mut self) -> bool

Undo operation

source

pub fn redo(&mut self) -> bool

Redo operation

source§

impl MaskedInputState

source

pub fn set_styles(&mut self, styles: Vec<(Range<usize>, usize)>)

Set and replace all styles.

source

pub fn add_style(&mut self, range: Range<usize>, style: usize)

Add a style for a [TextRange]. The style-nr refers to one of the styles set with the widget.

source

pub fn add_range_style( &mut self, range: Range<u32>, style: usize, ) -> Result<(), TextError>

Add a style for a Range<upos_type> to denote the cells. The style-nr refers to one of the styles set with the widget.

source

pub fn remove_style(&mut self, range: Range<usize>, style: usize)

Remove the exact TextRange and style.

source

pub fn remove_range_style( &mut self, range: Range<u32>, style: usize, ) -> Result<(), TextError>

Remove the exact Range<upos_type> and style.

source

pub fn styles_in( &self, range: Range<usize>, buf: &mut Vec<(Range<usize>, usize)>, )

Find all styles that touch the given range.

source

pub fn styles_at(&self, byte_pos: usize, buf: &mut Vec<(Range<usize>, usize)>)

All styles active at the given position.

source

pub fn style_match(&self, byte_pos: usize, style: usize) -> Option<Range<usize>>

Check if the given style applies at the position and return the complete range for the style.

source

pub fn styles(&self) -> Option<impl Iterator<Item = (Range<usize>, usize)>>

List of all styles.

source§

impl MaskedInputState

source

pub fn offset(&self) -> u32

Offset shown.

source

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

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

source

pub fn cursor(&self) -> u32

Cursor position.

source

pub fn set_cursor(&mut self, cursor: u32, extend_selection: bool) -> bool

Set the cursor position, reset selection.

source

pub fn set_default_cursor(&mut self)

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

source

pub fn anchor(&self) -> u32

Selection anchor.

source

pub fn has_selection(&self) -> bool

Selection.

source

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

Selection.

source

pub fn set_selection(&mut self, anchor: u32, cursor: u32) -> bool

Selection.

source

pub fn select_all(&mut self) -> bool

Selection.

source

pub fn selected_text(&self) -> &str

Selection.

source§

impl MaskedInputState

source

pub fn is_empty(&self) -> bool

Empty

source

pub fn text(&self) -> &str

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

source

pub fn str_slice_byte(&self, range: Range<usize>) -> Cow<'_, str>

Text slice as Cow. Uses a byte range.

source

pub fn try_str_slice_byte( &self, range: Range<usize>, ) -> Result<Cow<'_, str>, TextError>

Text slice as Cow. Uses a byte range.

source

pub fn str_slice(&self, range: Range<u32>) -> Cow<'_, str>

Text slice as Cow

source

pub fn try_str_slice( &self, range: Range<u32>, ) -> Result<Cow<'_, str>, TextError>

Text slice as Cow

source

pub fn len(&self) -> u32

Length as grapheme count.

source

pub fn line_width(&self) -> u32

Length as grapheme count.

source

pub fn glyphs( &self, screen_offset: u16, screen_width: u16, ) -> impl Iterator<Item = Glyph<'_>>

Iterator for the glyphs of the lines in range. Glyphs here a grapheme + display length.

source

pub fn condensed_glyphs( &self, screen_offset: u16, screen_width: u16, ) -> impl Iterator<Item = Glyph<'_>>

Iterator for the glyphs of the lines in range. Glyphs here a grapheme + display length.

source

pub fn text_graphemes( &self, pos: u32, ) -> impl Iterator<Item = Grapheme<'_>> + Cursor

Get a cursor over all the text with the current position set at pos.

source

pub fn try_text_graphemes( &self, pos: u32, ) -> Result<impl Iterator<Item = Grapheme<'_>> + Cursor, TextError>

Get a cursor over all the text with the current position set at pos.

source

pub fn graphemes( &self, range: Range<u32>, pos: u32, ) -> impl Iterator<Item = Grapheme<'_>> + Cursor

Get a cursor over the text-range the current position set at pos.

source

pub fn try_graphemes( &self, range: Range<u32>, pos: u32, ) -> Result<impl Iterator<Item = Grapheme<'_>> + Cursor, TextError>

Get a cursor over the text-range the current position set at pos.

source

pub fn byte_at(&self, pos: u32) -> Range<usize>

Grapheme position to byte position. This is the (start,end) position of the single grapheme after pos.

source

pub fn try_byte_at(&self, pos: u32) -> Result<Range<usize>, TextError>

Grapheme position to byte position. This is the (start,end) position of the single grapheme after pos.

source

pub fn bytes_at_range(&self, range: Range<u32>) -> Range<usize>

Grapheme range to byte range.

source

pub fn try_bytes_at_range( &self, range: Range<u32>, ) -> Result<Range<usize>, TextError>

Grapheme range to byte range.

source

pub fn byte_pos(&self, byte: usize) -> u32

Byte position to grapheme position. Returns the position that contains the given byte index.

source

pub fn try_byte_pos(&self, byte: usize) -> Result<u32, TextError>

Byte position to grapheme position. Returns the position that contains the given byte index.

source

pub fn byte_range(&self, bytes: Range<usize>) -> Range<u32>

Byte range to grapheme range.

source

pub fn try_byte_range( &self, bytes: Range<usize>, ) -> Result<Range<u32>, TextError>

Byte range to grapheme range.

source§

impl MaskedInputState

source

pub fn clear(&mut self) -> bool

Reset to empty.

source

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

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 insert_char(&mut self, c: char) -> bool

Insert a char at the current position.

source

pub fn delete_range(&mut self, range: Range<u32>) -> bool

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

source

pub fn try_delete_range(&mut self, range: Range<u32>) -> Result<bool, TextError>

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

source§

impl MaskedInputState

source

pub fn delete_next_char(&mut self) -> bool

Delete the char after the cursor.

source

pub fn delete_prev_char(&mut self) -> bool

Delete the char before the cursor.

source

pub fn delete_prev_section(&mut self) -> bool

Delete the previous section.

source

pub fn delete_next_section(&mut self) -> bool

Delete the next section.

source

pub fn move_right(&mut self, extend_selection: bool) -> bool

Move to the next char.

source

pub fn move_left(&mut self, extend_selection: bool) -> bool

Move to the previous char.

source

pub fn move_to_line_start(&mut self, extend_selection: bool) -> bool

Start of line

source

pub fn move_to_line_end(&mut self, extend_selection: bool) -> bool

End of line

source

pub fn move_to_prev_section(&mut self, extend_selection: bool) -> bool

Move to start of previous section.

source

pub fn move_to_next_section(&mut self, extend_selection: bool) -> bool

Move to end of previous section.

source

pub fn select_current_section(&mut self) -> bool

Select next section.

source

pub fn select_next_section(&mut self) -> bool

Select next section.

source

pub fn select_prev_section(&mut self) -> bool

Select previous section.

source§

impl MaskedInputState

source

pub fn col_to_screen(&self, pos: u32) -> u16

Converts a grapheme based position to a screen position relative to the widget area.

source

pub fn screen_to_col(&self, scx: i16) -> u32

Converts from a widget relative screen coordinate to a grapheme index. x is the relative screen position.

source

pub fn set_screen_cursor(&mut self, cursor: i16, extend_selection: bool) -> bool

Set the cursor position from a screen position relative to the origin of the widget. This value can be negative, which selects a currently not visible position and scrolls to it.

source

pub fn set_screen_cursor_sections( &mut self, screen_cursor: i16, extend_selection: bool, ) -> bool

Set the cursor position from screen coordinates, rounds the position to the next section bounds.

The cursor positions are relative to the inner rect. They may be negative too, this allows setting the cursor to a position that is currently scrolled away.

source

pub fn scroll_left(&mut self, delta: u32) -> bool

Scrolling

source

pub fn scroll_right(&mut self, delta: u32) -> bool

Scrolling

source

pub fn scroll_cursor_to_visible(&mut self) -> bool

Change the offset in a way that the cursor is visible.

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<(), Error>

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

impl Default for MaskedInputState

source§

fn default() -> MaskedInputState

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

impl HandleEvent<Event, MouseOnly, TextOutcome> for MaskedInputState

source§

fn handle(&mut self, event: &Event, _keymap: MouseOnly) -> TextOutcome

Handle an event. Read more
source§

impl HandleEvent<Event, ReadOnly, TextOutcome> for MaskedInputState

source§

fn handle(&mut self, event: &Event, _keymap: ReadOnly) -> TextOutcome

Handle an event. Read more
source§

impl HandleEvent<Event, Regular, TextOutcome> for MaskedInputState

source§

fn handle(&mut self, event: &Event, _keymap: Regular) -> TextOutcome

Handle an event. Read more
source§

impl HasFocusFlag for MaskedInputState

source§

fn focus(&self) -> FocusFlag

Access to the flag for the rest.
source§

fn area(&self) -> Rect

Access the area for mouse focus.
source§

fn navigable(&self) -> Navigation

Declares how the widget interacts with focus. Read more
source§

fn z_areas(&self) -> &[ZRect]

The widget might have several disjointed areas. This is the case if it is showing a popup, but there might be other causes. Read more
source§

fn is_focused(&self) -> bool

Focused?
source§

fn lost_focus(&self) -> bool

Just lost focus.
source§

fn gained_focus(&self) -> bool

Just gained focus.
source§

impl HasScreenCursor for MaskedInputState

source§

fn screen_cursor(&self) -> Option<(u16, u16)>

The current text cursor as an absolute screen position.

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, dst: *mut T)

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

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

source§

fn __clone_box(&self, _: Private) -> *mut ()

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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
source§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.