Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
11 changes: 11 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,17 @@ impl Default for EditableText {
}

impl EditableText {
/// Creates a new `EditableText` with its buffer already containing some initial text.
pub fn new(initial_text: impl AsRef<str>) -> Self {
let mut editor = PlainEditor::new(100.);
editor.set_text(initial_text.as_ref());

Self {
editor,
..Default::default()
}
}

/// 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