Adds forms to bevy_ui
.
This started out as a fork of bevy_simple_text_input
with a slightly more ambitious single-line text input widget for bevy_ui
.
Note
|
While the original text input widget works well the form logic is still in developmen, might be buggy and is subject to change. This also applies to the input, as the behaviour is changed. |
It now includes some form logic in addition to the text input widget.
There also is a macro for creating forms from a struct.
![animated screenshot of text input widget gaining focus and text typed and submitted](crates/core/assets/screenshot.gif)
-
Character masking
-
Placeholder text
-
Clipboard support
-
Focus (one active text input at a time and auto-focus on click)
-
Form logic
-
Form 'derive' macro
-
Tab
key to switch between text inputs -
Enter
key to submit form
Important
|
Code and examples in the main branch are under development and may not be compatible with the released version on crates.io. Make sure to switch to the corresponding tag. |
See examples/basic.rs
.
use bevy::prelude::*;
use bevy_ui_forms::prelude::*;
#[form_struct]
#[derive(Debug, Clone)]
pub struct LoginData {
#[form_field(active)]
#[text_box(placeholder = "Username")]
pub username: String,
#[text_box(placeholder = "Password", mask = '*')]
pub password: String,
#[form_field(optional)]
#[text_box(placeholder = "Email")]
pub email: Option<String>,
}
fn setup(mut commands: Commands) {
commands.spawn((
LoginDataForm,
NodeBundle {
style: Style {
flex_direction: FlexDirection::Column,
row_gap: Val::Px(8.0),
align_self: AlignSelf::Stretch,
align_items: AlignItems::Stretch,
..default()
},
..default()
},
));
}
fn on_form_submit(
mut ev_login_form: EventReader<LoginDataFormEvent>,
) {
for ev in ev_login_form.read() {
match &ev.event {
FormEvent::Submit(data) => {
// do something with the data
}
_ => {}
}
}
}
Please feel free to open a PR, but its best to open an issue first to discuss the changes you would like to make.
Please keep PRs small and scoped to a single feature or fix.
If you need more features, check out bevy_simple_text_input
, bevy_cosmic_edit
or bevy_egui
.
This project is licensed under the Mozilla Public License (MPL) 2.0.
The original bevy_simple_text_input
is licensed under the MIT or Apache 2.0 license.