Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/bevy_text/src/text_editable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ impl Default for EditableText {
}

impl EditableText {
/// Creates a new `EditableText` with its buffer already containing some initial text and
/// its cursor positioned at the end.
pub fn new(initial_text: impl AsRef<str>) -> Self {
let mut editable_text = Self::default();
editable_text.editor.set_text(initial_text.as_ref());
editable_text.queue_edit(TextEdit::TextEnd(false));
editable_text
}

/// Access the internal [`PlainEditor`].
pub fn editor(&self) -> &PlainEditor<TextBrush> {
&self.editor
Expand Down
2 changes: 1 addition & 1 deletion examples/ui/text/multiple_text_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
padding: px(4.).all(),
..default()
},
EditableText::default(),
EditableText::new(&format!("Initial text {row}")),
TextCursorStyle::default(),
font.clone(),
BackgroundColor(bevy::color::palettes::css::DARK_GREY.into()),
Expand Down
Loading