Skip to content

Commit 0628ac2

Browse files
TimJentzschjames7132
authored andcommitted
Make the default background color of NodeBundle transparent (bevyengine#6211)
# Objective Closes bevyengine#6202. The default background color for `NodeBundle` is currently white. However, it's very rare that you actually want a white background color. Instead, you often want a background color specific to the style of your game or a transparent background (e.g. for UI layout nodes). ## Solution `Default` is not derived for `NodeBundle` anymore, but explicitly specified. The default background color is now transparent (`Color::NONE.into()`) as this is the most common use-case, is familiar from the web and makes specifying a layout for your UI less tedious. --- ## Changelog - Changed the default `NodeBundle.background_color` to be transparent (`Color::NONE.into()`). ## Migration Guide If you want a `NodeBundle` with a white background color, you must explicitly specify it: Before: ```rust let node = NodeBundle { ..default() } ``` After: ```rust let node = NodeBundle { background_color: Color::WHITE.into(), ..default() } ```
1 parent 2764ec2 commit 0628ac2

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

crates/bevy_ui/src/entity.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ use bevy_ecs::{
1010
query::QueryItem,
1111
};
1212
use bevy_render::{
13-
camera::Camera, extract_component::ExtractComponent, prelude::ComputedVisibility,
13+
camera::Camera,
14+
extract_component::ExtractComponent,
15+
prelude::{Color, ComputedVisibility},
1416
view::Visibility,
1517
};
1618
use bevy_text::{Text, TextAlignment, TextSection, TextStyle};
1719
use bevy_transform::prelude::{GlobalTransform, Transform};
1820

1921
/// The basic UI node
20-
#[derive(Bundle, Clone, Debug, Default)]
22+
#[derive(Bundle, Clone, Debug)]
2123
pub struct NodeBundle {
2224
/// Describes the size of the node
2325
pub node: Node,
@@ -45,6 +47,23 @@ pub struct NodeBundle {
4547
pub computed_visibility: ComputedVisibility,
4648
}
4749

50+
impl Default for NodeBundle {
51+
fn default() -> Self {
52+
NodeBundle {
53+
// Transparent background
54+
background_color: Color::NONE.into(),
55+
node: Default::default(),
56+
style: Default::default(),
57+
image: Default::default(),
58+
focus_policy: Default::default(),
59+
transform: Default::default(),
60+
global_transform: Default::default(),
61+
visibility: Default::default(),
62+
computed_visibility: Default::default(),
63+
}
64+
}
65+
}
66+
4867
/// A UI node that is an image
4968
#[derive(Bundle, Clone, Debug, Default)]
5069
pub struct ImageBundle {

examples/games/alien_cake_addict.rs

-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ fn display_score(mut commands: Commands, asset_server: Res<AssetServer>, game: R
383383
align_items: AlignItems::Center,
384384
..default()
385385
},
386-
background_color: Color::NONE.into(),
387386
..default()
388387
})
389388
.with_children(|parent| {

examples/ui/ui.rs

-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
2828
justify_content: JustifyContent::SpaceBetween,
2929
..default()
3030
},
31-
background_color: Color::NONE.into(),
3231
..default()
3332
})
3433
.with_children(|parent| {
@@ -130,7 +129,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
130129
max_size: Size::UNDEFINED,
131130
..default()
132131
},
133-
background_color: Color::NONE.into(),
134132
..default()
135133
},
136134
ScrollingList::default(),
@@ -200,7 +198,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
200198
justify_content: JustifyContent::Center,
201199
..default()
202200
},
203-
background_color: Color::NONE.into(),
204201
..default()
205202
})
206203
.with_children(|parent| {
@@ -283,7 +280,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
283280
align_items: AlignItems::FlexEnd,
284281
..default()
285282
},
286-
background_color: Color::NONE.into(),
287283
..default()
288284
})
289285
.with_children(|parent| {

examples/window/scale_factor_override.rs

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
2828
justify_content: JustifyContent::SpaceBetween,
2929
..default()
3030
},
31-
background_color: Color::NONE.into(),
3231
..default()
3332
})
3433
.with_children(|parent| {

0 commit comments

Comments
 (0)