Crates.io | bevy_text_edit |
lib.rs | bevy_text_edit |
version | 0.3.1 |
source | src |
created_at | 2024-06-11 06:30:58.709026 |
updated_at | 2024-10-07 03:26:55.043839 |
description | Bevy plugin for input text |
homepage | |
repository | https://gitlab.com/kimtinh/bevy-text-edit |
max_upload_size | |
id | 1267825 |
size | 129,908 |
Add plugin TextEditPlugin
to the app and define which states it will run in:
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, States)]
enum GameState {
#[default]
Menu,
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
// Add the plugin
.add_plugins(TextEditPlugin::new(vec![GameState::Menu]))
.run;
}
If you don't care to game state and want to always run input text, use TextEditPluginNoState
:
fn main() {
App::new()
.add_plugins(DefaultPlugins)
// Add the plugin
.add_plugins(TextEditPluginNoState)
.add_systems(Startup, setup)
.run();
}
Insert component TextEditable
and Interaction
into any text entity that needs to be editable:
commands.spawn((
TextEditable::default(), // Mark text is editable
Interaction::None, // Mark entity is interactable
TextBundle::from_section(
"Input Text 1",
TextStyle::default(),
),
));
Only text that is focused by clicking gets keyboard input.
It is also possible to limit which characters are allowed to enter through filter_in
and filter_out
attribute. Regex is supported:
commands.spawn((
TextEditable {
filter_in: vec!["[0-9]".into(), " ".into()], // Only allow number and space
filter_out: vec!["5".into()], // Ignore number 5
},
Interaction::None,
TextBundle::from_section(
"Input Text 1",
TextStyle::default(),
),
));
Please see LICENSE.
bevy | bevy_text_edit |
---|---|
0.14 | 0.1-0.3, branch master |
0.13 | 0.0.1-0.0.5 |