diff --git a/components/rtgui/widgets/list_view.c b/components/rtgui/widgets/list_view.c index bbac1e69e5bf2c2f59c70fc067658d35a063752e..a6d146b65740ef7e709daaeb3d83efc7742ebfc4 100644 --- a/components/rtgui/widgets/list_view.c +++ b/components/rtgui/widgets/list_view.c @@ -558,15 +558,25 @@ rt_bool_t rtgui_list_view_event_handler(struct rtgui_widget* widget, struct rtgu static void rtgui_list_view_calc(struct rtgui_list_view* view) { - /* get image of first item*/ - rtgui_image_t *image; rtgui_rect_t rect; + rt_uint32_t image_width, image_height; rt_ubase_t text_width, text_height; rt_ubase_t item_width, item_height; if (view->items_count == 0) return; - image = view->items[0].image; + /* get image width and height */ + if (view->items[0].image != RT_NULL) + { + image_width = view->items[0].image->w; + image_height = view->items[0].image->h; + } + else + { + image_width = 0; + image_height = 0; + } + rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(view)), "HHHHHH", &rect); text_height = rtgui_rect_height(rect); @@ -574,9 +584,9 @@ static void rtgui_list_view_calc(struct rtgui_list_view* view) rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); - item_width = (image->w + LIST_MARGIN); + item_width = (image_width + LIST_MARGIN); if (item_width < (text_width + LIST_MARGIN)) item_width = text_width + LIST_MARGIN; - item_height = image->h + 8 + text_height + LIST_MARGIN; + item_height = image_height + 8 + text_height + LIST_MARGIN; if (item_width > item_height) item_height = item_width; else item_width = item_height;