diff --git a/src/others/xml/lv_xml_base_types.c b/src/others/xml/lv_xml_base_types.c index e7af6343d9..3c6e97c2e2 100644 --- a/src/others/xml/lv_xml_base_types.c +++ b/src/others/xml/lv_xml_base_types.c @@ -153,6 +153,17 @@ lv_text_decor_t lv_xml_text_decor_to_enum(const char * txt) return 0; /*Return 0 in lack of a better option. */ } +lv_scroll_snap_t lv_xml_scroll_snap_to_enum(const char * txt) +{ + if(lv_streq("none", txt)) return LV_SCROLL_SNAP_NONE; + if(lv_streq("start", txt)) return LV_SCROLL_SNAP_START; + if(lv_streq("center", txt)) return LV_SCROLL_SNAP_CENTER; + if(lv_streq("end", txt)) return LV_SCROLL_SNAP_END; + + LV_LOG_WARN("%s is an unknown value for scroll_snap", txt); + return 0; /*Return 0 in lack of a better option. */ +} + lv_flex_flow_t lv_xml_flex_flow_to_enum(const char * txt) { if(lv_streq("column", txt)) return LV_FLEX_FLOW_COLUMN; diff --git a/src/others/xml/lv_xml_base_types.h b/src/others/xml/lv_xml_base_types.h index 7d33852617..726f4eaa04 100644 --- a/src/others/xml/lv_xml_base_types.h +++ b/src/others/xml/lv_xml_base_types.h @@ -90,6 +90,13 @@ lv_text_align_t lv_xml_text_align_to_enum(const char * txt); */ lv_text_decor_t lv_xml_text_decor_to_enum(const char * txt); +/** + * Convert a scroll snap string to enum + * @param txt e.g. "start" + * @return the related enum, e.g. `LV_SCROLL_SNAP_START` + */ +lv_scroll_snap_t lv_xml_scroll_snap_to_enum(const char * txt); + /** * Convert a flex flow string to enum * @param txt e.g. "row_wrap" diff --git a/src/others/xml/parsers/lv_xml_obj_parser.c b/src/others/xml/parsers/lv_xml_obj_parser.c index 92c468163f..6c9d924b2c 100644 --- a/src/others/xml/parsers/lv_xml_obj_parser.c +++ b/src/others/xml/parsers/lv_xml_obj_parser.c @@ -88,6 +88,8 @@ void lv_xml_obj_apply(lv_xml_parser_state_t * state, const char ** attrs) else if(lv_streq("flex_flow", name)) lv_obj_set_flex_flow(item, lv_xml_flex_flow_to_enum(value)); else if(lv_streq("flex_grow", name)) lv_obj_set_flex_grow(item, lv_xml_atoi(value)); else if(lv_streq("ext_click_area", name)) lv_obj_set_ext_click_area(item, lv_xml_atoi(value)); + else if(lv_streq("scroll_snap_x", name)) lv_obj_set_scroll_snap_x(item, lv_xml_scroll_snap_to_enum(value)); + else if(lv_streq("scroll_snap_y", name)) lv_obj_set_scroll_snap_y(item, lv_xml_scroll_snap_to_enum(value)); else if(lv_streq("hidden", name)) lv_obj_set_flag(item, LV_OBJ_FLAG_HIDDEN, lv_xml_to_bool(value)); else if(lv_streq("clickable", name)) lv_obj_set_flag(item, LV_OBJ_FLAG_CLICKABLE, lv_xml_to_bool(value)); diff --git a/xmls/globals.xml b/xmls/globals.xml index bc6abaea4e..aa8fcc716b 100644 --- a/xmls/globals.xml +++ b/xmls/globals.xml @@ -186,6 +186,13 @@ + + + + + + + diff --git a/xmls/lv_obj.xml b/xmls/lv_obj.xml index d62010bef6..cc4c9ece03 100644 --- a/xmls/lv_obj.xml +++ b/xmls/lv_obj.xml @@ -184,6 +184,8 @@ Example + +