Skip to main content

TextBox

Struct TextBox 

Source
pub struct TextBox {
Show 28 fields pub controller: TextEditingControllerRef, pub focus_node: Option<FocusNodeRef>, pub header: Option<WidgetRef>, pub description: Option<WidgetRef>, pub placeholder_text: String, pub is_enabled: bool, pub font_size: Option<f64>, pub padding: Option<[f64; 4]>, pub corner_radius: Option<f64>, pub foreground: Option<Color>, pub background: Option<Brush>, pub border_brush: Option<Brush>, pub selection_highlight_color: Option<Color>, pub max_length: Option<i32>, pub input_formatters: Vec<TextInputFormatterRef>, pub autofocus: bool, pub show_cursor: Option<bool>, pub context_menu_builder: Option<EditableTextContextMenuBuilder>, pub is_read_only: bool, pub accepts_return: bool, pub text_wrapping: TextWrapping, pub horizontal_scroll_bar_visibility: ScrollBarVisibility, pub max_lines: Option<i32>, pub text_alignment: TextAlign, pub placeholder_foreground: Option<Color>, pub text_changed: Option<TextChangedCallback>, pub selection_changed: Option<TextSelectionChangedCallback>, pub key: Option<KeyRef>,
}
Expand description

The WinUI TextBox control with its default Fluent template.

Fields§

§controller: TextEditingControllerRef

Owns the text, selection and composing range; the caller retains and disposes it.

§focus_node: Option<FocusNodeRef>

An optional caller-owned focus node; otherwise the control creates one.

§header: Option<WidgetRef>

Content above the editor, with the source header margin.

§description: Option<WidgetRef>

Supporting content below the editor.

§placeholder_text: String

Text displayed while the controller is empty.

§is_enabled: bool

Whether the editor accepts pointer and keyboard input.

§font_size: Option<f64>

The editor font size and basis of the helper-button width threshold; the theme’s ControlContentThemeFontSize when None.

§padding: Option<[f64; 4]>

Editor padding in left, top, right, bottom order; the theme’s TextControlThemePadding when None.

§corner_radius: Option<f64>

The template border and helper-button corner radius.

§foreground: Option<Color>

Overrides the normal editor foreground; visual states use their source theme resources.

§background: Option<Brush>

Overrides the normal editor background.

§border_brush: Option<Brush>

Overrides the normal editor border brush.

§selection_highlight_color: Option<Color>

Overrides the selection fill while the editor has focus.

§max_length: Option<i32>

Limits user edits through the native length formatter; programmatic assignments remain unrestricted.

§input_formatters: Vec<TextInputFormatterRef>

Native formatters applied to user edits, following Flutter composition and undo behavior.

§autofocus: bool

Requests initial keyboard focus through the native editor.

§show_cursor: Option<bool>

Whether the caret is drawn while the box has the focus; Flutter’s TextField.showCursor, which XAML’s TextBox has no property for. None draws it unless the box is read-only. A box that hides it still takes what is typed.

§context_menu_builder: Option<EditableTextContextMenuBuilder>

Overrides the desktop text-command menu.

§is_read_only: bool

Allows selection and copying while preventing edits.

§accepts_return: bool

Accepts line breaks and enables native wrapped multiline editing.

A multiline box fills the height its parent gives it, as WinUI’s default VerticalAlignment="Stretch" does, and its editor scrolls once the text passes it; in an unbounded parent it grows with its text.

§text_wrapping: TextWrapping

Wraps text independently of accepting Enter; with NoWrap, a multiline box keeps each line whole and scrolls sideways.

§horizontal_scroll_bar_visibility: ScrollBarVisibility

ScrollViewer.HorizontalScrollBarVisibility: how a multiline box that does not wrap scrolls its lines sideways.

§max_lines: Option<i32>

Limits the visible height in lines for a multiline editor, which grows with its text from one line up to it; past it, the content scrolls vertically. Setting it leaves the editor at that height instead of filling the box; leave it unset for a box that fills its pane.

§text_alignment: TextAlign

Alignment of editor and placeholder text.

§placeholder_foreground: Option<Color>

Overrides the placeholder foreground in every visual state.

§text_changed: Option<TextChangedCallback>

Receives user text edits and clear-button actions; listen to the controller for all assignments.

§selection_changed: Option<TextSelectionChangedCallback>

Receives native user selection changes after the controller updates.

§key: Option<KeyRef>

Identity retained across parent rebuilds.

Implementations§

Source§

impl TextBox

Source

pub fn new(controller: TextEditingControllerRef) -> Self

Creates an editor using a caller-owned native editing controller.

Source

pub fn focus_node(self, value: FocusNodeRef) -> Self

Sets FocusNode.

Source

pub fn header<K>(self, value: impl IntoWidget<K>) -> Self

Sets Header.

Source

pub fn description<K>(self, value: impl IntoWidget<K>) -> Self

Sets Description.

Source

pub fn placeholder_text(self, value: impl Into<String>) -> Self

Sets PlaceholderText.

Source

pub fn is_enabled(self, value: bool) -> Self

Sets IsEnabled.

Source

pub fn font_size(self, value: f64) -> Self

Sets FontSize.

Source

pub fn padding(self, value: [f64; 4]) -> Self

Sets Padding.

Source

pub fn corner_radius(self, value: f64) -> Self

Sets CornerRadius.

Source

pub fn foreground(self, value: Color) -> Self

