1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00

[lv_list] Fix comments and add implementation of list layout

This commit is contained in:
C47D 2019-07-07 13:30:19 -05:00
parent 95149e466f
commit 3654253472
2 changed files with 48 additions and 6 deletions

View File

@ -366,6 +366,36 @@ void lv_list_set_style(lv_obj_t * list, lv_list_style_t type, const lv_style_t *
}
}
/**
* Set layout of a list
* @param list pointer to a list object
* @param layout which layout should be used
*/
void lv_list_set_layout(lv_obj_t * list, lv_list_layout_t layout)
{
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
/* Update list layout if necessary */
if (layout != lv_list_get_layout(list)) {
/* Get the first button on the list */
lv_obj_t * btn = lv_list_get_prev_btn(list, NULL);
/* Visit all buttons on the list and update their layout */
while(btn != NULL) {
if (LV_LIST_LAYOUT_HOR == layout) {
lv_btn_set_fit2(list, LV_FIT_FLOOD, LV_FIT_TIGHT);
} else { /* LV_LIST_LAYOUT_VER */
lv_btn_set_fit(list, LV_FIT_TIGHT);
}
btn = lv_list_get_prev_btn(list, btn);
}
ext->layout = layout;
}
}
/*=====================
* Getter functions
*====================*/
@ -529,15 +559,25 @@ lv_obj_t * lv_list_get_btn_selected(const lv_obj_t * list)
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
return ext->selected_btn;
}
#endif
/**
* Get layout of a list
* @param list pointer to a list object
* @return layout of the list object
*/
lv_list_layout_t lv_list_get_layout(lv_obj_t * list)
{
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
return ext->layout;
}
/**
* Get a style of a list
* @param list pointer to a list object
* @param type which style should be get
* @return style pointer to a style
* */
*/
const lv_style_t * lv_list_get_style(const lv_obj_t * list, lv_list_style_t type)
{
const lv_style_t * style = NULL;
@ -558,6 +598,7 @@ const lv_style_t * lv_list_get_style(const lv_obj_t * list, lv_list_style_t type
return style;
}
/*=====================
* Other functions
*====================*/

View File

@ -57,6 +57,7 @@ typedef struct
uint16_t size; /*the number of items(buttons) in the list*/
uint8_t single_mode : 1; /* whether single selected mode is enabled */
uint8_t layout : 1; /* Layout of the list */
#if LV_USE_GROUP
lv_obj_t * last_sel; /* The last selected button. It will be reverted when the list is focused again */
@ -78,10 +79,10 @@ enum {
};
typedef uint8_t lv_list_style_t;
/** List layouts. **/
/** List layouts. */
enum {
LV_LIST_LAYOUT_HOR,
LV_LIST_LAYOUT_VER
LV_LIST_LAYOUT_HOR, /*< List horizontal layout */
LV_LIST_LAYOUT_VER /*< List vertical layout */
}
typedef uint8_t lv_list_layout_t;
@ -276,7 +277,7 @@ lv_obj_t * lv_list_get_btn_selected(const lv_obj_t * list);
/**
* Get layout of a list
* @param list pointer to a list object
* @return layout which layout should be used
* @return layout of the list object
*/
lv_list_layout_t lv_list_get_layout(lv_obj_t * list);