Crate bevy_asky

Source
Expand description

§bevy_asky

This library is intended to make asking questions of the user easier within an application built with Bevy. It is not intended to provide a comprehensive UI beyond question-and-answer, and may indeed be better thought of as scaffolding for whatever one’s eventual UI may become.

[!WARNING] bevy_asky is currently in the early stages of development and is subject to breaking changes. The principle consumer of this crate is bevy_minibuffer, a gamedev console. As such it is under-developed for usage independent of bevy_minibuffer currently.

§Architecture

This crate uses a Model-View-Controller (MVC) architecture. Normally I am not too enthusiastic about MVC because there is a lot of ambiguity about what goes where especially when it comes to the controller aspect. However, I found that within Bevy’s Entity-Component-Systems (ECS) architecture, MVC enjoys much clearer boundaries.

§Model

The models are all found in the bevy_asky::prompt module. They represent the data that is being manipulated.

  • checkbox
  • confirm
  • number
  • password
  • radio button
  • text field
  • toggle

§Controller

The controllers are all implemented as systems and are not exposed to the user. If you prompt for a text field, and then hit ‘a’, the text field will append an ‘a’ character. It will not be shown though unless it has a view component.

§View

The view handles presentation. One chooses which view by using a marker component. There are two view modules in this crate: ‘ascii’ and ‘color’. Their marker components are ascii::View and color::View respectively.

One can use a view of their own. The configurability of these particular views are limited. It is suggested to copy-and-paste ascii.rs or color.rs for fine-grained control of the presentation.

§Usage

Run of code below

commands
    .construct::<Confirm>("Do you like cats?")
    .construct::<ascii::View>(())
    .observe(
        move |trigger: Trigger<Submit<bool>>, mut commands: Commands| {
            if let Submit(Ok(yes)) = trigger.event() {
                commands.entity(trigger.target())
                        .construct::<Feedback>(Feedback::info(if *yes {
                            "\nMe too!"
                        } else {
                            "\nOk."
                        }));
            }
        },
    );

§TODO

  • Design a setting for what to do when input is submitted, possible options:
    • do nothing,
    • block focus (take no more input),
    • or despawn.
  • Make keys re-bindable.
  • Add a button::View that uses mouse-clickable elements.

There is old button code that used to do this, but it has rotted and no longer compiles.

§Compatibility

bevy_askybevy
0.3.00.16
0.2.00.15
0.1.00.14

§Acknowledgments

Thanks to Axel Vasquez for his excellent and inspiring asky crate.

[!NOTE] I originally tried to extend Vasquez’s work from its terminal origin to work directly with Bevy. You can find that work in my fork, but it required a lot of compromises and pull requests needed on dependencies were not being accepted. So I decided to do a native-port of asky to bevy; this crate is the result.

§License

This crate is licensed under the MIT License or the Apache License 2.0.

Modules§

construct
Playing around with Cart’s proposal
focus
Handles focus between UI elements
prelude
Splat import, e.g., use bevy_asky::prelude::*
prompt
Checkbox, Confirm, Number, Password, Radio, TextField, Toggle
string_cursor
Keep track of string insertion point
sync
Uses triggers to communicate results
view
ascii, color, or button views

Structs§

AskyPlugin
Asky plugin
AskyPlugins
Asky plugins

Enums§

AskySet
In the Update schedule, AskySet runs the controllers then the views.
Dest
The destination for constructing new entities
Error
Asky errors
Submit
Prompts trigger an Submit

Traits§

Part
A part of a group
Submitter
This trait represents a commitment to fire a Trigger<Result<Self::Out, Error>>.