Skip to main content

Textarea

Struct Textarea 

Source
pub struct Textarea {
    pub style: Style,
    pub text_color: Color,
    /* private fields */
}
Expand description

Multi-line editable text area widget (LPAR-14 §5.C).

Wraps EditCore (promoted to rlvgl_core) for the mutation model and uses the LPAR-08 greedy-wrap algorithm for line layout. Supports placeholder text, password masking, optional single-line mode, and vertical overflow scrolling.

§Key navigation

Wire a Keyboard hook to apply_key_output:

keyboard.set_key_output_hook(|ko| ta.apply_key_output(ko));

For direct key injection (hardware keyboard / test harness) use Widget::handle_event with Event::KeyDown.

Fields§

§style: Style

Widget style (background, border).

§text_color: Color

Text colour.

Implementations§

Source§

impl Textarea

Source

pub fn new(bounds: Rect) -> Self

Create a new Textarea occupying bounds with an empty buffer.

Source

pub fn set_text(&mut self, text: &str)

Replace the buffer with text programmatically.

Bypasses the ASCII gate and accept predicate. Clamps the caret to the new length. Fires on_change if registered.

Source

pub fn text(&self) -> &str

Return a reference to the current buffer contents.

Source

pub fn set_placeholder(&mut self, text: &str)

Set the placeholder string shown when the buffer is empty and the field is inactive. Pass "" to clear.

Source

pub fn placeholder(&self) -> Option<&str>

Return the current placeholder string, if any.

Source

pub fn set_password_mode(&mut self, enable: bool)

Enable or disable password masking.

When enabled, every character in the rendered display is replaced by [PASSWORD_GLYPH] (*). The buffer stores the real text.

Source

pub fn password_mode(&self) -> bool

Return true if password masking is active.

Source

pub fn set_one_line(&mut self, enable: bool)

Enable or disable single-line mode.

In one-line mode:

  • '\n' is never inserted; Enter fires on_submit instead.
  • Wrapping is suppressed; the content scrolls horizontally.
Source

pub fn one_line(&self) -> bool

Return true if single-line mode is active.

Source

pub fn is_active(&self) -> bool

Return true when this field is consuming keyboard events.

Source

pub fn set_active(&mut self, active: bool)

Toggle key consumption. Applications keep at most one field active; no focus framework is imposed (WID-00 §7.1).

Source

pub fn caret(&self) -> usize

Return the current caret position (char index, 0..=char_count).

Source

pub fn widget_style(&self) -> &Style

Immutable access to the widget style.

Source

pub fn widget_style_mut(&mut self) -> &mut Style

Mutable access to the widget style.

Source

pub fn set_font(&mut self, font: &'static dyn FontMetrics)

Assign the font used to render this widget (FONT-00 §5); resolves to FONT_6X10 when unset.

Source

pub fn on_change<F: FnMut(&str) + 'static>(self, handler: F) -> Self

Register a change callback invoked after every committed edit and on programmatic set_text calls.

Source

pub fn on_submit<F: FnMut(&str) + 'static>(self, handler: F) -> Self

Register a submit callback fired when Enter is pressed in one-line mode.

Source

pub fn with_accept<F: Fn(char) -> bool + 'static>(self, accept: F) -> Self

Install an accepted-charset predicate (evaluated after the ASCII gate).

Source

pub fn with_max_len(self, max: usize) -> Self

Cap the buffer at max characters.

Source

pub fn apply_key_output(&mut self, ko: KeyOutput)

Apply a KeyOutput value produced by a [Keyboard] widget.

Mapping (LPAR-14 §5.I):

KeyOutputone-line=falseone-line=true
Char(c)try_insert(c)try_insert(c)
Backspacetry_backspace()try_backspace()
Entertry_insert('\n')fire on_submit, no mutation
Tabignoredignored
Escapedeactivatedeactivate
Control(_)ignored (mode handled by Keyboard)same
Source

pub fn scroll_offset_y(&self) -> i32

Return the current vertical scroll offset in pixels.

Trait Implementations§

Source§

impl Widget for Textarea

Source§

fn bounds(&self) -> Rect

Return the area this widget occupies relative to its parent.
Source§

fn widget_font_mut(&mut self) -> Option<&mut WidgetFont>

Expose this widget’s font slot for cascade-driven font resolution (FONT-05 §5.B). Read more
Source§

fn set_bounds(&mut self, new_bounds: Rect)

Called by the LPAR-10 layout pass to notify this widget of its layout-computed bounds. Read more
Source§

fn draw(&self, renderer: &mut dyn Renderer)

Render the widget using the provided Renderer.
Source§

fn handle_event(&mut self, event: &Event) -> bool

Handle an event and return true if it was consumed. Read more
Source§

fn clear_region(&mut self) -> Option<Rect>

Return a region (in draw/landscape coordinates) that should be restored from the pristine background copy, or None. 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, 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.