Enum bevy_ui_navigation::NavMenu
source · [−]#[non_exhaustive]
pub enum NavMenu {
Bound2d,
Wrapping2d,
BoundScope,
WrappingScope,
}
Expand description
A menu that isolate children Focusable
s 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::ScopeMove
emitted when the focused element is aFocusable
nested within thisNavMenu
will navigate this menu. SeeNavMenu::BoundScope
andNavMenu::WrappingScope
. - Specify submenus and specify from where those submenus are reachable.
- Add a specific component to all
Focusable
s in this menu. You must first create a “seed” bundle with any of theNavMenu
methods and then callmarking
on it. - Specify which entity will be the parents of this
NavMenu
, seeNavMenu::reachable_from
orNavMenu::reachable_from_named
if you don’t have access to theEntity
for the parentFocusable
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:
- A
Menu
must have at least oneFocusable
child 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
sourceimpl NavMenu
impl NavMenu
sourcepub fn with_parent(self, focus_parent: Option<Entity>) -> MenuSeed
pub fn with_parent(self, focus_parent: Option<Entity>) -> MenuSeed
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>
.
sourcepub fn root(self) -> MenuSeed
pub fn root(self) -> MenuSeed
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.
sourcepub fn reachable_from(self, focusable: Entity) -> MenuSeed
pub fn reachable_from(self, focusable: Entity) -> MenuSeed
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.
sourcepub 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
impl Copy for NavMenu
impl StructuralPartialEq for NavMenu
Auto Trait Implementations
impl RefUnwindSafe for NavMenu
impl Send for NavMenu
impl Sync for NavMenu
impl Unpin for NavMenu
impl UnwindSafe for NavMenu
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
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
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
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
fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
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
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T> TypeData for T where
T: 'static + Send + Sync + Clone,
impl<T> TypeData for T where
T: 'static + Send + Sync + Clone,
fn clone_type_data(&self) -> Box<dyn TypeData + 'static, Global>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more