CSS 解析器和选择引擎库
- 开始日期:2023-05-01
- 目标主要版本:3.x
- 参考问题:无
- 实现 PR:无
概括
将 CSS 相关的功能模块整合为独立的子库,重新设计部分接口,移除对 UI 库、线程库、字体库的依赖。
基本示例
#include <stdio.h>
#include <css.h>
char css_str[] = "\
* {\
box-sizing: border-box;\
}\
.btn {\
font-size: 14px;\
}\
";
int main(void)
{
css_prop_t *prop;
css_selector_t *selector;
css_style_decl_t *style;
css_init();
css_load_from_string(css_str);
selector = css_selector_create(".btn");
style = css_select_style(selector);
prop = css_style_decl_find(style, css_key_font_size);
if (prop != NULL) {
printf("font-size: %fpx\n", prop->value.unit_value.value);
}
css_selector_destroy(selector);
css_style_decl_destroy(style);
css_destroy();
return 0;
}