# 构造器 builder
将布局数据构造成指定类型的控件 支持多层结构的数据
# 基础的控件类
| 名字 | 类型 | 说明 | 
|---|---|---|
| 面板 | panel | 用来做底板 继承的子类可添加子控件 | 
| 图像 | texture | 用来只显示图像不做任何操作 | 
| 按钮 | button | 用来响应用户鼠标点击进入离开操作 | 
| 文本 | text | 用来显示文字 | 
| 编辑框 | edit | 用来获取用户输入文字 | 
| 模型 | model | 用来显示 mdx mdl 模型 | 
| 模型 2 | model | 用来显示 3d 模型 | 
# 例子
- 构造一个面板
 
    local panel = class.panel:builder {
        x = 300,
        y = 300,
        w = 300,
        h = 300,
        normal_image = "xx.blp",
    }
 1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
- 构造一个图像
 
    local texture = class.texture:builder {
        x = 300,
        y = 300,
        w = 300,
        h = 300,
        normal_image = "xx.blp",
    }
 1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
- 构造一个按钮
 
    local button = class.button:builder {
        x = 300,
        y = 300,
        w = 300,
        h = 300,
        normal_image = "xx.blp",
    }
 1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
- 构造一个文本
 
    local text = class.text:builder {
        x = 300,
        y = 300,
        w = 300,
        h = 300,
        text = "文本内容",
        align = 'center',
        font_size = 15,
    }
 1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
- 构造一个按钮带文字
 
当 x y 轴不填时 默认是 0 w h 不填时 默认为父控件大小
    local button = class.button:builder {
        x = 300,
        y = 300,
        w = 300,
        h = 300,
        normal_image = "xx.blp",
        text = {
            type = "text",
            text = "文字内容",
            align = 'center',
            font_size = 15,
        }
    }
    button.text:set_text("新的文本内容")
 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
等价于
    local button = class.button:builder {
        x = 300,
        y = 300,
        w = 300,
        h = 300,
        normal_image = "xx.blp",
    }
    button.text = class.text:builder
        parent = button,
        text = "文字内容",
        align = 'center',
        font_size = 15,
    }
    button.text:set_text("新的文本内容")
 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- 创建一个像魔兽一样的技能按钮
 
    local w, h = 91, 71
    local button = class.button:builder {
        x = 100,
        y = 100,
        w = w,
        y = h,
        normal_image = "button.blp",
        --右下角数字背景
        icon = {
            type = 'texture',
            x = w - 32,
            y = h - 32,
            w = 32,
            h = 32,
            num = {
                type = 'text',
                text = '10',
                align = 'center',
                font_size = 8,
            }
        },
        --cd 模型
        model = {
            type = 'model',
            model = [[UI\Feedback\Cooldown\UI-Cooldown-Indicator.mdl]],
            is_show = false, --默认隐藏
            animation = 0,
            animation_loop = false,
            scale_x = 0.65,
            scale_y = 0.85,
        }
    }
 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
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