lc-soft / LCUI

C library for building user interfaces
https://lcui-dev.github.io
MIT License
4.13k stars 356 forks source link

[Feature request]针对各个控件、功能的小演示代码段 #217

Closed retsyo closed 4 years ago

retsyo commented 4 years ago

test目录下的代码、博客的文章,都太长了,看晕了。有没有专门针对各个控件、功能的小的演示代码段或者文档?比如,如何在程序中读取、设置控件位置、尺寸、属性、事件;能否使用css等内容的字符串,而不是去读磁盘文件

lc-soft commented 4 years ago

有没有专门针对各个控件、功能的小的演示代码段或者文档?

常用的也就这四个:

image

如需其它组件可用这个组件库:

https://github.com/lc-ui/lc-design/blob/develop/README.zh-cn.md

下载运行它的 demo 程序可浏览组件用法、示例代码和预览效果:

https://github.com/lc-ui/lc-design/releases/download/v1.1.0/lc-design-demo.zip

如何在程序中读取、设置控件位置、尺寸、属性、事件

读取位置、尺寸:

LCUI_Widget w;

w->x;
w->y;
w->width;
w->height;

详见结构体定义:

https://github.com/lc-soft/LCUI/blob/7fb6a04564e2d56398a017564f9a9ad34c81a97d/include/LCUI/gui/widget_base.h#L253-L292

设置位置、尺寸:

https://github.com/lc-soft/LCUI/blob/7fb6a04564e2d56398a017564f9a9ad34c81a97d/include/LCUI/gui/widget_helper.h#L59-L67

建议用 CSS 代码实现位置和尺寸设置。

样式属性读取/设置:

https://github.com/lc-soft/LCUI/blob/7fb6a04564e2d56398a017564f9a9ad34c81a97d/include/LCUI/gui/widget_base.h#L339-L349

https://github.com/lc-soft/LCUI/blob/7fb6a04564e2d56398a017564f9a9ad34c81a97d/include/LCUI/gui/widget_helper.h#L65-L69

https://github.com/lc-soft/LCUI/blob/7fb6a04564e2d56398a017564f9a9ad34c81a97d/include/LCUI/gui/widget_style.h#L42-L46

自定义字符串属性读取/设置:

https://github.com/lc-soft/LCUI/blob/7fb6a04564e2d56398a017564f9a9ad34c81a97d/include/LCUI/gui/widget_attribute.h#L35-L45

事件绑定/解绑:

https://github.com/lc-soft/LCUI/blob/7fb6a04564e2d56398a017564f9a9ad34c81a97d/include/LCUI/gui/widget_event.h#L122-L174

能否使用css等内容的字符串,而不是去读磁盘文件

用 LCUI_LoadCSSString() 从字符串中加载 CSS:

https://github.com/lc-soft/LCUI/blob/7fb6a04564e2d56398a017564f9a9ad34c81a97d/include/LCUI/gui/css_parser.h#L166-L172

用 CodeToString() 宏将代码转字符串:

https://github.com/lc-soft/LCUI/blob/7fb6a04564e2d56398a017564f9a9ad34c81a97d/src/gui/widget/button.c#L42-L69

用 LCUIBuilder_LoadString() 从字符串中加载 XML:

https://github.com/lc-soft/LCUI/blob/7fb6a04564e2d56398a017564f9a9ad34c81a97d/include/LCUI/gui/builder.h#L36-L42