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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use bevy::prelude::*;
use bevy_lunex::prelude::*;

use super::components::{List, ListUi};
use crate::{resources::CodexSettings, widgets::button::components::CustomButton};

pub fn build_list(
    mut commands: Commands,
    query: Query<(Entity, &List), Added<List>>,
    assets: Res<AssetServer>,
    codex_settings: Res<CodexSettings>,
) {
    for (entity, list) in &query {
        commands
            .entity(entity)
            .insert(UiTreeBundle::<ListUi>::from(UiTree::new2d("List")))
            .with_children(|ui| {
                let mut offset = 0.0;
                let list_link = UiLink::<ListUi>::path("List");
                ui.spawn((
                    list_link.clone(),
                    UiLayout::window_full().pack::<Base>(),
                    Pickable::IGNORE,
                ));
                for item in &list.items {
                    ui.spawn((
                        list_link.add("Button-".to_string() + item),
                        UiLayout::window()
                            .y(Rl(offset))
                            .x(Rl(5.0))
                            .size((Rl(90.0), Ab(list.size)))
                            .pack::<Base>(),
                        Pickable::IGNORE,
                        CustomButton {
                            link: "Button".to_string(),
                            text: item.to_string(),
                            texture: assets.load(codex_settings.button_texture.clone()),
                            color: codex_settings.button_color,
                        },
                    ));
                    offset += list.gap + list.size;
                }
            });
    }
}