Skip to content

Commit 5163363

Browse files
committed
feat(gui): add Widget_SetStyleString()
1 parent 184b7bf commit 5163363

File tree

7 files changed

+223
-146
lines changed

7 files changed

+223
-146
lines changed

include/LCUI/gui/css_library.h

+4
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ typedef struct LCUI_SelectorRec_ {
198198

199199
#define StyleSheet_GetStyle(S, K) &((S)->sheet[K])
200200

201+
LCUI_API void DestroyStyle(LCUI_Style s);
202+
203+
LCUI_API void MergeStyle(LCUI_Style dst, LCUI_Style src);
204+
201205
LCUI_API LCUI_StyleList StyleList(void);
202206

203207
LCUI_API LCUI_StyleListNode StyleList_GetNode(LCUI_StyleList list, int key);

include/LCUI/gui/css_parser.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ LCUI_BEGIN_HEADER
5050
(CTX)->pos = 0;\
5151
} while( 0 );
5252

53-
#define CSSParser_SetStyleParser( CTX, NAME ) do {\
54-
(CTX)->style.parser = Dict_FetchValue( self.parsers, NAME ); \
55-
} while( 0 );
56-
5753
#define CSSParser_GetRuleParser(CTX) &ctx->rule.parsers[CSS_RULE_FONT_FACE]
5854

5955
typedef enum LCUI_CSSParserTarget {
@@ -121,6 +117,10 @@ struct LCUI_CSSPropertyParserRec_ {
121117
struct LCUI_CSSParserStyleContextRec_ {
122118
char *dirname; /**< 当前所在的目录 */
123119
const char *space; /**< 样式记录所属的空间 */
120+
121+
void (*style_handler)(int, LCUI_Style, void*);
122+
void *style_handler_arg;
123+
124124
LinkedList selectors; /**< 当前匹配到的选择器列表 */
125125
LCUI_StyleSheet sheet; /**< 当前缓存的样式表 */
126126
LCUI_CSSPropertyParser parser; /**< 当前找到的样式属性解析器 */
@@ -162,6 +162,8 @@ LCUI_API const char *LCUI_GetStyleName(int key);
162162
/** 初始化 LCUI 的 CSS 代码解析功能 */
163163
LCUI_API void LCUI_InitCSSParser(void);
164164

165+
LCUI_API LCUI_CSSPropertyParser LCUI_GetCSSPropertyParser(const char *name);
166+
165167
/** 从文件中载入CSS样式数据,并导入至样式库中 */
166168
LCUI_API int LCUI_LoadCSSFile(const char *filepath);
167169

include/LCUI/gui/widget_style.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ void LCUIWidget_FreeStyle(void);
4040
/** 打印部件的样式表 */
4141
LCUI_API void Widget_PrintStyleSheets(LCUI_Widget w);
4242

43-
/** 更新当前部件的样式 */
43+
/** Set widget style by string */
44+
LCUI_API void Widget_SetStyleString(LCUI_Widget w, const char *name, const char *value);
45+
46+
/** 更新当前部件的样式 */
4447
LCUI_API void Widget_UpdateStyle(LCUI_Widget w, LCUI_BOOL is_refresh_all);
4548

4649
/** 更新当前部件的子级部件样式 */

src/gui/css_library.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ LCUI_StyleList StyleList(void)
440440
return list;
441441
}
442442

443-
static void DestroyStyle(LCUI_Style s)
443+
void DestroyStyle(LCUI_Style s)
444444
{
445445
switch (s->type) {
446446
case LCUI_STYPE_STRING:
@@ -461,7 +461,7 @@ static void DestroyStyle(LCUI_Style s)
461461
s->is_valid = FALSE;
462462
}
463463

464-
static void MergeStyle(LCUI_Style dst, LCUI_Style src)
464+
void MergeStyle(LCUI_Style dst, LCUI_Style src)
465465
{
466466
switch (src->type) {
467467
case LCUI_STYPE_STRING:

0 commit comments

Comments
 (0)