Skip to content

Commit

Permalink
Decouple BackgroundColor from UiImage
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Jan 24, 2024
1 parent 143066d commit 918867c
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 120 deletions.
54 changes: 43 additions & 11 deletions crates/bevy_ui/src/node_bundles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Default for NodeBundle {
}

/// A UI node that is an image
#[derive(Bundle, Debug, Default)]
#[derive(Bundle, Debug)]
pub struct ImageBundle {
/// Describes the logical size of the node
pub node: Node,
Expand All @@ -84,8 +84,6 @@ pub struct ImageBundle {
/// The calculated size based on the given image
pub calculated_size: ContentSize,
/// The background color, which serves as a "fill" for this node
///
/// Combines with `UiImage` to tint the provided image.
pub background_color: BackgroundColor,
/// The image of the node
pub image: UiImage,
Expand Down Expand Up @@ -114,10 +112,30 @@ pub struct ImageBundle {
pub z_index: ZIndex,
}

impl Default for ImageBundle {
fn default() -> Self {
Self {
node: Default::default(),
style: Default::default(),
calculated_size: Default::default(),
background_color: BackgroundColor(Color::NONE),
image: Default::default(),
image_size: Default::default(),
focus_policy: Default::default(),
transform: Default::default(),
global_transform: Default::default(),
visibility: Default::default(),
inherited_visibility: Default::default(),
view_visibility: Default::default(),
z_index: Default::default(),
}
}
}

/// A UI node that is a texture atlas sprite
///
/// This bundle is identical to [`ImageBundle`] with an additional [`TextureAtlas`] component.
#[derive(Bundle, Debug, Default)]
#[derive(Bundle, Debug)]
pub struct AtlasImageBundle {
/// Describes the logical size of the node
pub node: Node,
Expand All @@ -127,8 +145,6 @@ pub struct AtlasImageBundle {
/// The calculated size based on the given image
pub calculated_size: ContentSize,
/// The background color, which serves as a "fill" for this node
///
/// Combines with `UiImage` to tint the provided image.
pub background_color: BackgroundColor,
/// The image of the node
pub image: UiImage,
Expand Down Expand Up @@ -159,6 +175,27 @@ pub struct AtlasImageBundle {
pub z_index: ZIndex,
}

impl Default for AtlasImageBundle {
fn default() -> Self {
Self {
node: Default::default(),
style: Default::default(),
calculated_size: Default::default(),
background_color: BackgroundColor(Color::NONE),
image: Default::default(),
texture_atlas: Default::default(),
focus_policy: Default::default(),
image_size: Default::default(),
transform: Default::default(),
global_transform: Default::default(),
visibility: Default::default(),
inherited_visibility: Default::default(),
view_visibility: Default::default(),
z_index: Default::default(),
}
}
}

#[cfg(feature = "bevy_text")]
/// A UI node that is text
///
Expand Down Expand Up @@ -298,13 +335,9 @@ pub struct ButtonBundle {
/// Whether this node should block interaction with lower nodes
pub focus_policy: FocusPolicy,
/// The background color, which serves as a "fill" for this node
///
/// When combined with `UiImage`, tints the provided image.
pub background_color: BackgroundColor,
/// The color of the Node's border
pub border_color: BorderColor,
/// The image of the node
pub image: UiImage,
/// The transform of the node
///
/// This component is automatically managed by the UI layout system.
Expand Down Expand Up @@ -334,7 +367,6 @@ impl Default for ButtonBundle {
border_color: BorderColor(Color::NONE),
interaction: Default::default(),
background_color: Default::default(),
image: Default::default(),
transform: Default::default(),
global_transform: Default::default(),
visibility: Default::default(),
Expand Down
Loading

0 comments on commit 918867c

Please sign in to comment.