mirror of
https://github.com/bevyengine/bevy
synced 2025-02-17 14:38:34 +00:00
Expanded ui
example (#16151)
# Objective Expand the `ui` example to show off more of the features and make it more useful for debugging. # Solution Added some extra elements to the `ui` example demonstrating outlines, border-radius, rotation, image sizing and image flipping. ## Showcase <img width="961" alt="uiexample" src="https://github.com/user-attachments/assets/fb0cfb57-9102-4c6c-bc8e-03d3fa6e0bf6">
This commit is contained in:
parent
267b57e565
commit
a9b2344992
1 changed files with 68 additions and 23 deletions
|
@ -1,11 +1,13 @@
|
||||||
//! This example illustrates the various features of Bevy UI.
|
//! This example illustrates the various features of Bevy UI.
|
||||||
|
|
||||||
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
a11y::{
|
a11y::{
|
||||||
accesskit::{NodeBuilder, Role},
|
accesskit::{NodeBuilder, Role},
|
||||||
AccessibilityNode,
|
AccessibilityNode,
|
||||||
},
|
},
|
||||||
color::palettes::basic::LIME,
|
color::palettes::{basic::LIME, css::DARK_GRAY},
|
||||||
input::mouse::{MouseScrollUnit, MouseWheel},
|
input::mouse::{MouseScrollUnit, MouseWheel},
|
||||||
picking::focus::HoverMap,
|
picking::focus::HoverMap,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
|
@ -158,28 +160,39 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
});
|
});
|
||||||
|
|
||||||
parent
|
parent
|
||||||
.spawn((
|
.spawn(Node {
|
||||||
Node {
|
left: Val::Px(210.),
|
||||||
width: Val::Px(200.0),
|
bottom: Val::Px(10.),
|
||||||
height: Val::Px(200.0),
|
position_type: PositionType::Absolute,
|
||||||
position_type: PositionType::Absolute,
|
..default()
|
||||||
left: Val::Px(210.),
|
})
|
||||||
bottom: Val::Px(10.),
|
|
||||||
border: UiRect::all(Val::Px(20.)),
|
|
||||||
..default()
|
|
||||||
},
|
|
||||||
BorderColor(LIME.into()),
|
|
||||||
BackgroundColor(Color::srgb(0.4, 0.4, 1.)),
|
|
||||||
))
|
|
||||||
.with_children(|parent| {
|
.with_children(|parent| {
|
||||||
parent.spawn((
|
parent
|
||||||
Node {
|
.spawn((
|
||||||
width: Val::Percent(100.0),
|
Node {
|
||||||
height: Val::Percent(100.0),
|
width: Val::Px(200.0),
|
||||||
..default()
|
height: Val::Px(200.0),
|
||||||
},
|
border: UiRect::all(Val::Px(20.)),
|
||||||
BackgroundColor(Color::srgb(0.8, 0.8, 1.)),
|
flex_direction: FlexDirection::Column,
|
||||||
));
|
justify_content: JustifyContent::Center,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
BorderColor(LIME.into()),
|
||||||
|
BackgroundColor(Color::srgb(0.8, 0.8, 1.)),
|
||||||
|
))
|
||||||
|
.with_children(|parent| {
|
||||||
|
parent.spawn((
|
||||||
|
UiImage::new(asset_server.load("branding/bevy_logo_light.png")),
|
||||||
|
// Uses the transform to rotate the logo image by 45 degrees
|
||||||
|
Transform::from_rotation(Quat::from_rotation_z(0.25 * PI)),
|
||||||
|
BorderRadius::all(Val::Px(10.)),
|
||||||
|
Outline {
|
||||||
|
width: Val::Px(2.),
|
||||||
|
offset: Val::Px(4.),
|
||||||
|
color: DARK_GRAY.into(),
|
||||||
|
},
|
||||||
|
));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
let shadow = BoxShadow {
|
let shadow = BoxShadow {
|
||||||
|
@ -187,7 +200,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
blur_radius: Val::Px(2.),
|
blur_radius: Val::Px(2.),
|
||||||
x_offset: Val::Px(10.),
|
x_offset: Val::Px(10.),
|
||||||
y_offset: Val::Px(10.),
|
y_offset: Val::Px(10.),
|
||||||
..Default::default()
|
..default()
|
||||||
};
|
};
|
||||||
|
|
||||||
// render order test: reddest in the back, whitest in the front (flex center)
|
// render order test: reddest in the back, whitest in the front (flex center)
|
||||||
|
@ -303,6 +316,38 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// four bevy icons demonstrating image flipping
|
||||||
|
parent
|
||||||
|
.spawn(Node {
|
||||||
|
width: Val::Percent(100.0),
|
||||||
|
height: Val::Percent(100.0),
|
||||||
|
position_type: PositionType::Absolute,
|
||||||
|
justify_content: JustifyContent::Center,
|
||||||
|
align_items: AlignItems::FlexEnd,
|
||||||
|
column_gap: Val::Px(10.),
|
||||||
|
padding: UiRect::all(Val::Px(10.)),
|
||||||
|
..default()
|
||||||
|
})
|
||||||
|
.with_children(|parent| {
|
||||||
|
for (flip_x, flip_y) in
|
||||||
|
[(false, false), (false, true), (true, true), (true, false)]
|
||||||
|
{
|
||||||
|
parent.spawn((
|
||||||
|
Node {
|
||||||
|
// The height will be chosen automatically to preserve the image's aspect ratio
|
||||||
|
width: Val::Px(75.),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
UiImage {
|
||||||
|
image: asset_server.load("branding/icon.png"),
|
||||||
|
flip_x,
|
||||||
|
flip_y,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue