Files
LCUI/test/test_widget_render.c
T
YDYKand李梓豪 b46306ddea refactor(util): add yutil library (#264)
* add yutil

* add yutil to util.h

* remove util file that same as yutil's

* replace the old header file like '#include <LCUI/util/*>' with yutil's head file

* Replace the old UTIL module associated data structures and function call code

* change timer

* Replace the old UTIL module associated data structures and function call code

* fix

* fix compilation problems(RGB to YUTIL_TEST_RGB)

* turn some useless changes back to origin

* change YUTIL_TEST_RGB back to RGB and add  lcui-util/xmake.lua include

* update github action

* update github action

* update github action

* change new yutil func name

* update xmake and change way to include yutil

* update include to <yutil.h>

* update list_for_each to for(list_each())

* fix

* add graph.h to test_*

* add #include <LCUI/graph.h>

* update yutil

* change timer func name and update submodule

* update submodules

* test strncpy

* turn useless code back origin

* fix lose RGB issue

* fix yutil charset

* update yutil

* update yutil

* add yutil_test instead of lcui-util test

* change timer func name style

Co-authored-by: 李梓豪 <yidianyiko@foxmail.com>
2023-04-01 22:34:33 +08:00

59 lines
1.6 KiB
C

#include <LCUI.h>
#include <LCUI/gui/widget.h>
#include <LCUI/gui/widget/textview.h>
#include <LCUI/graph.h>
#include <LCUI/image.h>
int main(void)
{
int ret;
LCUI_Graph canvas;
LCUI_Widget root, box, txt;
LCUI_PaintContextRec paint;
LCUI_Rect area = { 40, 40, 320, 240 };
LCUI_Color bgcolor = RGB(242, 249, 252);
LCUI_Color bdcolor = RGB(201, 230, 242);
LCUI_Init();
root = LCUIWidget_New(NULL);
box = LCUIWidget_New(NULL);
txt = LCUIWidget_New("textview");
/* 创建一块灰色的画板 */
Graph_Init(&canvas);
Graph_Create(&canvas, 320, 240);
Graph_FillRect(&canvas, RGB(240, 240, 240), NULL, FALSE);
/* 初始化一个绘制实例,绘制区域为整个画板 */
paint.with_alpha = FALSE;
paint.rect.width = 320;
paint.rect.height = 320;
paint.rect.x = paint.rect.y = 0;
Graph_Quote(&paint.canvas, &canvas, &area);
/* 设定基本的样式和内容 */
Widget_SetPadding(box, 20, 20, 20, 20);
Widget_SetBorder(box, 1, SV_SOLID, bdcolor);
Widget_SetStyle(box, key_background_color, bgcolor, color);
TextView_SetTextW(txt, L"[size=24px]这是一段测试文本[/size]");
Widget_Append(box, txt);
Widget_Append(root, box);
/* 标记需要更新样式 */
Widget_UpdateStyle(txt, TRUE);
Widget_UpdateStyle(box, TRUE);
Widget_UpdateStyle(root, TRUE);
/* 更新部件,此处的更新顺序必须是父级到子级 */
Widget_Update(root);
Widget_Update(box);
Widget_Update(txt);
/* 渲染部件 */
Widget_Render(box, &paint);
ret = LCUI_WritePNGFile("test_widget_render.png", &canvas);
Graph_Free(&canvas);
LCUI_Destroy();
return ret;
}