pub struct TextareaState {
pub lines: Vec<String>,
pub cursor_row: usize,
pub cursor_col: usize,
pub max_length: Option<usize>,
pub wrap_width: Option<u32>,
pub scroll_offset: usize,
/* private fields */
}Expand description
State for a multi-line text area widget.
Pass a mutable reference to Context::textarea each frame along with the
number of visible rows. The widget handles all keyboard events when focused.
§Undo / redo
Ctrl+Z undoes the most recent edit and Ctrl+Y redoes it. The widget
pushes a snapshot before every destructive mutation (char insert, delete,
Enter, Backspace, paste). Rapid character typing coalesces into a single
undoable batch — only the first char of a typing burst pushes a snapshot.
History is capped at history_max entries (default
100); the oldest snapshot is dropped when the cap is exceeded.
§Example
let mut state = TextareaState::new();
// Type, then press Ctrl+Z to undo or Ctrl+Y to redo.
ui.textarea(&mut state, 5);Fields§
§lines: Vec<String>The lines of text, one entry per line.
cursor_row: usizeRow index of the cursor (0-based, logical line).
cursor_col: usizeColumn index of the cursor within the current row (character index).
max_length: Option<usize>Maximum total character count across all lines.
wrap_width: Option<u32>When set, lines longer than this display-column width are soft-wrapped.
scroll_offset: usizeFirst visible visual line (managed internally by textarea()).
Implementations§
Source§impl TextareaState
impl TextareaState
Sourcepub fn set_value(&mut self, text: impl Into<String>)
pub fn set_value(&mut self, text: impl Into<String>)
Replace the content with the given text, splitting on newlines.
Resets the cursor to the beginning of the first line and clears the undo history — programmatic replacement is treated as a fresh state, not an undoable edit.
Sourcepub fn max_length(self, len: usize) -> Self
pub fn max_length(self, len: usize) -> Self
Set the maximum allowed total character count.
Sourcepub fn word_wrap(self, width: u32) -> Self
pub fn word_wrap(self, width: u32) -> Self
Enable soft word-wrap at the given display-column width.
Sourcepub fn history_max(self, cap: usize) -> Self
pub fn history_max(self, cap: usize) -> Self
Override the maximum number of undo snapshots kept (default 100).
When the history exceeds this cap the oldest snapshot is dropped.
Setting 0 disables undo recording — the field is read every keypress.
Sourcepub fn history_len(&self) -> usize
pub fn history_len(&self) -> usize
Number of undo snapshots currently retained.
Read-only — useful for tests and debugging the history cap. The cap
itself is set via history_max.
Sourcepub fn history_cap(&self) -> usize
pub fn history_cap(&self) -> usize
Maximum number of undo snapshots retained.
Mirrors history_max (the builder setter) but as
a getter — useful for tests asserting the cap stays bounded.
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 more