-
That's the corresponding method: fn setup_window(
mut materials: ResMut<Assets<ColorMaterial>>,
mut meshes: ResMut<Assets<Mesh>>,
mut commands: Commands,
windows: Query<&Window>,
) {
let window = windows.single();
let window_width = window.unwrap().width();
let rect_height = 30.0;
commands
.spawn((
Node {
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
width: Val::Percent(0.0),
height: Val::Percent(90.0),
..default()
},
Mesh2d(meshes.add(Rectangle::new(window_width, rect_height))),
MeshMaterial2d(materials.add(Color::Srgba(Srgba::GREEN))),
Pickable::IGNORE,
))
.with_children(|parent| {
// Spawn three pill-shaped buttons
Buttons::iter().for_each(|button_name| {
parent.spawn((
Node {
width: Val::Px(0.0),
height: Val::Px(0.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
margin: UiRect::horizontal(Val::Px(60.0)),
..default()
},
children![(
BorderColor(Color::BLACK),
BorderRadius::MAX,
Mesh2d(meshes.add(Capsule2d::new(20.0, 60.))),
MeshMaterial2d(materials.add(Color::Srgba(Srgba::BLUE))),
Pickable::IGNORE,
Transform::from_translation(Vec3::new(0.0, 0.0, 1.0))
.with_rotation(Quat::from_rotation_z(std::f32::consts::FRAC_PI_2)),
Text::new("new!"),
TextLayout::new(JustifyText::Center, bevy::text::LineBreak::NoWrap),
)],
button_name,
));
});
});
} Somehow I can't get the text to appear on the meshes, but somewhere in the field. Can anyone see what I'm missing? |
Beta Was this translation helpful? Give feedback.
Answered by
rparrett
May 2, 2025
Replies: 1 comment 6 replies
-
A couple important points:
It looks like you want to make some buttons that are round rectangles? You want a hierarchy like this:
See the |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It solves a problem. It is a fundamental mistake that may be leading you astray and wasting your time. And fixing it means that we can continue the conversation while talking about valid Bevy code.
It sounds like maybe you want these buttons contained in a bar at the top of the screen? Here's a modification of the code I shared above that does that.
Expand Code