#bevy-ui #forms #text-input #input #bevy-plugin #ui #bevy

bevy_ui_forms_form_proc

为创建表单的bevy插件

3个不稳定版本

0.2.1 2024年5月15日
0.2.0 2024年5月15日
0.1.0 2024年4月24日

#38#text-input

每月25次 下载
用于 bevy_ui_forms

MPL-2.0 许可证

30KB
603

bevy_ui_forms

Xenira [email protected] :toc: :toc-placement!: :toclevels: 2 :sectnums: :icons: font :source-highlighter: highlight.js

////

嗨,crates.io用户o/

如果您能读到这段话,那么crater.io仍然不支持asciidoc,所以文档显示不正确。请查看GitHub页面上的readme: https://github.com/xenira/bevy_ui_forms

////

crates.io, link=https://crates.io/crates/bevy_ui_forms docs, link=https://docs.rs/bevy_ui_forms Following released Bevy versions, link=https://bevy.rust-lang.net.cn/learn/book/plugin-development/#main-branch-tracking

bevy_ui添加表单。

这最初是从bevy_simple_text_input的一个分支开始的,为bevy_ui添加了一个更具雄心的单行文本输入小部件。

注意:虽然原始的文本输入小部件运行良好,但表单逻辑仍在开发中,可能存在错误,并且可能会更改。这也适用于输入,因为行为已更改。

它现在除了文本输入小部件外,还包括一些表单逻辑。

还有一个宏可以从结构体创建表单。

animated screenshot of text input widget gaining focus and text typed and submitted

toc::[]

从原始版本扩展的功能

  • 字符掩码
  • 占位文本
  • 剪贴板支持
  • 焦点(一次一个活动文本输入,点击自动聚焦)
  • 表单逻辑
  • 表单'derive'宏
  • Tab键在文本输入之间切换
  • Enter键提交表单

用法

重要:主分支中的代码和示例仍在开发中,可能与crates.io上发布的版本不兼容。请确保切换到相应的标签。

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
            }
            _ => {}
        }
    }
}

兼容性

.与Bevy版本[选项="标题"] |==== | bevy_ui_forms | bevy | 0.1 - latest | 0.13 |====

贡献

请随时提交一个PR,但最好先打开一个issue来讨论您想要进行的更改。

请保持PR小而专注于单个功能或修复。

替代方案

如果您需要更多功能,请查看 bevy_simple_text_inputbevy_cosmic_editbevy_egui

许可协议

本项目受 Mozilla公共许可证(MPL)2.0 许可。

原始的 bevy_simple_text_inputMITApache 2.0 许可协议的许可。

依赖关系

~0.6–1MB
~24K SLoC