1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use bevy::{ecs::system::EntityCommands, prelude::*};

use crate::{GuiCommands, OuterStyle};

pub trait LabelCommands<'w, 's> {
    fn spawn_label(&mut self, size: OuterStyle, caption: impl Into<String>) -> EntityCommands<'_>;
}

impl<'w, 's> LabelCommands<'w, 's> for GuiCommands<'w, 's> {
    fn spawn_label(&mut self, style: OuterStyle, caption: impl Into<String>) -> EntityCommands<'_> {
        let text_style = self.text_props().label_text_style();

        let mut commands = self.spawn(NodeBundle {
            style: Style {
                justify_content: JustifyContent::FlexStart,
                align_items: AlignItems::Center,
                width: style.width,
                height: style.height,
                margin: style.margin,
                ..default()
            },
            ..default()
        });

        commands.with_children(|builder| {
            builder.spawn(TextBundle::from_section(caption, text_style));
        });

        commands
    }
}