CreateItemsBox.ts 1,2 КБ
Newer Older
Medvedev Anton's avatar
Medvedev Anton включено в состав коммита
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
46
47
48
49
50
51
52
53
54
55
56
import { COLOR_LIGHT, COLOR_PRIMARY, COLOR_DARK } from './Const';
import CreateItem from './CreateItem';
import AddDragDropItemBehavior from './AddDragDropItemBehavior';

type SceneType = {
    rexUI: {
        add: {
            sizer: (config: SizerConfig) => Sizer,
            roundRectangle: (config: any) => any
        }
    }
};

type SizerConfig = {
    orientation: string;
    space: {
        left: number;
        right: number;
        top: number;
        bottom: number;
        item?: number;
    };
};

type Sizer = {
    add: (item: any, config: any) => void;
    addBackground: (item: any, key: string) => void;
};

const CreateItemsBox = (scene: SceneType, itemCount: number): Sizer => {
    const itemsBox: Sizer = scene.rexUI.add.sizer({
        orientation: 'y',
        space: {
            left: 5, right: 5, top: 5, bottom: 5,
            item: 5
        },
    });

    itemsBox.addBackground(
        scene.rexUI.add.roundRectangle({}),
        'background'
    );

    for (let i = 0; i < itemCount; i++) {
        itemsBox.add(
            CreateItem(scene, i.toString()),
            { proportion: 0, expand: true }
        );
    }

    AddDragDropItemBehavior(itemsBox);

    return itemsBox;
};

export default CreateItemsBox;