pub struct EditableText {
pub editor: PlainEditor<TextBrush>,
pub pending_edits: Vec<TextEdit>,
pub pending_paste: Option<ClipboardRead>,
pub cursor_width: f32,
pub cursor_blink_period: Duration,
pub max_characters: Option<usize>,
pub visible_lines: Option<f32>,
pub visible_width: Option<f32>,
pub allow_newlines: bool,
}Expand description
A plain-text text input field.
Please see this module docs for more details on usage and functionality.
Note that text editing operations are trickier than they might first appear, due to the complexities of Unicode text handling.
As a result, we store an internal PlainEditor instance,
which manages both the text content and the cursor position,
and provides methods for applying text edits and cursor movements correctly
according to Unicode rules.
Fields§
§editor: PlainEditor<TextBrush>A parley::PlainEditor, tracking both the text content and cursor position.
This serves as an analogue to ComputedTextBlock for editable text.
In most cases, you should queue text edits via the EditableText::queue_edit method instead of directly manipulating the editor,
and then allow the apply_text_edits system to apply the edits at the appropriate time in the update cycle.
Note that many more complex editing operations require working with PlainEditor::driver.
These operations should generally be batched together to avoid redundant layout work.
pending_edits: Vec<TextEdit>Text edit actions that have been requested but not yet applied.
These edits are processed in first-in, first-out order.
pending_paste: Option<ClipboardRead>A paste operation that is awaiting clipboard I/O.
On platforms where system clipboard reads are asynchronous (currently wasm32), a
TextEdit::Paste may not resolve in the same frame it was queued.
While this field is Some, apply_pending_edits waits for this to resolve,
rather than draining further edits, so that everything after the paste stays correctly ordered behind it.
cursor_width: f32Cursor width, relative to font size
cursor_blink_period: DurationCursor blink period in seconds.
max_characters: Option<usize>Maximum number of characters the text input can contain.
Edits which would cause the length to exceed the maximum are ignored.
Does not stop setting a string longer than the maximum using set_text.
visible_lines: Option<f32>Sets the input’s height in number of visible lines.
visible_width: Option<f32>Sets the input’s width in number of visible glyphs. For proportional fonts the final size is the given value times the “0” advance width.
allow_newlines: boolAllow new lines
Implementations§
Source§impl EditableText
impl EditableText
Sourcepub fn new(initial_text: impl AsRef<str>) -> Self
pub fn new(initial_text: impl AsRef<str>) -> Self
Creates a new EditableText with its buffer already containing some initial text and
its cursor positioned at the end.
Sourcepub fn editor(&self) -> &PlainEditor<TextBrush>
pub fn editor(&self) -> &PlainEditor<TextBrush>
Access the internal PlainEditor.
Sourcepub fn editor_mut(&mut self) -> &mut PlainEditor<TextBrush>
pub fn editor_mut(&mut self) -> &mut PlainEditor<TextBrush>
Mutably access the internal PlainEditor.
Sourcepub fn value(&self) -> SplitString<'_>
pub fn value(&self) -> SplitString<'_>
Get the current text input as a SplitString.
A SplitString can be converted into a String using to_string if needed.
Sourcepub fn queue_edit(&mut self, edit: TextEdit)
pub fn queue_edit(&mut self, edit: TextEdit)
Queue a TextEdit action to be applied later by the apply_text_edits system.
Sourcepub fn apply_pending_edits(
&mut self,
font_context: &mut FontContext,
layout_context: &mut LayoutContext<TextBrush>,
clipboard: &mut Clipboard,
char_filter: impl Fn(char) -> bool,
)
pub fn apply_pending_edits( &mut self, font_context: &mut FontContext, layout_context: &mut LayoutContext<TextBrush>, clipboard: &mut Clipboard, char_filter: impl Fn(char) -> bool, )
Applies all TextEdits in pending_edits immediately, updating the PlainEditor text / cursor state accordingly.
FontContext should be gathered from the FontCx resource, and LayoutContext should be gathered from the LayoutCx resource.
On platforms with async clipboard reads (wasm32), a TextEdit::Paste whose
contents aren’t yet available acts as a barrier: this call parks the in-flight
read on EditableText and leaves the remaining edits queued in order. Each
subsequent frame re-polls the read, and processing resumes once it resolves.
On native targets clipboard reads are synchronous, so this barrier collapses.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the input’s text buffer and any pending edits.
Also drops any in-flight paste. The underlying clipboard read task will still complete, but its result is discarded.
Sourcepub fn is_composing(&self) -> bool
pub fn is_composing(&self) -> bool
Is the IME currently composing text for this input?
Some behavior (e.g. “submit on Enter”) may want to be suppressed while the IME is active to avoid interrupting the user’s composition.
Trait Implementations§
Source§impl Clone for EditableText
impl Clone for EditableText
Source§fn clone(&self) -> EditableText
fn clone(&self) -> EditableText
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Component for EditableText
Required Components: TextLayout, TextFont, TextColor, LineHeight, FontHinting, EditableTextGeneration.
impl Component for EditableText
Required Components: TextLayout, TextFont, TextColor, LineHeight, FontHinting, EditableTextGeneration.
A component’s Required Components are inserted whenever it is inserted. Note that this will also insert the required components of the required components, recursively, in depth-first order.
Source§const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table
const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table
Source§type Mutability = Mutable
type Mutability = Mutable
Component<Mutability = Mutable>,
while immutable components will instead have Component<Mutability = Immutable>. Read moreSource§fn register_required_components(
_requiree: ComponentId,
required_components: &mut RequiredComponentsRegistrator<'_, '_>,
)
fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )
Source§fn clone_behavior() -> ComponentCloneBehavior
fn clone_behavior() -> ComponentCloneBehavior
Source§fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>
fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>
ComponentRelationshipAccessor required for working with relationships in dynamic contexts. Read moreSource§fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
EntityMapper. This is used to remap entities in contexts like scenes and entity cloning.
When deriving Component, this is populated by annotating fields containing entities with #[entities] Read moreAuto Trait Implementations§
impl !RefUnwindSafe for EditableText
impl !UnwindSafe for EditableText
impl Freeze for EditableText
impl Send for EditableText
impl Sync for EditableText
impl Unpin for EditableText
impl UnsafeUnpin for EditableText
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<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut ComponentsRegistrator<'_>, ) -> impl Iterator<Item = ComponentId> + use<C>
Source§fn get_component_ids(
components: &Components,
) -> impl Iterator<Item = Option<ComponentId>>
fn get_component_ids( components: &Components, ) -> impl Iterator<Item = Option<ComponentId>>
Source§impl<C> BundleFromComponents for Cwhere
C: Component,
impl<C> BundleFromComponents for Cwhere
C: Component,
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ConditionalSend for Twhere
T: Send,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
Source§unsafe fn get_components(
ptr: MovingPtr<'_, C>,
func: &mut impl FnMut(StorageType, OwningPtr<'_>),
) -> <C as DynamicBundle>::Effect
unsafe fn get_components( ptr: MovingPtr<'_, C>, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect
Source§unsafe fn apply_effect(
_ptr: MovingPtr<'_, MaybeUninit<C>>,
_entity: &mut EntityWorldMut<'_>,
)
unsafe fn apply_effect( _ptr: MovingPtr<'_, MaybeUninit<C>>, _entity: &mut EntityWorldMut<'_>, )
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FromTemplate for T
impl<T> FromTemplate for T
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
Source§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Settings for T
Source§impl<T> Template for T
impl<T> Template for T
Source§fn build_template(
&self,
_context: &mut TemplateContext<'_, '_>,
) -> Result<<T as Template>::Output, BevyError>
fn build_template( &self, _context: &mut TemplateContext<'_, '_>, ) -> Result<<T as Template>::Output, BevyError>
entity context to produce a Template::Output.Source§fn clone_template(&self) -> T
fn clone_template(&self) -> T
Clone.