Skip to content

Double-click events #23874

@viridia

Description

@viridia

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

Multiple users have requested support for double-click events.

What solution would you like?

On desktop platforms, the double click interval is a user preference in the system settings. Unfortunately, this setting is not currently exposed through winit, although it might be possible using platform-specific APIs like windows-sys.

For the short term, we can just go with a fixed constant, perhaps hidden behind an API that would let us migrate to the OS setting in the future.

The other requirement of double-click processing is detecting pointer movement: rapidly clicking on two different places on the screen is not generally considered a double-click. There are a few ways this can be done:

  • remembering the coordinates of the previous click, and checking the distance between that and the current click
  • detecting whether the click is on the same pickable entity

From an API standpoint, the most straightforward approach would be to add a new field on the Click event. This can be a simple boolean, which if true means that the current click is sufficiently close (both spatially and temporally) to the previous click to be considered a double-click. Triple- and Quadruple-clicks can be handled by a state machine in application code, we don't need to build support for this into Bevy itself.

What alternative(s) have you considered?

An alternative is to have consumers of click events do the double-click detection themselves, although this would most likely lead to inconsistent behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-UIGraphical user interfaces, styles, layouts, and widgetsC-FeatureA new feature, making something new possibleD-StraightforwardSimple bug fixes and API improvements, docs, test and examplesS-Needs-TriageThis issue needs to be labelled

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions