Skip to content

Commit d3e76a8

Browse files
alice-i-cecileecoskey
authored andcommitted
Rename "focus" in bevy_picking to "hover" (bevyengine#16872)
# Objective With the introduction of bevy_input_focus, the uses of "focus" in bevy_picking are quite confusing and make searching hard. Users will intuitively think these concepts are related, but they actually aren't. ## Solution Rename / rephrase all uses of "focus" in bevy_picking to refer to "hover", since this is ultimately related to creating the `HoverMap`. ## Migration Guide Various terms related to "focus" in `bevy_picking` have been renamed to refer to "hover" to avoid confusion with `bevy_input_focus`. In particular: - The `update_focus` system has been renamed to `generate_hovermap` - `PickSet::Focus` and `PostFocus` have been renamed to `Hover` and `PostHover` - The `bevy_picking::focus` module has been renamed to `bevy_picking::hover` - The `is_focus_enabled` field on `PickingPlugin` has been renamed to `is_hover_enabled` - The `focus_should_run` run condition has been renamed to `hover_should_run`
1 parent 8864790 commit d3e76a8

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

crates/bevy_picking/src/events.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
//!
2424
//! The order in which interaction events are received is extremely important, and you can read more
2525
//! about it on the docs for the dispatcher system: [`pointer_events`]. This system runs in
26-
//! [`PreUpdate`](bevy_app::PreUpdate) in [`PickSet::Focus`](crate::PickSet::Focus). All pointer-event
26+
//! [`PreUpdate`](bevy_app::PreUpdate) in [`PickSet::Hover`](crate::PickSet::Hover). All pointer-event
2727
//! observers resolve during the sync point between [`pointer_events`] and
28-
//! [`update_interactions`](crate::focus::update_interactions).
28+
//! [`update_interactions`](crate::hover::update_interactions).
2929
//!
3030
//! # Events Types
3131
//!
@@ -49,7 +49,7 @@ use bevy_window::Window;
4949

5050
use crate::{
5151
backend::{prelude::PointerLocation, HitData},
52-
focus::{HoverMap, PreviousHoverMap},
52+
hover::{HoverMap, PreviousHoverMap},
5353
pointer::{
5454
Location, PointerAction, PointerButton, PointerId, PointerInput, PointerMap, PressDirection,
5555
},
@@ -385,7 +385,7 @@ pub struct PickingEventWriters<'w> {
385385
/// receive [`Out`] and then entity B will receive [`Over`]. No entity will ever
386386
/// receive both an [`Over`] and and a [`Out`] event during the same frame.
387387
///
388-
/// When we account for event bubbling, this is no longer true. When focus shifts
388+
/// When we account for event bubbling, this is no longer true. When the hovering focus shifts
389389
/// between children, parent entities may receive redundant [`Out`] → [`Over`] pairs.
390390
/// In the context of UI, this is especially problematic. Additional hierarchy-aware
391391
/// events will be added in a future release.

crates/bevy_picking/src/focus.rs renamed to crates/bevy_picking/src/hover.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub struct PreviousHoverMap(pub HashMap<PointerId, HashMap<Entity, HitData>>);
6262

6363
/// Coalesces all data from inputs and backends to generate a map of the currently hovered entities.
6464
/// This is the final focusing step to determine which entity the pointer is hovering over.
65-
pub fn update_focus(
65+
pub fn generate_hovermap(
6666
// Inputs
6767
picking_behavior: Query<&PickingBehavior>,
6868
pointers: Query<&PointerId>,

crates/bevy_picking/src/lib.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,12 @@
128128
//! Bevy provides some backends out of the box, but you can even write your own. It's been
129129
//! made as easy as possible intentionally; the `bevy_mod_raycast` backend is 50 lines of code.
130130
//!
131-
//! #### Focus ([`focus`])
131+
//! #### Hover ([`hover`])
132132
//!
133133
//! The next step is to use the data from the backends, combine and sort the results, and determine
134-
//! what each cursor is hovering over, producing a [`HoverMap`](`crate::focus::HoverMap`). Note that
134+
//! what each cursor is hovering over, producing a [`HoverMap`](`crate::hover::HoverMap`). Note that
135135
//! just because a pointer is over an entity, it is not necessarily *hovering* that entity. Although
136-
//! multiple backends may be reporting that a pointer is hitting an entity, the focus system needs
136+
//! multiple backends may be reporting that a pointer is hitting an entity, the hover system needs
137137
//! to determine which entities are actually being hovered by this pointer based on the pick depth,
138138
//! order of the backend, and the optional [`PickingBehavior`] component of the entity. In other words,
139139
//! if one entity is in front of another, usually only the topmost one will be hovered.
@@ -154,7 +154,7 @@ extern crate alloc;
154154

155155
pub mod backend;
156156
pub mod events;
157-
pub mod focus;
157+
pub mod hover;
158158
pub mod input;
159159
#[cfg(feature = "bevy_mesh_picking_backend")]
160160
pub mod mesh_picking;
@@ -201,9 +201,9 @@ pub struct PickingBehavior {
201201
///
202202
/// For example, if a pointer is over a UI element, as well as a 3d mesh, backends will report
203203
/// hits for both of these entities. Additionally, the hits will be sorted by the camera order,
204-
/// so if the UI is drawing on top of the 3d mesh, the UI will be "above" the mesh. When focus
204+
/// so if the UI is drawing on top of the 3d mesh, the UI will be "above" the mesh. When hovering
205205
/// is computed, the UI element will be checked first to see if it this field is set to block
206-
/// lower entities. If it does (default), the focus system will stop there, and only the UI
206+
/// lower entities. If it does (default), the hovering system will stop there, and only the UI
207207
/// element will be marked as hovered. However, if this field is set to `false`, both the UI
208208
/// element *and* the mesh will be marked as hovered.
209209
///
@@ -257,12 +257,12 @@ pub enum PickSet {
257257
ProcessInput,
258258
/// Reads inputs and produces [`backend::PointerHits`]s. In the [`PreUpdate`] schedule.
259259
Backend,
260-
/// Reads [`backend::PointerHits`]s, and updates focus, selection, and highlighting states. In
260+
/// Reads [`backend::PointerHits`]s, and updates the hovermap, selection, and highlighting states. In
261261
/// the [`PreUpdate`] schedule.
262-
Focus,
263-
/// Runs after all the focus systems are done, before event listeners are triggered. In the
262+
Hover,
263+
/// Runs after all the [`PickSet::Hover`] systems are done, before event listeners are triggered. In the
264264
/// [`PreUpdate`] schedule.
265-
PostFocus,
265+
PostHover,
266266
/// Runs after all other picking sets. In the [`PreUpdate`] schedule.
267267
Last,
268268
}
@@ -298,7 +298,7 @@ pub struct PickingPlugin {
298298
/// Enables and disables input collection.
299299
pub is_input_enabled: bool,
300300
/// Enables and disables updating interaction states of entities.
301-
pub is_focus_enabled: bool,
301+
pub is_hover_enabled: bool,
302302
/// Enables or disables picking for window entities.
303303
pub is_window_picking_enabled: bool,
304304
}
@@ -309,10 +309,10 @@ impl PickingPlugin {
309309
state.is_input_enabled && state.is_enabled
310310
}
311311

312-
/// Whether or not systems updating entities' [`PickingInteraction`](focus::PickingInteraction)
312+
/// Whether or not systems updating entities' [`PickingInteraction`](hover::PickingInteraction)
313313
/// component should be running.
314-
pub fn focus_should_run(state: Res<Self>) -> bool {
315-
state.is_focus_enabled && state.is_enabled
314+
pub fn hover_should_run(state: Res<Self>) -> bool {
315+
state.is_hover_enabled && state.is_enabled
316316
}
317317

318318
/// Whether or not window entities should receive pick events.
@@ -326,7 +326,7 @@ impl Default for PickingPlugin {
326326
Self {
327327
is_enabled: true,
328328
is_input_enabled: true,
329-
is_focus_enabled: true,
329+
is_hover_enabled: true,
330330
is_window_picking_enabled: true,
331331
}
332332
}
@@ -370,8 +370,8 @@ impl Plugin for PickingPlugin {
370370
(
371371
PickSet::ProcessInput.run_if(Self::input_should_run),
372372
PickSet::Backend,
373-
PickSet::Focus.run_if(Self::focus_should_run),
374-
PickSet::PostFocus,
373+
PickSet::Hover.run_if(Self::hover_should_run),
374+
PickSet::PostHover,
375375
PickSet::Last,
376376
)
377377
.chain(),
@@ -393,10 +393,10 @@ pub struct InteractionPlugin;
393393
impl Plugin for InteractionPlugin {
394394
fn build(&self, app: &mut App) {
395395
use events::*;
396-
use focus::{update_focus, update_interactions};
396+
use hover::{generate_hovermap, update_interactions};
397397

398-
app.init_resource::<focus::HoverMap>()
399-
.init_resource::<focus::PreviousHoverMap>()
398+
app.init_resource::<hover::HoverMap>()
399+
.init_resource::<hover::PreviousHoverMap>()
400400
.init_resource::<PointerState>()
401401
.add_event::<Pointer<Cancel>>()
402402
.add_event::<Pointer<Click>>()
@@ -414,9 +414,9 @@ impl Plugin for InteractionPlugin {
414414
.add_event::<Pointer<Released>>()
415415
.add_systems(
416416
PreUpdate,
417-
(update_focus, update_interactions, pointer_events)
417+
(generate_hovermap, update_interactions, pointer_events)
418418
.chain()
419-
.in_set(PickSet::Focus),
419+
.in_set(PickSet::Hover),
420420
);
421421
}
422422
}

examples/testbed/ui.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use bevy::{
77
a11y::AccessibilityNode,
88
color::palettes::{basic::LIME, css::DARK_GRAY},
99
input::mouse::{MouseScrollUnit, MouseWheel},
10-
picking::focus::HoverMap,
10+
picking::hover::HoverMap,
1111
prelude::*,
1212
ui::widget::NodeImageMode,
1313
};

examples/ui/scroll.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use accesskit::{Node as Accessible, Role};
44
use bevy::{
55
a11y::AccessibilityNode,
66
input::mouse::{MouseScrollUnit, MouseWheel},
7-
picking::focus::HoverMap,
7+
picking::hover::HoverMap,
88
prelude::*,
99
winit::WinitSettings,
1010
};

0 commit comments

Comments
 (0)