mirror of
https://github.com/bevyengine/bevy
synced 2024-11-23 05:03:47 +00:00
08bf1a6c2e
# Objective - Simplify API and make authoring styles easier See: https://github.com/bevyengine/bevy/issues/8540#issuecomment-1536177102 ## Solution - The `size`, `min_size`, `max_size`, and `gap` properties have been replaced by `width`, `height`, `min_width`, `min_height`, `max_width`, `max_height`, `row_gap`, and `column_gap` properties --- ## Changelog - Flattened `Style` properties that have a `Size` value directly into `Style` ## Migration Guide - The `size`, `min_size`, `max_size`, and `gap` properties have been replaced by the `width`, `height`, `min_width`, `min_height`, `max_width`, `max_height`, `row_gap`, and `column_gap` properties. Use the new properties instead. --------- Co-authored-by: ickshonpe <david.curthoys@googlemail.com>
80 lines
2.9 KiB
Rust
80 lines
2.9 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_systems(Startup, 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(NodeBundle {
|
|
style: Style {
|
|
width: Val::Percent(100.0),
|
|
align_items: AlignItems::Center,
|
|
justify_content: JustifyContent::SpaceAround,
|
|
..default()
|
|
},
|
|
..default()
|
|
})
|
|
.with_children(|parent| {
|
|
parent
|
|
.spawn(ButtonBundle {
|
|
style: Style {
|
|
width: Val::Px(150.0),
|
|
height: Val::Px(65.0),
|
|
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.
|
|
parent
|
|
.spawn(ButtonBundle {
|
|
style: Style {
|
|
width: Val::Px(150.0),
|
|
height: Val::Px(65.0),
|
|
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),
|
|
},
|
|
));
|
|
});
|
|
});
|
|
}
|