#text-input #bevy-ui #forms #input #bevy #ui #user-input

bevy_ui_forms

用于创建表单的bevy插件

3个不稳定版本

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

#1137 in 游戏开发

MPL-2.0 许可证

275KB
1K SLoC

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版本的兼容性 [options="header"] |==== | bevy_ui_forms | bevy | 0.1 - latest | 0.13 |====

贡献

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

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

替代方案

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

许可证

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

原始的 bevy_simple_text_input 采用 MITApache 2.0 许可。

依赖

~36–78MB
~1.5M SLoC