Enum bevy_ui_navigation::NavMenu
source · [−]#[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:
- Prevent navigation from one specific submenu to another
- Specify if 2d navigation wraps around the screen, see
NavMenu::Wrapping2d. - Specify “scope menus” such that a
NavRequest::ScopeMoveemitted when the focused element is aFocusablenested within thisNavMenuwill navigate this menu. SeeNavMenu::BoundScopeandNavMenu::WrappingScope. - Specify submenus and specify from where those submenus are reachable.
- Add a specific component to all
Focusables in this menu. You must first create a “seed” bundle with any of theNavMenumethods and then callmarkingon it. - Specify which entity will be the parents of this
NavMenu, seeNavMenu::reachable_fromorNavMenu::reachable_from_namedif you don’t have access to theEntityfor the parentFocusable
Example
See the example in this crate’s root level documentation page.
Invariants
You need to follow those rules (invariants) to avoid panics:
- A
Menumust have at least oneFocusablechild in the UI hierarchy. - 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.
- 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
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.
pub fn reachable_from_named(
self,
parent_label: impl Into<Cow<'static, str>>
) -> NamedMenuSeed
pub fn reachable_from_named(
self,
parent_label: impl Into<Cow<'static, str>>
) -> NamedMenuSeed
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for NavMenu
impl UnwindSafe for NavMenu
Blanket Implementations
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
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
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
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
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
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
pub fn clone_type_data(&self) -> Box<dyn TypeData + 'static, Global>
pub fn vzip(self) -> V
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