pub struct Focusable { /* private fields */ }
Expand description

An [Entity] that can be navigated to, using the cursor navigation system.

It is in one of multiple FocusState, you can check its state with the Focusable::state method.

A Focusable can execute a variety of FocusAction when receiving NavRequest::Action, the default one is FocusAction::Normal.

Note: You should avoid updating manually the state of Focusables. You should instead use NavRequest to manipulate and change focus.

Implementations

Default Focusable.

The FocusState of this Focusable.

The FocusAction of this Focusable.

A “cancel” focusable, see FocusAction::Cancel.

A “lock” focusable, see FocusAction::Lock.

A focusable that will get highlighted in priority when none are set yet.

WARNING: Only use this when creating the UI. Any of the following state is unspecified and will likely result in broken behavior:

  • Having multiple prioritized Focusables in the same menu.
  • Updating an already existing Focusable with this.
Example
fn setup(mut commands: Commands) {
    commands.spawn_bundle(FocusableButtonBundle {
        focus: Focusable::new().prioritized(),
        ..default()
    });
}

A FocusState::Blocked focusable.

This focusable will not be able to take focus until Focusable::unblock is called on it.

Example
fn setup(mut commands: Commands) {
    commands.spawn_bundle(FocusableButtonBundle {
        focus: Focusable::new().blocked(),
        ..default()
    });
}

Prevent this Focusable from gaining focus until it is unblocked.

Note: Due to the way focus is handled, this does nothing when the Focusable::state is FocusState::Active or FocusState::Focused.

Returns true if self has succesfully been blocked (its Focusable::state was either Inert or Prioritized).

Limitations
  • If all the children of a menu are blocked, when activating the menu’s parent, the block state of the last active focusable will be ignored.
  • When FocusOn to an focusable in a menu reachable from an blocked focusable, its block state will be ignored.

Allow this Focusable to gain focus again, setting it to FocusState::Inert.

Returns true if self’s state was FocusState::Blocked.

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

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Return the T [ShaderType] for self. When used in [AsBindGroup] derives, it is safe to assume that all images in self exist. 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.

Creates Self using data from the given [World]

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

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