-
In the following example, I'd like to shrink the height of the This example deals with height, but I would also like to know how to shrink the width of a GUI component. I'm using Bevy 0.11.0. use bevy::prelude::*;
use bevy::window::WindowResolution;
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
resolution: WindowResolution::new(640.0, 360.0),
..default()
}),
..default()
}))
.add_systems(Startup, startup)
.run();
}
fn startup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
let root_node = spawn_root_node(&mut commands);
let dialog = spawn_dialog(&mut commands);
commands.entity(root_node).add_child(dialog);
}
fn spawn_root_node(commands: &mut Commands) -> Entity {
commands
.spawn(NodeBundle {
style: Style {
width: Val::Percent(100.0),
padding: UiRect::all(Val::Px(16.0)),
..default()
},
..default()
})
.id()
}
fn spawn_dialog(commands: &mut Commands) -> Entity {
commands
.spawn(TextBundle {
text: Text::from_sections([
TextSection::new(
"Alex:\n",
TextStyle {
font_size: 30.0,
..default()
},
),
TextSection::new(
"Hi there.",
TextStyle {
font_size: 30.0,
..default()
},
),
]),
style: Style {
// height: todo!(),
..default()
},
background_color: Color::DARK_GRAY.into(),
..default()
})
.id()
} |
Beta Was this translation helpful? Give feedback.
Answered by
ickshonpe
Aug 12, 2023
Replies: 1 comment 4 replies
-
The default behaviour is
or
|
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
mamekoro
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The default behaviour is
AlignItems::Stretch
which stretches the node to fill the whole cross-axis.You can either use
AlignSelf
on the node, orAlignItems
on its parent to change it: