pub struct TextAreaState { /* private fields */ }Expand description
State for a TextArea component.
Implementations§
Source§impl TextAreaState
impl TextAreaState
Sourcepub fn has_selection(&self) -> bool
pub fn has_selection(&self) -> bool
Returns true if there is an active text selection.
Sourcepub fn selection_positions(&self) -> Option<((usize, usize), (usize, usize))>
pub fn selection_positions(&self) -> Option<((usize, usize), (usize, usize))>
Returns the ordered selection positions as ((start_row, start_col), (end_row, end_col)).
Sourcepub fn selected_text(&self) -> Option<String>
pub fn selected_text(&self) -> Option<String>
Returns the selected text, or None if no selection.
Source§impl TextAreaState
impl TextAreaState
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty textarea.
§Example
use envision::component::TextAreaState;
let state = TextAreaState::new();
assert!(state.is_empty());
assert_eq!(state.line_count(), 1);Sourcepub fn with_value(value: impl Into<String>) -> Self
pub fn with_value(value: impl Into<String>) -> Self
Creates a textarea with initial content, split on newlines. Cursor is placed at the end of the content.
Sourcepub fn with_placeholder(placeholder: impl Into<String>) -> Self
pub fn with_placeholder(placeholder: impl Into<String>) -> Self
Creates a textarea with placeholder text.
Sourcepub fn set_value(&mut self, value: impl Into<String>)
pub fn set_value(&mut self, value: impl Into<String>)
Sets the content from a string (splits on \n). Cursor moves to end.
Sourcepub fn cursor_position(&self) -> (usize, usize)
pub fn cursor_position(&self) -> (usize, usize)
Returns the cursor position as (row, char_column).
Sourcepub fn cursor_display_position(&self) -> (usize, usize)
pub fn cursor_display_position(&self) -> (usize, usize)
Returns the cursor display position as (row, terminal_column_width).
Unlike cursor_position() which returns the
character count for the column, this returns the display width
accounting for wide characters (emoji, CJK) that occupy 2 terminal columns.
§Example
use envision::component::{TextArea, TextAreaState, TextAreaMessage, Component};
let mut state = TextArea::init();
TextArea::update(&mut state, TextAreaMessage::Insert('A'));
TextArea::update(&mut state, TextAreaMessage::Insert('\u{1F600}')); // emoji
// Character count is 2 (two characters)
assert_eq!(state.cursor_position(), (0, 2));
// Display width is 3 (A=1 + 😀=2)
assert_eq!(state.cursor_display_position(), (0, 3));Sourcepub fn cursor_row(&self) -> usize
pub fn cursor_row(&self) -> usize
Returns the cursor row.
Sourcepub fn cursor_col(&self) -> usize
pub fn cursor_col(&self) -> usize
Returns the cursor column (byte offset).
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Returns the number of lines.
Sourcepub fn current_line(&self) -> &str
pub fn current_line(&self) -> &str
Returns the current line (at cursor row).
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the textarea is empty.
A textarea is empty if it contains only a single empty line.
Sourcepub fn placeholder(&self) -> &str
pub fn placeholder(&self) -> &str
Returns the placeholder text.
Sourcepub fn set_placeholder(&mut self, placeholder: impl Into<String>)
pub fn set_placeholder(&mut self, placeholder: impl Into<String>)
Sets the placeholder text.
Sourcepub fn scroll_offset(&self) -> usize
pub fn scroll_offset(&self) -> usize
Returns the scroll offset.
Sourcepub fn set_cursor_position(&mut self, row: usize, col: usize)
pub fn set_cursor_position(&mut self, row: usize, col: usize)
Sets the cursor position (row, char_column).
Both row and column are clamped to valid ranges.
Sourcepub fn ensure_cursor_visible(&mut self, visible_lines: usize)
pub fn ensure_cursor_visible(&mut self, visible_lines: usize)
Ensures the cursor is visible within the viewport.
Sourcepub fn is_focused(&self) -> bool
pub fn is_focused(&self) -> bool
Returns true if the textarea is focused.
Sourcepub fn set_focused(&mut self, focused: bool)
pub fn set_focused(&mut self, focused: bool)
Sets the focus state.
Sourcepub fn is_disabled(&self) -> bool
pub fn is_disabled(&self) -> bool
Returns true if the textarea is disabled.
Sourcepub fn set_disabled(&mut self, disabled: bool)
pub fn set_disabled(&mut self, disabled: bool)
Sets the disabled state.
Sourcepub fn with_disabled(self, disabled: bool) -> Self
pub fn with_disabled(self, disabled: bool) -> Self
Sets the disabled state using builder pattern.
Sourcepub fn handle_event(&self, event: &Event) -> Option<TextAreaMessage>
pub fn handle_event(&self, event: &Event) -> Option<TextAreaMessage>
Maps an input event to a textarea message.
Sourcepub fn dispatch_event(&mut self, event: &Event) -> Option<TextAreaOutput>
pub fn dispatch_event(&mut self, event: &Event) -> Option<TextAreaOutput>
Dispatches an event, updating state and returning any output.
Sourcepub fn update(&mut self, msg: TextAreaMessage) -> Option<TextAreaOutput>
pub fn update(&mut self, msg: TextAreaMessage) -> Option<TextAreaOutput>
Updates the textarea state with a message, returning any output.
Trait Implementations§
Source§impl Clone for TextAreaState
impl Clone for TextAreaState
Source§fn clone(&self) -> TextAreaState
fn clone(&self) -> TextAreaState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TextAreaState
impl Debug for TextAreaState
Source§impl Default for TextAreaState
impl Default for TextAreaState
Source§impl<'de> Deserialize<'de> for TextAreaState
impl<'de> Deserialize<'de> for TextAreaState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for TextAreaState
impl PartialEq for TextAreaState
Source§impl Serialize for TextAreaState
impl Serialize for TextAreaState
impl StructuralPartialEq for TextAreaState
Auto Trait Implementations§
impl Freeze for TextAreaState
impl RefUnwindSafe for TextAreaState
impl Send for TextAreaState
impl Sync for TextAreaState
impl Unpin for TextAreaState
impl UnsafeUnpin for TextAreaState
impl UnwindSafe for TextAreaState
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§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