2 unstable releases
0.2.0 | Dec 11, 2024 |
---|---|
0.1.0 | Dec 8, 2024 |
#320 in Game dev
224 downloads per month
Used in 2 crates
(via bevy_minibuffer)
125KB
3K
SLoC
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 ofbevy_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
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.entity())
.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_asky | bevy |
---|---|
0.2.0 | 0.15 |
0.1.0 | 0.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.
Dependencies
~53–85MB
~1.5M SLoC