#[non_exhaustive]
pub enum NavMenu {
    Bound2d,
    Wrapping2d,
    BoundScope,
    WrappingScope,
}
Expand description

A menu that isolate children Focusables from other focusables and specify navigation method within itself.

Usage

A NavMenu can be used to:

If you want to specify which Focusable should be focused first when entering a menu, you should mark one of the children of this menu with Focusable::dormant.

Example

See the example in this crate’s root level documentation page.

Invariants

You need to follow those rules (invariants) to avoid panics:

  1. A Menu must have at least one Focusable child in the UI hierarchy.
  2. There must not be a menu loop. Ie: a way to go from menu A to menu B and then from menu B to menu A while never going back.
  3. Focusables in 2d menus must have a GlobalTransform.

Panics

Thankfully, programming errors are caught early and you’ll probably get a panic fairly quickly if you don’t follow the invariants.

  • Invariant (1) panics as soon as you add the menu without focusable children.
  • Invariant (2) panics if the focus goes into a menu loop.

Variants (Non-exhaustive)

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.

Bound2d

Non-wrapping menu with 2d navigation.

It is possible to move around this menu in all cardinal directions, the focus changes according to the physical position of the Focusable in it.

If the player moves to a direction where there aren’t any focusables, nothing will happen.

Wrapping2d

Wrapping menu with 2d navigation.

It is possible to move around this menu in all cardinal directions, the focus changes according to the physical position of the Focusable in it.

If the player moves to a direction where there aren’t any focusables, the focus will “wrap” to the other direction of the screen.

BoundScope

Non-wrapping scope menu

Controlled with NavRequest::ScopeMove even when the focused element is not in this menu, but in a submenu reachable from this one.

WrappingScope

Wrapping scope menu

Controlled with NavRequest::ScopeMove even when the focused element is not in this menu, but in a submenu reachable from this one.

Implementations

Spawn a NavMenu seed with provided parent entity (or root if None).

Prefer Self::reachable_from and Self::root to this if you don’t already have an Option<Entity>.

Spawn this menu with no parents.

No Focusable will “lead to” this menu. You either need to programmatically give focus to this menu tree with NavRequest::FocusOn or have only one root menu.

Spawn this menu as reachable from a given Focusable

When requesting NavRequest::Action when focusable is focused, the focus will be changed to a focusable within this menu.

Important

You must ensure this doesn’t create a cycle. Eg: you shouldn’t be able to reach NavMenu X from Focusable Y if there is a path from NavMenu X to Focusable Y.

Spawn this menu as reachable from a Focusable with a Name component.

This is useful if, for example, you just want to spawn your UI without keeping track of entity ids of buttons that leads to submenus.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more