feat(xml): add support for scroll snapping

This commit is contained in:
Gabor Kiss-Vamosi
2025-06-11 11:26:47 +02:00
parent 104ede500e
commit 40158e483a
5 changed files with 29 additions and 0 deletions
+11
View File
@@ -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;
+7
View File
@@ -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"
@@ -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));
+7
View File
@@ -186,6 +186,13 @@
<enum name="full" help=""/>
</enumdef>
<enumdef name="lv_scroll_snap">
<enum name="none" help=""/>
<enum name="start" help=""/>
<enum name="end" help=""/>
<enum name="center" help=""/>
</enumdef>
<enumdef name="lv_screen_load_anim">
<enum name="none" help=""/>
<enum name="over_left" help=""/>
+2
View File
@@ -184,6 +184,8 @@ Example
<prop name="align" type="enum:lv_align"/>
<prop name="ext_click_area" type="int"/>
<prop name="scroll_snap_x" type="enum:lv_scroll_snap"/>
<prop name="scroll_snap_y" type="enum:lv_scroll_snap"/>
<prop name="style_x" type="coords"/>
<prop name="style_y" type="coords"/>