pub struct TextArea<'a, C: PixelColor, M: Clone> { /* private fields */ }Expand description
Editable multi-line text field.
Borrows the text as Cow<'a, str> and reads a host-owned cursor position
(char index). It emits a message via on_tap carrying
the nearest char index when tapped, so the host can move its cursor.
Implementations§
Source§impl<'a, C: PixelColor, M: Clone> TextArea<'a, C, M>
impl<'a, C: PixelColor, M: Clone> TextArea<'a, C, M>
Sourcepub fn new(text: impl Into<Cow<'a, str>>) -> Self
pub fn new(text: impl Into<Cow<'a, str>>) -> Self
New text area displaying text. The cursor defaults to index 0;
set it with cursor. Position and size are assigned
by the parent container via arrange.
Sourcepub fn cursor(self, index: usize) -> Self
pub fn cursor(self, index: usize) -> Self
Cursor position as a char index into the text. Values past the end are clamped to the char count at draw time.
Sourcepub fn placeholder(self, text: impl Into<Cow<'a, str>>) -> Self
pub fn placeholder(self, text: impl Into<Cow<'a, str>>) -> Self
Dimmed placeholder shown when the text is empty.
Sourcepub fn id(self, id: WidgetId) -> Self
pub fn id(self, id: WidgetId) -> Self
Set a stable id so this text area can participate in focus traversal.
Sourcepub fn color(self, color: C) -> Self
pub fn color(self, color: C) -> Self
Override the text color (default: theme.background.on_base).
Sourcepub fn cursor_color(self, color: C) -> Self
pub fn cursor_color(self, color: C) -> Self
Override the cursor bar color (default: theme.accent.base).
Sourcepub fn placeholder_color(self, color: C) -> Self
pub fn placeholder_color(self, color: C) -> Self
Override the placeholder color (default:
theme.palette.neutral_2).
Sourcepub fn font(self, font: &'a MonoFont<'a>) -> Self
pub fn font(self, font: &'a MonoFont<'a>) -> Self
Override the font (default: theme.default_font()). Must be a
mono font; wrapping relies on character_size.width.
Sourcepub fn on_tap<F: Fn(usize) -> M + 'a>(self, f: F) -> Self
pub fn on_tap<F: Fn(usize) -> M + 'a>(self, f: F) -> Self
Callback receiving the nearest char index when the area is tapped. Without it, taps are ignored. The host typically stores the returned index as its new cursor position.
Tap-to-cursor mapping requires an explicit font (the
theme is not reachable during touch dispatch); without one, taps are
silently ignored.
Trait Implementations§
Source§impl<'a, C: PixelColor, M: Clone> Widget<C, M> for TextArea<'a, C, M>
impl<'a, C: PixelColor, M: Clone> Widget<C, M> for TextArea<'a, C, M>
Source§fn measure(&mut self, constraints: Constraints) -> Size
fn measure(&mut self, constraints: Constraints) -> Size
constraints.Source§fn preferred_size(&self) -> (Length, Length)
fn preferred_size(&self) -> (Length, Length)
.width(...) / .height(...).
Containers consult this during layout to allocate fixed slots,
query intrinsic sizes, and split residual space among
Fill / FillPortion children. Default is Length::Fill on
both axes.Source§fn arrange(&mut self, rect: Rectangle)
fn arrange(&mut self, rect: Rectangle)
Source§fn handle_touch(&mut self, point: Point, phase: TouchPhase) -> Option<M>
fn handle_touch(&mut self, point: Point, phase: TouchPhase) -> Option<M>
Source§fn widget_id(&self) -> Option<WidgetId>
fn widget_id(&self) -> Option<WidgetId>
Source§fn is_focusable(&self) -> bool
fn is_focusable(&self) -> bool
Source§fn handle_action(&mut self, action: UiAction) -> Option<M>
fn handle_action(&mut self, action: UiAction) -> Option<M>
Source§fn sync_focus(&mut self, focused: Option<WidgetId>)
fn sync_focus(&mut self, focused: Option<WidgetId>)
Source§fn draw<'t>(
&self,
renderer: &mut dyn Renderer<C>,
theme: &Theme<'t, C>,
) -> Result<(), RenderError>
fn draw<'t>( &self, renderer: &mut dyn Renderer<C>, theme: &Theme<'t, C>, ) -> Result<(), RenderError>
renderer at rect.Source§fn mark_pressed(&mut self, point: Point)
fn mark_pressed(&mut self, point: Point)
point hits. No message emit.
Containers forward to children. Default no-op.Source§fn collect_focusable(&self, out: &mut Vec<WidgetId>)
fn collect_focusable(&self, out: &mut Vec<WidgetId>)
Source§fn route_action(&mut self, target: WidgetId, action: UiAction) -> Option<M>
fn route_action(&mut self, target: WidgetId, action: UiAction) -> Option<M>
target.target for directional actions.Auto Trait Implementations§
impl<'a, C, M> Freeze for TextArea<'a, C, M>where
C: Freeze,
impl<'a, C, M> !RefUnwindSafe for TextArea<'a, C, M>
impl<'a, C, M> !Send for TextArea<'a, C, M>
impl<'a, C, M> !Sync for TextArea<'a, C, M>
impl<'a, C, M> Unpin for TextArea<'a, C, M>where
C: Unpin,
impl<'a, C, M> UnsafeUnpin for TextArea<'a, C, M>where
C: UnsafeUnpin,
impl<'a, C, M> !UnwindSafe for TextArea<'a, C, M>
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> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<'a, C, M, W> IntoElement<'a, C, M> for W
impl<'a, C, M, W> IntoElement<'a, C, M> for W
Source§fn into_element(self) -> Element<'a, C, M>
fn into_element(self) -> Element<'a, C, M>
self.