Skip to content

Commit c4b6836

Browse files
authored
Add a UiTransform centered scene to examples/testbed/ui (#21974)
# Objective Fixes #21815 ## Solution - Adds a new scene to `examples/testbed/ui` called `Transformations` that calls some basic `UiTransform`s on Nodes. This is my first PR for Bevy! ## Testing I ran the example via console to test out the scene. Tested on Desktop MacOS 15.7.1 ## Showcase <img width="902" height="780" alt="Screenshot 2025-11-29 at 11 29 52 AM" src="https://github.com/user-attachments/assets/602ab485-61dd-4887-a0ad-0624b3d79db8" /> To view, run in console: `cargo run --package bevy --example testbed_ui` Press spacebar 11x until you see the new scene.
1 parent 3702373 commit c4b6836

File tree

1 file changed

+88
-1
lines changed

1 file changed

+88
-1
lines changed

examples/testbed/ui.rs

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fn main() {
2222
.add_systems(OnEnter(Scene::LayoutRounding), layout_rounding::setup)
2323
.add_systems(OnEnter(Scene::LinearGradient), linear_gradient::setup)
2424
.add_systems(OnEnter(Scene::RadialGradient), radial_gradient::setup)
25+
.add_systems(OnEnter(Scene::Transformations), transformations::setup)
2526
.add_systems(Update, switch_scene);
2627

2728
#[cfg(feature = "bevy_ci_testing")]
@@ -45,6 +46,7 @@ enum Scene {
4546
LayoutRounding,
4647
LinearGradient,
4748
RadialGradient,
49+
Transformations,
4850
}
4951

5052
impl Next for Scene {
@@ -60,7 +62,8 @@ impl Next for Scene {
6062
Scene::Slice => Scene::LayoutRounding,
6163
Scene::LayoutRounding => Scene::LinearGradient,
6264
Scene::LinearGradient => Scene::RadialGradient,
63-
Scene::RadialGradient => Scene::Image,
65+
Scene::RadialGradient => Scene::Transformations,
66+
Scene::Transformations => Scene::Image,
6467
}
6568
}
6669
}
@@ -882,3 +885,87 @@ mod radial_gradient {
882885
});
883886
}
884887
}
888+
889+
mod transformations {
890+
use bevy::{color::palettes::css::*, prelude::*};
891+
892+
pub fn setup(mut commands: Commands) {
893+
commands.spawn((Camera2d, DespawnOnExit(super::Scene::Transformations)));
894+
commands
895+
.spawn((
896+
Node {
897+
width: percent(100),
898+
height: percent(100),
899+
display: Display::Block,
900+
..default()
901+
},
902+
DespawnOnExit(super::Scene::Transformations),
903+
))
904+
.with_children(|parent| {
905+
for (transformation, label, background) in [
906+
(
907+
UiTransform::from_rotation(Rot2::degrees(45.)),
908+
"Rotate 45 degrees",
909+
RED,
910+
),
911+
(
912+
UiTransform::from_scale(Vec2::new(2., 0.5)),
913+
"Scale 2.x 0.5y",
914+
GREEN,
915+
),
916+
(
917+
UiTransform::from_translation(Val2::px(-50., 50.)),
918+
"Translate -50px x +50px y",
919+
BLUE,
920+
),
921+
(
922+
UiTransform {
923+
translation: Val2::px(50., 0.),
924+
scale: Vec2::new(-1., 1.),
925+
rotation: Rot2::degrees(30.),
926+
},
927+
"T 50px x\nS -1.x (refl)\nR 30deg",
928+
DARK_CYAN,
929+
),
930+
] {
931+
parent
932+
.spawn((Node {
933+
width: percent(100),
934+
margin: UiRect {
935+
top: px(50),
936+
bottom: px(50),
937+
..default()
938+
},
939+
align_items: AlignItems::Center,
940+
justify_content: JustifyContent::SpaceAround,
941+
..default()
942+
},))
943+
.with_children(|row| {
944+
row.spawn((
945+
Text::new("Before Tf"),
946+
Node {
947+
width: px(100),
948+
height: px(100),
949+
border_radius: BorderRadius::bottom_right(px(25.)),
950+
..default()
951+
},
952+
BackgroundColor(background.into()),
953+
TextFont::default(),
954+
));
955+
row.spawn((
956+
Text::new(label),
957+
Node {
958+
width: px(100),
959+
height: px(100),
960+
border_radius: BorderRadius::bottom_right(px(25.)),
961+
..default()
962+
},
963+
BackgroundColor(background.into()),
964+
transformation,
965+
TextFont::default(),
966+
));
967+
});
968+
}
969+
});
970+
}
971+
}

0 commit comments

Comments
 (0)