diff --git a/examples/others/xml/view.xml b/examples/others/xml/view.xml
index b4415b12b4..e66da53304 100644
--- a/examples/others/xml/view.xml
+++ b/examples/others/xml/view.xml
@@ -7,12 +7,15 @@
+
+
diff --git a/src/others/xml/lv_xml.c b/src/others/xml/lv_xml.c
index 1d45933747..6b3e800e81 100644
--- a/src/others/xml/lv_xml.c
+++ b/src/others/xml/lv_xml.c
@@ -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;
}
diff --git a/src/others/xml/lv_xml_component.c b/src/others/xml/lv_xml_component.c
index be2ce77dca..0ca7c3af7b 100644
--- a/src/others/xml/lv_xml_component.c
+++ b/src/others/xml/lv_xml_component.c
@@ -106,6 +106,8 @@ lv_xml_component_ctx_t * lv_xml_component_get_ctx(const char * component_name)
return NULL;
}
+#include
+
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. */
process_const_element(state, attrs);
break;
+
case LV_XML_PARSER_SECTION_GRAD:
if(old_section != state->section) return; /*Ignore the section opening, e.g. */
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. */
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. */
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. */
process_image_element(state, name, attrs);