Skip to content

First-class technique for splitting input streams or absorbing input events #3570

Open
@alice-i-cecile

Description

What problem does this solve or what need does it fill?

Typically, when users click on a UI element (including in game units), we don't want to also handle that click in the rest of the world.

The same pattern is observed when typing into a chat box, where the keyboard inputs are stolen.

Right now, the default behavior is to pass all events through.

What solution would you like?

A few solutions immediately come to mind:

  1. Centralize this input stream splitting technique into a single standard mega-system that can be customized using function pointers.
  2. Assign ownership of input stream events by storing some form of owner (entities? labels?) on the input events as an optional field.
  3. Assign ownership of input events using entity-specific events (Suggestion: Entity Events #2070, Per entity Events #2116).
  4. Add a split method to ResMut<Events<T>>, which returns two iterators of events based on whether the supplied predicate is true. This doesn't make the chaos any better, but does improve ergonomics.

What alternative(s) have you considered?

Consume events in one-off systems using ResMut<Events<Input<T>>>.
This was the approach taken in vladbat00/bevy_egui#50, specifically vladbat00/bevy_egui@53c1773#diff-420f4e08a25299e0e1fb09f4757e1d5d027a2278f37030c09ab9c06786cfa52eR283.

However this is not a particularly principle or discoverable approach, and risks serious chaos as input events are silently eaten according to decentralized rules based on system ordering.

Additional context

Initially discussed on Discord. Led to #3569. Related reddit post with proposed workarounds.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-InputPlayer input via keyboard, mouse, gamepad, and moreA-UIGraphical user interfaces, styles, layouts, and widgetsC-FeatureA new feature, making something new possibleS-Needs-Design-DocThis issue or PR is particularly complex, and needs an approved design doc before it can be merged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions