mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-24 08:16:29 +08:00
fix(xml): fix xml property propagation issues
This commit is contained in:
committed by
Liam Howatt
parent
1964dfe2ab
commit
5652914e14
@@ -7,12 +7,15 @@
|
||||
<styles>
|
||||
<style name="btn_style" bg_color="#dark_blue" bg_opa="150"/>
|
||||
<style name="btn_pr_style" bg_opa="255"/>
|
||||
<style name="red_border" border_color="0xff0000"></style>
|
||||
|
||||
</styles>
|
||||
|
||||
<view extends="lv_obj" name="main" width="280" height="content" style_bg_color="#light_blue">
|
||||
<lv_label text="Hello"/>
|
||||
<my_card title="Card 1" name="card1"
|
||||
y="0"
|
||||
styles="red_border"
|
||||
btn_rel_style="btn_style"
|
||||
btn_pr_style="btn_pr_style"/>
|
||||
|
||||
|
||||
+18
-6
@@ -143,11 +143,6 @@ void * lv_xml_create_from_ctx(lv_obj_t * parent, lv_xml_component_ctx_t * parent
|
||||
|
||||
state.item = state.view;
|
||||
|
||||
if(attrs) {
|
||||
lv_widget_processor_t * proc = lv_xml_widget_get_extended_widget_processor(ctx->extends);
|
||||
proc->apply_cb(&state, attrs);
|
||||
}
|
||||
|
||||
lv_ll_clear(&state.parent_ll);
|
||||
XML_ParserFree(parser);
|
||||
|
||||
@@ -164,7 +159,9 @@ void * lv_xml_create(lv_obj_t * parent, const char * name, const char ** attrs)
|
||||
lv_xml_parser_state_t state;
|
||||
lv_xml_parser_state_init(&state);
|
||||
state.parent = parent;
|
||||
state.ctx.name = "";
|
||||
/*When a widget is just created there is no context where
|
||||
*its styles, constants, etc are stored. So use the global context.*/
|
||||
state.ctx = *lv_xml_component_get_ctx("globals");
|
||||
state.item = p->create_cb(&state, attrs);
|
||||
if(attrs) {
|
||||
p->apply_cb(&state, attrs);
|
||||
@@ -175,6 +172,21 @@ void * lv_xml_create(lv_obj_t * parent, const char * name, const char ** attrs)
|
||||
lv_xml_component_ctx_t * ctx = lv_xml_component_get_ctx(name);
|
||||
if(ctx) {
|
||||
item = lv_xml_create_from_ctx(parent, NULL, ctx, attrs);
|
||||
|
||||
if(attrs) {
|
||||
lv_xml_parser_state_t state;
|
||||
lv_xml_parser_state_init(&state);
|
||||
state.parent = parent;
|
||||
state.item = item;
|
||||
|
||||
/*When a component is just created there is no context where
|
||||
*its styles, constants, etc are stored. So use the global context.*/
|
||||
state.ctx = *lv_xml_component_get_ctx("globals");
|
||||
|
||||
p = lv_xml_widget_get_extended_widget_processor(ctx->extends);
|
||||
p->apply_cb(&state, attrs);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
@@ -106,6 +106,8 @@ lv_xml_component_ctx_t * lv_xml_component_get_ctx(const char * component_name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
lv_result_t lv_xml_component_register_from_data(const char * name, const char * xml_def)
|
||||
{
|
||||
bool globals = false;
|
||||
@@ -132,6 +134,7 @@ lv_result_t lv_xml_component_register_from_data(const char * name, const char *
|
||||
XML_ErrorString(XML_GetErrorCode(parser)),
|
||||
(unsigned long)XML_GetCurrentLineNumber(parser));
|
||||
XML_ParserFree(parser);
|
||||
lv_free((char *)state.ctx.extends);
|
||||
return LV_RESULT_INVALID;
|
||||
}
|
||||
|
||||
@@ -229,6 +232,7 @@ lv_result_t lv_xml_component_unregister(const char * name)
|
||||
|
||||
lv_free((char *)ctx->name);
|
||||
lv_free((char *)ctx->view_def);
|
||||
lv_free((char *)ctx->extends);
|
||||
|
||||
lv_xml_const_t * cnst;
|
||||
LV_LL_READ(&ctx->const_ll, cnst) {
|
||||
@@ -634,7 +638,6 @@ static void start_metadata_handler(void * user_data, const char * name, const ch
|
||||
|
||||
if(lv_streq(name, "widget")) state->ctx.is_widget = 1;
|
||||
|
||||
|
||||
/* Process elements based on current context */
|
||||
switch(state->section) {
|
||||
case LV_XML_PARSER_SECTION_API:
|
||||
@@ -646,10 +649,12 @@ static void start_metadata_handler(void * user_data, const char * name, const ch
|
||||
if(old_section != state->section) return; /*Ignore the section opening, e.g. <consts>*/
|
||||
process_const_element(state, attrs);
|
||||
break;
|
||||
|
||||
case LV_XML_PARSER_SECTION_GRAD:
|
||||
if(old_section != state->section) return; /*Ignore the section opening, e.g. <gradients>*/
|
||||
process_grad_element(state, name, attrs);
|
||||
break;
|
||||
|
||||
case LV_XML_PARSER_SECTION_GRAD_STOP:
|
||||
process_grad_stop_element(state, attrs);
|
||||
break;
|
||||
@@ -658,10 +663,12 @@ static void start_metadata_handler(void * user_data, const char * name, const ch
|
||||
if(old_section != state->section) return; /*Ignore the section opening, e.g. <styles>*/
|
||||
lv_xml_style_register(&state->ctx, attrs);
|
||||
break;
|
||||
|
||||
case LV_XML_PARSER_SECTION_FONTS:
|
||||
if(old_section != state->section) return; /*Ignore the section opening, e.g. <styles>*/
|
||||
process_font_element(state, name, attrs);
|
||||
break;
|
||||
|
||||
case LV_XML_PARSER_SECTION_IMAGES:
|
||||
if(old_section != state->section) return; /*Ignore the section opening, e.g. <styles>*/
|
||||
process_image_element(state, name, attrs);
|
||||
|
||||
Reference in New Issue
Block a user