forked from lc-soft/LCUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_widget_render.c
49 lines (41 loc) · 1.33 KB
/
test_widget_render.c
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
#include <LCUI.h>
#include <pandagl.h>
int main(void)
{
int ret;
pd_canvas_t canvas;
ui_widget_t *root, *box, *txt;
pd_context_t paint;
pd_rect_t area = { 40, 40, 320, 240 };
lcui_init();
root = ui_create_widget(NULL);
box = ui_create_widget(NULL);
txt = ui_create_widget("text");
/* 创建一块灰色的画板 */
pd_canvas_init(&canvas);
pd_canvas_create(&canvas, 320, 240);
pd_canvas_fill(&canvas, pd_rgb(240, 240, 240));
/* 初始化一个绘制实例,绘制区域为整个画板 */
paint.with_alpha = FALSE;
paint.rect.width = 320;
paint.rect.height = 320;
paint.rect.x = paint.rect.y = 0;
pd_canvas_quote(&paint.canvas, &canvas, &area);
/* 设定基本的样式和内容 */
ui_widget_set_style_string(box, "padding", "20px");
ui_widget_set_style_string(box, "border", "1px solid rgb(201,230,242)");
ui_widget_set_style_string(box, "background-color", "rgb(242,249,252)");
ui_text_set_content_w(txt, L"[size=24px]这是一段测试文本[/size]");
ui_widget_append(box, txt);
ui_widget_append(root, box);
/* 更新部件,此处的更新顺序必须是父级到子级 */
ui_widget_update(root);
ui_widget_update(box);
ui_widget_update(txt);
/* 渲染部件 */
ui_widget_render(box, &paint);
ret = pd_write_png_file("test_widget_render.png", &canvas);
pd_canvas_destroy(&canvas);
lcui_destroy();
return ret;
}