Sets Foreground.

Source

pub fn background(self, value: Brush) -> Self

Sets Background.

Source

pub fn border_brush(self, value: Brush) -> Self

Sets BorderBrush.

Source

pub fn selection_highlight_color(self, value: Color) -> Self

Sets SelectionHighlightColor.

Source

pub fn max_length(self, value: i32) -> Self

Sets MaxLength.

Source

pub fn input_formatters(self, value: Vec<TextInputFormatterRef>) -> Self

Sets InputFormatters.

Source

pub fn autofocus(self, value: bool) -> Self

Sets Autofocus.

Source

pub fn context_menu_builder( self, value: impl Fn(&mut App, BuildContext, Handle<EditableTextState>) -> WidgetRef + 'static, ) -> Self

Sets ContextMenuBuilder.

Source

pub fn is_read_only(self, value: bool) -> Self

Sets IsReadOnly.

Source

pub fn accepts_return(self, value: bool) -> Self

Sets AcceptsReturn.

Source

pub fn text_wrapping(self, value: TextWrapping) -> Self

Sets TextWrapping.

Source

pub fn horizontal_scroll_bar_visibility( self, value: ScrollBarVisibility, ) -> Self

Sets ScrollViewer.HorizontalScrollBarVisibility.

Source

pub fn max_lines(self, value: i32) -> Self

Sets MaxLines.

Source

pub fn text_alignment(self, value: TextAlign) -> Self

Sets TextAlignment.

Source

pub fn show_cursor(self, value: bool) -> Self

Whether the caret is drawn while the box has the focus: Flutter’s TextField.showCursor.

Source

pub fn placeholder_foreground(self, value: Color) -> Self

Sets PlaceholderForeground.

Source

pub fn text_changed(self, value: impl Fn(&mut App, String) + 'static) -> Self

Sets TextChanged.

Source

pub fn selection_changed( self, value: impl Fn(&mut App, TextSelection, Option<SelectionChangedCause>) + 'static, ) -> Self

Sets SelectionChanged.

Source

pub fn key(self, key: KeyRef) -> Self

Sets widget identity.

Trait Implementations§

Source§

impl Clone for TextBox

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TextBox

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl StatefulWidget for TextBox

Source§

type State = TextBoxState

The state this widget creates.
Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn create_state(&self) -> TextBoxState

Creates the mutable state for this widget at a given location in the tree. Read more
Source§

fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s debugFillProperties: the properties a dump shows for this widget, in Dart’s order. Dart’s Widget base only sets the dense tree style, which the framework does.
Source§

fn debug_check_constructor(&self)

Source§

fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>

Source§

fn type_name(&self) -> &'static str

See Widget::type_name. A stateful form another widget kind becomes (an animated or status transition widget) names the widget it wraps.

Auto Trait Implementations§

§

impl !RefUnwindSafe for TextBox

§

impl !Send for TextBox

§

impl !Sync for TextBox

§

impl !UnwindSafe for TextBox

§

impl Forget for TextBox

§

impl Freeze for TextBox
where NonZero<u32>: Freeze, &'static TextEditingControllerVTable: Freeze, *const RcInner<Keep> is !null: Freeze, PhantomData<RcInner<Keep>>: Freeze, &'static FocusNodeVTable: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<TextInputFormatterRef>: Freeze, *const RcInner<dyn Fn(&mut App, AnyElement, Handle<EditableTextState>) -> Rc<dyn Widget>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, Handle<EditableTextState>) -> Rc<dyn Widget>>>: Freeze, *const RcInner<dyn Fn(&mut App, String)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, String)>>: Freeze, *const RcInner<dyn Fn(&mut App, TextSelection, Option<SelectionChangedCause>)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, TextSelection, Option<SelectionChangedCause>)>>: Freeze, *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze,

§

impl Move for TextBox

§

impl Unpin for TextBox
where NonZero<u32>: Unpin, &'static TextEditingControllerVTable: Unpin, Rc<Keep>: Unpin, &'static FocusNodeVTable: Unpin, Rc<dyn Widget>: Unpin, *const u8 is !null: Unpin, Rc<dyn TextInputFormatter>: Unpin, Rc<dyn Fn(&mut App, AnyElement, Handle<EditableTextState>) -> Rc<dyn Widget>>: Unpin, Rc<dyn Fn(&mut App, String)>: Unpin, Rc<dyn Fn(&mut App, TextSelection, Option<SelectionChangedCause>)>: Unpin, Rc<dyn Key>: Unpin,

§

impl UnsafeUnpin for TextBox
where NonZeroU32Inner: UnsafeUnpin, &'static TextEditingControllerVTable: UnsafeUnpin, *const RcInner<Keep> is !null: UnsafeUnpin, PhantomData<RcInner<Keep>>: UnsafeUnpin, &'static FocusNodeVTable: UnsafeUnpin, *const RcInner<dyn Widget> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Widget>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, PhantomData<TextInputFormatterRef>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, AnyElement, Handle<EditableTextState>) -> Rc<dyn Widget>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, Handle<EditableTextState>) -> Rc<dyn Widget>>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, String)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, String)>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, TextSelection, Option<SelectionChangedCause>)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, TextSelection, Option<SelectionChangedCause>)>>: UnsafeUnpin, *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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<W> IntoWidget<StatefulKind> for W
where W: StatefulWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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

Source§

fn upcast(&self) -> Option<&T>