Replace Transform in the UI with NodeTransform#8240
Replace Transform in the UI with NodeTransform#8240ickshonpe wants to merge 35 commits intobevyengine:mainfrom
Transform in the UI with NodeTransform#8240Conversation
…n for the vertical text.
…not just changed.
NodePositionTransform and GlobalTransform in the UI with NodePosition
|
This partially fixes #7876. Strongly in favor of this direction. |
|
Haven't been able to give this a thorough review just yet, but I'm also in favor of this change, if not only to avoid transform propagation from wasting time on UI hierarchies when the layoutting algorithm already does that natively. |
|
This is a regression, as we lose the ability to rotate and scale independently of the layout. Having a I would prefer to add support for (even limited to rotation and scale) transform functions to our UI before removing the actual |
|
You added a new example but didn't add metadata for it. Please update the root Cargo.toml file. |
Transform and GlobalTransform in the UI with NodeTransformTransform in the UI with NodeTransform
|
on rotations, this does not behave like I expected it to: use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_systems(Update, rotate)
.run();
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands
.spawn(NodeBundle { ..default() })
.with_children(|parent| {
parent.spawn((TextBundle::from_section(
"Text Example 1",
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: 30.0,
color: Color::WHITE,
},
),));
parent.spawn((
TextBundle::from_section(
"Text Example 2",
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: 30.0,
color: Color::WHITE,
},
),
NodeRotation::default(),
));
});
}
fn rotate(mut rots: Query<&mut NodeRotation>, time: Res<Time>) {
for mut rot in &mut rots {
rot.0 += time.delta_seconds();
}
}text-rotation.mp4 |
examples/ui/node_transform.rs
Outdated
| background_color: Color::WHITE.into(), | ||
| ..default() | ||
| }) | ||
| .insert(RotateButton(-std::f32::consts::PI / 8.)) |
There was a problem hiding this comment.
| .insert(RotateButton(-std::f32::consts::PI / 8.)) | |
| .insert(RotateButton(-std::f32::consts::FRAC_PI_8)) |
You should use the appropriate constants instead of dividing PI
see https://doc.rust-lang.org/std/f32/consts/index.html
There was a problem hiding this comment.
please also do the other PI fractions
Co-authored-by: François <mockersf@gmail.com>
This is because it's rotating the Ui Node, not only the text. If you add background colors it becomes obvious what is happening: By default items stretch to fill the cross-axis, you can get the text to rotate on its center by setting I thought about adding some sort of anchors, but I think it goes beyond the scope of this PR probably. |
|
Agreed: I'd like anchors, but not in this PR. IMO rotating the entire node is the correct behavior here. |
|
Still I was expecting it to behave like this html: text-rotation-html.mp4EDIT: this PR does behave the same as in Bevy 0.10 use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_systems(Update, rotate)
.run();
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands
.spawn(NodeBundle { ..default() })
.with_children(|parent| {
parent.spawn((TextBundle::from_section(
"Text Example 1",
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: 30.0,
color: Color::WHITE,
},
),));
parent.spawn((
TextBundle::from_section(
"Text Example 2",
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: 30.0,
color: Color::WHITE,
},
),
NodeRotation,
));
});
}
#[derive(Component)]
struct NodeRotation;
fn rotate(mut rots: Query<&mut Transform, With<NodeRotation>>, time: Res<Time>) {
for mut rot in &mut rots {
rot.rotate_local_z(time.delta_seconds());
}
} |
Co-authored-by: François <mockersf@gmail.com>
Rotating content like this text is really easy to implement at the widget level. We would just need to add a rotation value to |
|
Closing in favour of #16615 |
Objective
Bevy UI uses
TransformandGlobalTransformto manage node positions. There are lots of problems:Transformbreaking the UI layout.TransformandGlobalTransformare big, 112 bytes together in total.GlobalTransform.Transform.propagate_transformshas to be run afterflex_layout_systemSolution
Remove the
TransformandGlobalTransformcomponents and queries from the UI bundles and systems. Replace them with a a tuple struct component wrapping anAffine2calledNodeTransform.Bevy.App.2023-03-30.14-12-09.mp4
Changelog
NodeTransformwhich is a tuple struct component wrapping anAffine2calledNodeTransform.NodeTransformto the UI node bundles.Transform andGlobalTransform` from the UI node bundles.TransformSystemafter and before conditions fromUiPluginNodePositioninstead ofTransform/GlobalTransform.ui_focus_systemto respond correctly to interactions with rotated and scaled elements.node_transformthat demos interactions with translated, rotated and scaled buttons.NodeTranslation,NodeRotationandNodeScalecomponents.Migration Guide
The
TransformandGlobalTransformcomponents have been replaced in Bevy UI's node bundles by the componentNodeTransform.The components
NodeTranslation,NodeRotationandNodeScalecan be added to UI node entities to allow translation, rotation and scaling of a node and its children.