bevyengine / bevyengine/bevy

Inconsistent handling of focus in bevy_ui_widgets

Open
#25,072 0 comments 0 reactions 0 assignees View on GitHub
A-UI C-Code-Quality C-Feature D-Straightforward S-Ready-For-Implementation X-Uncontroversial
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

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

Some of the widgets in `bevy_ui_widgets` (like checkbox) set focus to themselves when clicked; others (like button) do not.

Doing this is redundant, since we already have a global observer that does this for all focusable entities.

## What solution would you like?

The code to set focus should be removed, since it's redundant and confusing. More generally, widgets should not manipulate focus at all if we can help it, widgets should only be _consumers_ of focus. Instead, the setting and clearing of focus should be handled globally and consistently.

## Additional context

Note that this is orthogonal to the debate about how focus interacts with disabled widgets; the global click-to-focus handler is able to make this decision without help from the widgets.

However, this relies on the click-to-focus handler being installed (which I think it will be, based on the current feature flag / default plugin installations).

@alice-i-cecile @gagnus

Contributor guide

Open the contributing guide

Research direction

Start by searching the bevy_ui_widgets implementation for checkbox and button code that sets focus, then inspect the global click-to-focus observer and its installation. Remove widget-level focus manipulation while preserving the observer as the central focus handler, and verify that the affected widgets still receive focus consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
frontend, game-dev
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.