 481eec2c92
			
		
	
	
		481eec2c92
		
	
	
	
	
		
			
			# Objective Fixes #6078. The `UiColor` component is unhelpfully named: it is unclear, ambiguous with border color and ## Solution Rename the `UiColor` component (and associated fields) to `BackgroundColor` / `background_colorl`. ## Migration Guide `UiColor` has been renamed to `BackgroundColor`. This change affects `NodeBundle`, `ButtonBundle` and `ImageBundle`. In addition, the corresponding field on `ExtractedUiNode` has been renamed to `background_color` for consistency.
		
			
				
	
	
		
			69 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			69 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| //! Demonstrates how to use transparency with UI.
 | |
| //! Shows two colored buttons with transparent text.
 | |
| 
 | |
| use bevy::prelude::*;
 | |
| 
 | |
| fn main() {
 | |
|     App::new()
 | |
|         .insert_resource(ClearColor(Color::BLACK))
 | |
|         .add_plugins(DefaultPlugins)
 | |
|         .add_startup_system(setup)
 | |
|         .run();
 | |
| }
 | |
| 
 | |
| fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
 | |
|     commands.spawn(Camera2dBundle::default());
 | |
| 
 | |
|     let font_handle = asset_server.load("fonts/FiraSans-Bold.ttf");
 | |
| 
 | |
|     commands
 | |
|         .spawn(ButtonBundle {
 | |
|             style: Style {
 | |
|                 size: Size::new(Val::Px(150.0), Val::Px(65.0)),
 | |
|                 margin: UiRect::all(Val::Auto),
 | |
|                 justify_content: JustifyContent::Center,
 | |
|                 align_items: AlignItems::Center,
 | |
|                 ..default()
 | |
|             },
 | |
|             background_color: Color::rgb(0.1, 0.5, 0.1).into(),
 | |
|             ..default()
 | |
|         })
 | |
|         .with_children(|parent| {
 | |
|             parent.spawn(TextBundle::from_section(
 | |
|                 "Button 1",
 | |
|                 TextStyle {
 | |
|                     font: font_handle.clone(),
 | |
|                     font_size: 40.0,
 | |
|                     // Alpha channel of the color controls transparency.
 | |
|                     color: Color::rgba(1.0, 1.0, 1.0, 0.2),
 | |
|                 },
 | |
|             ));
 | |
|         });
 | |
| 
 | |
|     // Button with a different color,
 | |
|     // to demonstrate the text looks different due to its transparency.
 | |
|     commands
 | |
|         .spawn(ButtonBundle {
 | |
|             style: Style {
 | |
|                 size: Size::new(Val::Px(150.0), Val::Px(65.0)),
 | |
|                 margin: UiRect::all(Val::Auto),
 | |
|                 justify_content: JustifyContent::Center,
 | |
|                 align_items: AlignItems::Center,
 | |
|                 ..default()
 | |
|             },
 | |
|             background_color: Color::rgb(0.5, 0.1, 0.5).into(),
 | |
|             ..default()
 | |
|         })
 | |
|         .with_children(|parent| {
 | |
|             parent.spawn(TextBundle::from_section(
 | |
|                 "Button 2",
 | |
|                 TextStyle {
 | |
|                     font: font_handle.clone(),
 | |
|                     font_size: 40.0,
 | |
|                     // Alpha channel of the color controls transparency.
 | |
|                     color: Color::rgba(1.0, 1.0, 1.0, 0.2),
 | |
|                 },
 | |
|             ));
 | |
|         });
 | |
| }
 |