Search code examples
rustbevy

Bevy 0.5: arrange text in column


I'm trying to put one text above another using this code

use bevy::prelude::*;

fn setup_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
    let font: Handle<Font> = asset_server.load("fonts/RobotoMono-Regular.ttf");
    commands.spawn_bundle(UiCameraBundle::default());
    commands
        .spawn_bundle(NodeBundle {
            style: Style {
                flex_direction: FlexDirection::Column,
                align_content: AlignContent::FlexEnd,
                ..Default::default()
            },
            visible: Visible {
                is_visible: false,
                is_transparent: false,
            },
            ..Default::default()
        })
        .with_children(|parent| {
            parent.spawn_bundle(TextBundle {
                text: Text::with_section(
                    "HELLO",
                    TextStyle {
                        font: font.clone(),
                        ..Default::default()
                    },
                    TextAlignment {
                        ..Default::default()
                    },
                ),
                ..Default::default()
            });
            parent.spawn_bundle(TextBundle {
                text: Text::with_section(
                    "WORLD",
                    TextStyle {
                        font: font.clone(),
                        ..Default::default()
                    },
                    TextAlignment {
                        ..Default::default()
                    },
                ),
                ..Default::default()
            });
        });
}

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup_ui.system())
        .run();
}

So far it works but unfortunately HELLO has been spaced way too far from WORLD despite every option I try with align_content, how can I make HELLO right above WORLD ?

due to stackoverflow moronic policy on code to text ratio i'm forced to write useless text in my post so i can post it.
blah
blah
blah


Solution

  • I needed to use align_items: AlignItems::FlexEnd instead of align_content (I still have no idea what align_content does lol)