Skip to main content

EditCore

Struct EditCore 

Source
pub struct EditCore {
    pub bounds: Rect,
    pub buffer: String,
    pub caret: usize,
    pub active: bool,
    pub multi_line: bool,
    pub max_len: Option<usize>,
    pub accept: Option<AcceptFn>,
    pub on_change: Option<ChangeCallback>,
    pub char_width: i32,
    pub line_height: i32,
}
Expand description

Shared edit-state machine for single-line and multi-line text fields (WID-00 §5; LPAR-14 §5.C).

EditCore owns the edit buffer, caret position, and the optional mutation gates (max_len, accept, on_change). Rendering helpers that need glyph geometry or a [Label] remain in the widget wrappers that embed this struct.

§Buffer and caret invariants

  • The buffer may contain arbitrary Unicode inserted via set_text.
  • Interactive insertion via try_insert is limited to printable ASCII (0x20..=0x7E) plus '\n' on multi-line fields (WID-00 §5.2).
  • caret is a char index (0..=char_count()). byte_index converts it to a byte offset for safe String mutation.

Fields§

§bounds: Rect

Text bounds used for caret geometry and derived rendering.

Widgets that embed EditCore expose set_bounds on themselves and forward the update here.

§buffer: String

Edit buffer.

ASCII-bounded for keyboard input so byte index == char index in practice; stored as String so a programmatic set_text can hold arbitrary Unicode without corrupting subsequent edits.

§caret: usize

Caret position as a char index in 0..=char_count().

§active: bool

Whether this field is currently consuming keyboard events.

§multi_line: bool

Whether Enter inserts a newline (true) or signals submit (false).

§max_len: Option<usize>

Optional cap on the number of characters in the buffer.

§accept: Option<AcceptFn>

Optional accepted-charset predicate (applied after the ASCII gate).

§on_change: Option<ChangeCallback>

Optional change callback invoked after every committed edit.

§char_width: i32

Nominal character advance used for caret geometry (pixels).

§line_height: i32

Nominal line height used for caret geometry and line pitch (pixels).

Implementations§

Source§

impl EditCore

Source

pub fn new(text: &str, bounds: Rect, multi_line: bool) -> Self

Create an EditCore with text pre-loaded, caret at the end.

multi_line controls whether Enter inserts a newline.

Source

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

Replace the buffer with text, clamp the caret, fire on_change.

This is the programmatic path; it bypasses the ASCII gate and accept predicate.

Source

pub fn committed(&mut self)

Sync the label/display state and fire on_change after a committed edit (WID-00 §5.1).

Called internally by try_insert and try_backspace; also available for widget wrappers that perform their own buffer mutations.

Source

pub fn byte_index(&self, char_index: usize) -> usize

Convert a char index to a byte offset in Self::buffer.

Safe for any char index in 0..=char_count(); returns buffer.len() for out-of-range values.

Source

pub fn char_count(&self) -> usize

Return the number of chars currently in the buffer.

Source

pub fn try_insert(&mut self, c: char) -> bool

Attempt to insert c at the caret.

Returns true when the edit was applied. Failed insertions leave the buffer and caret untouched and do not fire on_change (WID-00 §5.1).

Gate order:

  1. ASCII printable bound (0x20..=0x7E) plus '\n' on multi-line.
  2. accept predicate (skipped for '\n').
  3. max_len cap.
Source

pub fn try_backspace(&mut self) -> bool

Delete the character before the caret.

Returns true if a character was removed. No-ops silently at position 0 (WID-00 §5.1).

Source

pub fn handle_key(&mut self, key: &Key) -> bool

Handle a raw key event while the field is active.

Returns true when the key was consumed. Enter is not handled here — its semantics differ between single-line (Input fires submit) and multi-line (Textarea inserts newline), so the wrapper is responsible (WID-00 §5.3).

Source

pub fn caret_row_col(&self) -> (i32, i32)

Return the (row, col) of the caret in '\n'-split line space.

Row 0 is the first line; col 0 is the start of a line.

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

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.