bevy_ui_forms_form_proc

A bevy plugin for creating forms.


Keywords
gamedev, input, ui, forms, bevy
License
MPL-2.0

Documentation

bevy_ui_forms

crates.io docs Following released Bevy versions

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)

1. Features extended from the original

  • 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

2. Usage

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.

2.1. Form macro

Macro example
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>,
}
Usage
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
            }
            _ => {}
        }
    }
}

3. Compatibility

Table 1. Compatibility with Bevy versions
bevy_ui_forms bevy

0.1

0.13

4. Contributing

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.

5. Alternatives

If you need more features, check out bevy_simple_text_input, bevy_cosmic_edit or bevy_egui.

6. License

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.