Skip to content

Commit ba3069f

Browse files
committed
Change default FocusPolicy to Pass (#7161)
# Objective - While building UI, it makes more sense for most nodes to have a `FocusPolicy` of `Pass`, so that user interaction can correctly bubble - Only `ButtonBundle` blocks by default This change means that for someone adding children to a button, it's not needed to change the focus policy of those children to `Pass` for the button to continue to work. --- ## Changelog - `FocusPolicy` default has changed from `FocusPolicy::Block` to `FocusPolicy::Pass` ## Migration Guide - `FocusPolicy` default has changed from `FocusPolicy::Block` to `FocusPolicy::Pass`
1 parent 76de9f9 commit ba3069f

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

crates/bevy_ui/src/focus.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub enum FocusPolicy {
6363
}
6464

6565
impl FocusPolicy {
66-
const DEFAULT: Self = Self::Block;
66+
const DEFAULT: Self = Self::Pass;
6767
}
6868

6969
impl Default for FocusPolicy {
@@ -164,9 +164,7 @@ pub fn ui_focus_system(
164164
// Reset their interaction to None to avoid strange stuck state
165165
if let Some(mut interaction) = node.interaction {
166166
// We cannot simply set the interaction to None, as that will trigger change detection repeatedly
167-
if *interaction != Interaction::None {
168-
*interaction = Interaction::None;
169-
}
167+
interaction.set_if_neq(Interaction::None);
170168
}
171169

172170
return None;

crates/bevy_ui/src/node_bundles.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub struct ImageBundle {
9696
}
9797

9898
/// A UI node that is text
99-
#[derive(Bundle, Clone, Debug)]
99+
#[derive(Bundle, Clone, Debug, Default)]
100100
pub struct TextBundle {
101101
/// Describes the size of the node
102102
pub node: Node,
@@ -160,25 +160,8 @@ impl TextBundle {
160160
}
161161
}
162162

163-
impl Default for TextBundle {
164-
fn default() -> Self {
165-
TextBundle {
166-
focus_policy: FocusPolicy::Pass,
167-
text: Default::default(),
168-
node: Default::default(),
169-
calculated_size: Default::default(),
170-
style: Default::default(),
171-
transform: Default::default(),
172-
global_transform: Default::default(),
173-
visibility: Default::default(),
174-
computed_visibility: Default::default(),
175-
z_index: Default::default(),
176-
}
177-
}
178-
}
179-
180163
/// A UI node that is a button
181-
#[derive(Bundle, Clone, Debug, Default)]
164+
#[derive(Bundle, Clone, Debug)]
182165
pub struct ButtonBundle {
183166
/// Describes the size of the node
184167
pub node: Node,
@@ -213,3 +196,22 @@ pub struct ButtonBundle {
213196
/// Indicates the depth at which the node should appear in the UI
214197
pub z_index: ZIndex,
215198
}
199+
200+
impl Default for ButtonBundle {
201+
fn default() -> Self {
202+
Self {
203+
focus_policy: FocusPolicy::Block,
204+
node: Default::default(),
205+
button: Default::default(),
206+
style: Default::default(),
207+
interaction: Default::default(),
208+
background_color: Default::default(),
209+
image: Default::default(),
210+
transform: Default::default(),
211+
global_transform: Default::default(),
212+
visibility: Default::default(),
213+
computed_visibility: Default::default(),
214+
z_index: Default::default(),
215+
}
216+
}
217+
}

0 commit comments

Comments
 (0)