Struct rat_widget::masked_input::MaskedInputState
source · pub struct MaskedInputState {
pub focus: FocusFlag,
pub invalid: bool,
pub area: Rect,
pub inner: Rect,
pub mouse: MouseFlags,
pub value: InputMaskCore,
pub non_exhaustive: NonExhaustive,
}Expand description
State of the input-mask.
Fields§
§focus: FocusFlagCurrent focus state.
invalid: boolDisplay as invalid.
area: RectArea with block
inner: RectArea
mouse: MouseFlagsMouse selection in progress.
value: InputMaskCoreEditing core.
non_exhaustive: NonExhaustiveConstruct with ..Default::default()
Implementations§
source§impl MaskedInputState
impl MaskedInputState
pub fn new() -> Self
sourcepub fn new_with_symbols(sym: NumberSymbols) -> Self
pub fn new_with_symbols(sym: NumberSymbols) -> Self
Uses localized symbols for number formatting.
sourcepub fn set_invalid(&mut self, invalid: bool)
pub fn set_invalid(&mut self, invalid: bool)
Renders the widget in invalid style.
sourcepub fn get_invalid(&self) -> bool
pub fn get_invalid(&self) -> bool
Renders the widget in invalid style.
sourcepub fn set_offset(&mut self, offset: usize)
pub fn set_offset(&mut self, offset: usize)
Offset shown. This is corrected if the cursor wouldn’t be visible.
sourcepub fn set_cursor(&mut self, cursor: usize, extend_selection: bool) -> bool
pub fn set_cursor(&mut self, cursor: usize, extend_selection: bool) -> bool
Set the cursor position, reset selection.
sourcepub fn set_default_cursor(&mut self)
pub fn set_default_cursor(&mut self)
Place cursor at decimal separator, if any. 0 otherwise.
sourcepub fn set_display_mask<S: Into<String>>(&mut self, s: S)
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.
sourcepub fn display_mask(&self) -> String
pub fn display_mask(&self) -> String
Display mask.
sourcepub fn set_mask<S: AsRef<str>>(&mut self, s: S) -> Result<(), Error>
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.
sourcepub fn debug_mask(&self) -> String
pub fn debug_mask(&self) -> String
Mask with some debug information.
sourcepub fn set_num_symbols(&mut self, sym: NumberSymbols)
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 “-”.
sourcepub fn default_value(&self) -> String
pub fn default_value(&self) -> String
Create a default value according to the mask.
sourcepub fn set_value<S: Into<String>>(&mut self, s: S)
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.
sourcepub fn value(&self) -> &str
pub fn value(&self) -> &str
Value with all punctuation and default values according to the mask type.
sourcepub fn value_parts(&self) -> Vec<String>
pub fn value_parts(&self) -> Vec<String>
Value split along any separators
sourcepub fn compact_value(&self) -> String
pub fn compact_value(&self) -> String
Value without optional whitespace and grouping separators. Might be easier to parse.
sourcepub fn has_selection(&self) -> bool
pub fn has_selection(&self) -> bool
Selection
sourcepub fn set_selection(&mut self, anchor: usize, cursor: usize) -> bool
pub fn set_selection(&mut self, anchor: usize, cursor: usize) -> bool
Selection
sourcepub fn select_all(&mut self) -> bool
pub fn select_all(&mut self) -> bool
Selection
sourcepub fn selected_value(&self) -> &str
pub fn selected_value(&self) -> &str
Selection
sourcepub fn insert_char(&mut self, c: char) -> bool
pub fn insert_char(&mut self, c: char) -> bool
Insert a char at the current position.
sourcepub fn delete_range(&mut self, range: Range<usize>) -> bool
pub fn delete_range(&mut self, range: Range<usize>) -> bool
Remove the selected range. The text will be replaced with the default value as defined by the mask.
sourcepub fn delete_next_word(&mut self) -> bool
pub fn delete_next_word(&mut self) -> bool
Deletes the next word.
sourcepub fn delete_prev_word(&mut self) -> bool
pub fn delete_prev_word(&mut self) -> bool
Deletes the given range.
sourcepub fn delete_prev_char(&mut self) -> bool
pub fn delete_prev_char(&mut self) -> bool
Delete the char before the cursor.
sourcepub fn delete_next_char(&mut self) -> bool
pub fn delete_next_char(&mut self) -> bool
Delete the char after the cursor.
pub fn move_to_next_word(&mut self, extend_selection: bool) -> bool
pub fn move_to_prev_word(&mut self, extend_selection: bool) -> bool
sourcepub fn move_to_next(&mut self, extend_selection: bool) -> bool
pub fn move_to_next(&mut self, extend_selection: bool) -> bool
Move to the next char.
sourcepub fn move_to_prev(&mut self, extend_selection: bool) -> bool
pub fn move_to_prev(&mut self, extend_selection: bool) -> bool
Move to the previous char.
sourcepub fn move_to_line_start(&mut self, extend_selection: bool) -> bool
pub fn move_to_line_start(&mut self, extend_selection: bool) -> bool
Start of line
sourcepub fn move_to_line_end(&mut self, extend_selection: bool) -> bool
pub fn move_to_line_end(&mut self, extend_selection: bool) -> bool
End of line
sourcepub fn to_screen_col(&self, pos: usize) -> Option<u16>
pub fn to_screen_col(&self, pos: usize) -> Option<u16>
Converts a grapheme based position to a screen position relative to the widget area.
sourcepub fn from_screen_col(&self, x: usize) -> Option<usize>
pub fn from_screen_col(&self, x: usize) -> Option<usize>
Converts from a widget relative screen coordinate to a grapheme index. x is the relative screen position.
sourcepub fn set_screen_cursor(
&mut self,
cursor: isize,
extend_selection: bool,
) -> bool
pub fn set_screen_cursor( &mut self, cursor: isize, 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.
sourcepub fn screen_cursor(&self) -> Option<(u16, u16)>
pub fn screen_cursor(&self) -> Option<(u16, u16)>
The current text cursor as an absolute screen position.
Trait Implementations§
source§impl Clone for MaskedInputState
impl Clone for MaskedInputState
source§fn clone(&self) -> MaskedInputState
fn clone(&self) -> MaskedInputState
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for MaskedInputState
impl Debug for MaskedInputState
source§impl Default for MaskedInputState
impl Default for MaskedInputState
source§impl HandleEvent<Event, FocusKeys, TextOutcome> for MaskedInputState
impl HandleEvent<Event, FocusKeys, TextOutcome> for MaskedInputState
source§impl HandleEvent<Event, MouseOnly, TextOutcome> for MaskedInputState
impl HandleEvent<Event, MouseOnly, TextOutcome> for MaskedInputState
source§impl HandleEvent<Event, ReadOnly, TextOutcome> for MaskedInputState
impl HandleEvent<Event, ReadOnly, TextOutcome> for MaskedInputState
source§impl HasFocusFlag for MaskedInputState
impl HasFocusFlag for MaskedInputState
source§fn z_areas(&self) -> &[ZRect]
fn z_areas(&self) -> &[ZRect]
source§fn is_focused(&self) -> bool
fn is_focused(&self) -> bool
source§fn lost_focus(&self) -> bool
fn lost_focus(&self) -> bool
source§fn gained_focus(&self) -> bool
fn gained_focus(&self) -> bool
Auto Trait Implementations§
impl !Freeze for MaskedInputState
impl !RefUnwindSafe for MaskedInputState
impl Send for MaskedInputState
impl !Sync for MaskedInputState
impl Unpin for MaskedInputState
impl UnwindSafe for MaskedInputState
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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