Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Rename UiColor to BackgroundColor #6087

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 12 additions & 8 deletions crates/bevy_ui/src/entity.rs
Expand Up @@ -2,7 +2,7 @@

use crate::{
widget::{Button, ImageMode},
CalculatedSize, FocusPolicy, Interaction, Node, Style, UiColor, UiImage,
BackgroundColor, CalculatedSize, FocusPolicy, Interaction, Node, Style, UiImage,
};
use bevy_ecs::{
bundle::Bundle,
Expand All @@ -23,8 +23,8 @@ pub struct NodeBundle {
pub node: Node,
/// Describes the style including flexbox settings
pub style: Style,
/// Describes the color of the node
pub color: UiColor,
/// The background color, which serves as a "fill" for this node
pub background_color: BackgroundColor,
/// Describes the image of the node
pub image: UiImage,
/// Whether this node should block interaction with lower nodes
Expand All @@ -50,8 +50,10 @@ pub struct ImageBundle {
pub image_mode: ImageMode,
/// The calculated size based on the given image
pub calculated_size: CalculatedSize,
/// The color of the node
pub color: UiColor,
/// The background color, which serves as a "fill" for this node
///
/// When combined with `UiImage`, tints the provided image.
pub background_color: BackgroundColor,
/// The image of the node
pub image: UiImage,
/// Whether this node should block interaction with lower nodes
Expand Down Expand Up @@ -152,8 +154,10 @@ pub struct ButtonBundle {
pub interaction: Interaction,
/// Whether this node should block interaction with lower nodes
pub focus_policy: FocusPolicy,
/// The color of the node
pub color: UiColor,
/// The background color, which serves as a "fill" for this node
///
/// When combined with `UiImage`, tints the provided image.
pub background_color: BackgroundColor,
/// The image of the node
pub image: UiImage,
/// The transform of the node
Expand All @@ -174,7 +178,7 @@ impl Default for ButtonBundle {
focus_policy: Default::default(),
node: Default::default(),
style: Default::default(),
color: Default::default(),
background_color: Default::default(),
image: Default::default(),
transform: Default::default(),
global_transform: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ui/src/lib.rs
Expand Up @@ -90,7 +90,7 @@ impl Plugin for UiPlugin {
.register_type::<Size>()
.register_type::<UiRect>()
.register_type::<Style>()
.register_type::<UiColor>()
.register_type::<BackgroundColor>()
.register_type::<UiImage>()
.register_type::<Val>()
.register_type::<widget::Button>()
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_ui/src/render/mod.rs
Expand Up @@ -5,7 +5,7 @@ use bevy_core_pipeline::{core_2d::Camera2d, core_3d::Camera3d};
pub use pipeline::*;
pub use render_pass::*;

use crate::{prelude::UiCameraConfig, CalculatedClip, Node, UiColor, UiImage};
use crate::{prelude::UiCameraConfig, BackgroundColor, CalculatedClip, Node, UiImage};
use bevy_app::prelude::*;
use bevy_asset::{load_internal_asset, AssetEvent, Assets, Handle, HandleUntyped};
use bevy_ecs::prelude::*;
Expand Down Expand Up @@ -161,7 +161,7 @@ fn get_ui_graph(render_app: &mut App) -> RenderGraph {

pub struct ExtractedUiNode {
pub transform: Mat4,
pub color: Color,
pub background_color: Color,
pub rect: Rect,
pub image: Handle<Image>,
pub atlas_size: Option<Vec2>,
Expand All @@ -180,7 +180,7 @@ pub fn extract_uinodes(
Query<(
&Node,
&GlobalTransform,
&UiColor,
&BackgroundColor,
&UiImage,
&ComputedVisibility,
Option<&CalculatedClip>,
Expand All @@ -203,7 +203,7 @@ pub fn extract_uinodes(
}
extracted_uinodes.uinodes.push(ExtractedUiNode {
transform: transform.compute_matrix(),
color: color.0,
background_color: color.0,
rect: Rect {
min: Vec2::ZERO,
max: uinode.size,
Expand Down Expand Up @@ -328,7 +328,7 @@ pub fn extract_text_uinodes(

extracted_uinodes.uinodes.push(ExtractedUiNode {
transform: extracted_transform,
color,
background_color: color,
rect,
image: texture,
atlas_size,
Expand Down Expand Up @@ -490,7 +490,7 @@ pub fn prepare_uinodes(
ui_meta.vertices.push(UiVertex {
position: positions_clipped[i].into(),
uv: uvs[i].into(),
color: extracted_uinode.color.as_linear_rgba_f32(),
color: extracted_uinode.background_color.as_linear_rgba_f32(),
});
}

Expand Down
11 changes: 7 additions & 4 deletions crates/bevy_ui/src/ui_node.rs
Expand Up @@ -375,18 +375,21 @@ pub struct CalculatedSize {
pub size: Size,
}

/// The color of the node
/// The background color of the node
///
/// This serves as the "fill" color.
/// When combined with [`UiImage`], tints the provided texture.
#[derive(Component, Default, Copy, Clone, Debug, Reflect)]
#[reflect(Component, Default)]
pub struct UiColor(pub Color);
pub struct BackgroundColor(pub Color);

impl From<Color> for UiColor {
impl From<Color> for BackgroundColor {
fn from(color: Color) -> Self {
Self(color)
}
}

/// The image of the node
/// The 2D texture displayed for this UI node
#[derive(Component, Clone, Debug, Reflect, Deref, DerefMut)]
#[reflect(Component, Default)]
pub struct UiImage(pub Handle<Image>);
Expand Down
4 changes: 2 additions & 2 deletions examples/ecs/state.rs
Expand Up @@ -52,7 +52,7 @@ fn setup_menu(mut commands: Commands, asset_server: Res<AssetServer>) {
align_items: AlignItems::Center,
..default()
},
color: NORMAL_BUTTON.into(),
background_color: NORMAL_BUTTON.into(),
..default()
})
.with_children(|parent| {
Expand All @@ -72,7 +72,7 @@ fn setup_menu(mut commands: Commands, asset_server: Res<AssetServer>) {
fn menu(
mut state: ResMut<State<AppState>>,
mut interaction_query: Query<
(&Interaction, &mut UiColor),
(&Interaction, &mut BackgroundColor),
(Changed<Interaction>, With<Button>),
>,
) {
Expand Down
2 changes: 1 addition & 1 deletion examples/games/alien_cake_addict.rs
Expand Up @@ -379,7 +379,7 @@ fn display_score(mut commands: Commands, asset_server: Res<AssetServer>, game: R
align_items: AlignItems::Center,
..default()
},
color: Color::NONE.into(),
background_color: Color::NONE.into(),
..default()
})
.with_children(|parent| {
Expand Down
34 changes: 17 additions & 17 deletions examples/games/game_menu.rs
Expand Up @@ -161,7 +161,7 @@ mod game {
align_items: AlignItems::Center,
..default()
},
color: Color::BLACK.into(),
background_color: Color::BLACK.into(),
..default()
},
OnGameScreen,
Expand Down Expand Up @@ -349,7 +349,7 @@ mod menu {
// This system handles changing all buttons color based on mouse interaction
fn button_system(
mut interaction_query: Query<
(&Interaction, &mut UiColor, Option<&SelectedOption>),
(&Interaction, &mut BackgroundColor, Option<&SelectedOption>),
(Changed<Interaction>, With<Button>),
>,
) {
Expand All @@ -367,7 +367,7 @@ mod menu {
// the button as the one currently selected
fn setting_button<T: Resource + Component + PartialEq + Copy>(
interaction_query: Query<(&Interaction, &T, Entity), (Changed<Interaction>, With<Button>)>,
mut selected_query: Query<(Entity, &mut UiColor), With<SelectedOption>>,
mut selected_query: Query<(Entity, &mut BackgroundColor), With<SelectedOption>>,
mut commands: Commands,
mut setting: ResMut<T>,
) {
Expand Down Expand Up @@ -424,7 +424,7 @@ mod menu {
align_items: AlignItems::Center,
..default()
},
color: Color::CRIMSON.into(),
background_color: Color::CRIMSON.into(),
..default()
},
OnMainMenuScreen,
Expand Down Expand Up @@ -454,7 +454,7 @@ mod menu {
.spawn((
ButtonBundle {
style: button_style.clone(),
color: NORMAL_BUTTON.into(),
background_color: NORMAL_BUTTON.into(),
..default()
},
MenuButtonAction::Play,
Expand All @@ -475,7 +475,7 @@ mod menu {
.spawn((
ButtonBundle {
style: button_style.clone(),
color: NORMAL_BUTTON.into(),
background_color: NORMAL_BUTTON.into(),
..default()
},
MenuButtonAction::Settings,
Expand All @@ -496,7 +496,7 @@ mod menu {
.spawn((
ButtonBundle {
style: button_style,
color: NORMAL_BUTTON.into(),
background_color: NORMAL_BUTTON.into(),
..default()
},
MenuButtonAction::Quit,
Expand Down Expand Up @@ -537,7 +537,7 @@ mod menu {
align_items: AlignItems::Center,
..default()
},
color: Color::CRIMSON.into(),
background_color: Color::CRIMSON.into(),
..default()
},
OnSettingsMenuScreen,
Expand All @@ -552,7 +552,7 @@ mod menu {
.spawn((
ButtonBundle {
style: button_style.clone(),
color: NORMAL_BUTTON.into(),
background_color: NORMAL_BUTTON.into(),
..default()
},
action,
Expand Down Expand Up @@ -591,7 +591,7 @@ mod menu {
align_items: AlignItems::Center,
..default()
},
color: Color::CRIMSON.into(),
background_color: Color::CRIMSON.into(),
..default()
},
OnDisplaySettingsMenuScreen,
Expand All @@ -605,7 +605,7 @@ mod menu {
align_items: AlignItems::Center,
..default()
},
color: Color::CRIMSON.into(),
background_color: Color::CRIMSON.into(),
..default()
})
.with_children(|parent| {
Expand All @@ -625,7 +625,7 @@ mod menu {
size: Size::new(Val::Px(150.0), Val::Px(65.0)),
..button_style.clone()
},
color: NORMAL_BUTTON.into(),
background_color: NORMAL_BUTTON.into(),
..default()
});
entity.insert(quality_setting).with_children(|parent| {
Expand All @@ -644,7 +644,7 @@ mod menu {
.spawn((
ButtonBundle {
style: button_style,
color: NORMAL_BUTTON.into(),
background_color: NORMAL_BUTTON.into(),
..default()
},
MenuButtonAction::BackToSettings,
Expand Down Expand Up @@ -682,7 +682,7 @@ mod menu {
align_items: AlignItems::Center,
..default()
},
color: Color::CRIMSON.into(),
background_color: Color::CRIMSON.into(),
..default()
},
OnSoundSettingsMenuScreen,
Expand All @@ -694,7 +694,7 @@ mod menu {
align_items: AlignItems::Center,
..default()
},
color: Color::CRIMSON.into(),
background_color: Color::CRIMSON.into(),
..default()
})
.with_children(|parent| {
Expand All @@ -708,7 +708,7 @@ mod menu {
size: Size::new(Val::Px(30.0), Val::Px(65.0)),
..button_style.clone()
},
color: NORMAL_BUTTON.into(),
background_color: NORMAL_BUTTON.into(),
..default()
});
entity.insert(Volume(volume_setting));
Expand All @@ -721,7 +721,7 @@ mod menu {
.spawn((
ButtonBundle {
style: button_style,
color: NORMAL_BUTTON.into(),
background_color: NORMAL_BUTTON.into(),
..default()
},
MenuButtonAction::BackToSettings,
Expand Down
2 changes: 1 addition & 1 deletion examples/ios/src/lib.rs
Expand Up @@ -124,7 +124,7 @@ fn setup_scene(

fn button_handler(
mut interaction_query: Query<
(&Interaction, &mut UiColor),
(&Interaction, &mut BackgroundColor),
(Changed<Interaction>, With<Button>),
>,
) {
Expand Down
11 changes: 7 additions & 4 deletions examples/stress_tests/many_buttons.rs
Expand Up @@ -25,10 +25,13 @@ fn main() {
}

#[derive(Component)]
struct IdleColor(UiColor);
struct IdleColor(BackgroundColor);

fn button_system(
mut interaction_query: Query<(&Interaction, &mut UiColor, &IdleColor), Changed<Interaction>>,
mut interaction_query: Query<
(&Interaction, &mut BackgroundColor, &IdleColor),
Changed<Interaction>,
>,
) {
for (interaction, mut material, IdleColor(idle_color)) in interaction_query.iter_mut() {
if matches!(interaction, Interaction::Hovered) {
Expand Down Expand Up @@ -74,7 +77,7 @@ fn setup(mut commands: Commands, font: Res<UiFont>) {
fn spawn_button(
commands: &mut ChildBuilder,
font: Handle<Font>,
color: UiColor,
color: BackgroundColor,
total: f32,
i: usize,
j: usize,
Expand All @@ -95,7 +98,7 @@ fn spawn_button(
position_type: PositionType::Absolute,
..default()
},
color,
background_color: color,
..default()
},
IdleColor(color),
Expand Down
4 changes: 2 additions & 2 deletions examples/ui/button.rs
Expand Up @@ -19,7 +19,7 @@ const PRESSED_BUTTON: Color = Color::rgb(0.35, 0.75, 0.35);

fn button_system(
mut interaction_query: Query<
(&Interaction, &mut UiColor, &Children),
(&Interaction, &mut BackgroundColor, &Children),
(Changed<Interaction>, With<Button>),
>,
mut text_query: Query<&mut Text>,
Expand Down Expand Up @@ -58,7 +58,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
align_items: AlignItems::Center,
..default()
},
color: NORMAL_BUTTON.into(),
background_color: NORMAL_BUTTON.into(),
..default()
})
.with_children(|parent| {
Expand Down