🏃♂️ Bevy Quickmenu
Every game needs menus. Be it for the settings, for a pause screen, or for the main menu when the user enters the game.
While Bevy UI allows building menus, it is a cumbersome process especially if nested menus are needed. Even worse, though, is the effort required if you want your menu to be accessible with a keyboard, a gamepad, or the mouse.
Bevy Quickmenu offers all that. It is a super lightweight way of building in-game menus that can be controlled by all input devices. It even offers a simple way of having hover
states. Everything can also be customized.
- Super simple menu plugin for bevy, building upon Bevy UI
- Keyboard, Mouse, Gamepad input is processed
- Support mouse hover states in simplified Stylesheet
- Many customizations possible (see examples/custom.rs)
Usage
Add to Cargo.toml
:
[]
= "0.1.1"
Demo
Quick Examples
examples/basic.rs
: Basic example to show how it worksexamples/settings.rs
: Full blown user settings including switching game states and showing the menu againexamples/custom.rs
: Showcase customization options
An explanation of the required components
State
A generic type that hosts the state of your menu (e.g. which items are selected, and so on). Whenever this state changes, the menu is automatically redrawn.
Action
(Conforms to ActionTrait
): This enum defines all the actions your user can take. Such as SoundOn
, SoundOff
etc. When a user performs an action (by selecting the corresponding menu entry), the handle
method is called on your ActionTrait
implementation. ActionTrait
has two generic types: Your State
as well as a Event
which you can define. This allows you to handle your action:
Screen
(Conforms to the ScreenTrait
). Each page or screen in your menu is defined by this enum. Note that menu screens are not nested!. Instead the ScreenTrait
has a resolve
function that allows you to return the corresponding menu definition for the given enum:
Menu
A menu is just a function that returns a list of MenuItem
to be displayed. Each menu needs to have a distinct id. The example shows how the root
and the sound
menu are defined.
MenuItem
In order to give you some flexibility, the menu item allows you to return five different types:
MenuItem::label
: A small text label that cannot be selectedMenuItem::headline
: A big text label that cannot be selectedMenuItem::action
: A action that is performed when the user selects itMenuItem::screen
: Dive into a screen when the user selects thisMenuItem::image
: A single image (including an optionalStyle
)
In addition, a menu-item can have one of a couple of pre-defined icons or a custom icon
.with_icon
screen.with_icon
screen
MenuItem
s can also be checked or unchecked:
.checked
action.checked
action
Displaying a Menu
Here's a the annoated setup function from the example:
Removing a Menu
In order to remove a menu, there's the bevy_quickmenu::cleanup
function. Usually, it is best
to use it with the event that Bevy Quickmenu allows you to register: