From cbefb0394f830490baa65707b52aa079cc96bc4c Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 25 Sep 2015 18:12:00 +0200 Subject: [PATCH] Refactor scroll indices code for menu_navigation_ctl --- menu/menu_displaylist.c | 18 ++++++++---------- menu/menu_navigation.c | 11 +++++++++-- menu/menu_navigation.h | 3 ++- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 154ab31bfe..e6d7151792 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -167,13 +167,13 @@ static void menu_list_build_scroll_indices(file_list_t *list) size_t i; int current; bool current_is_dir; - size_t scroll_indices = 0; - menu_navigation_t *nav = menu_navigation_get_ptr(); + size_t scroll_value = 0; - if (!nav || !list || !list->size) + if (!list || !list->size) return; - nav->scroll.indices.list[scroll_indices++] = 0; + menu_navigation_ctl(MENU_NAVIGATION_CTL_CLEAR_SCROLL_INDICES, NULL); + menu_navigation_ctl(MENU_NAVIGATION_CTL_ADD_SCROLL_INDEX, &scroll_value); current = menu_list_elem_get_first_char(list, 0); current_is_dir = menu_list_elem_is_dir(list, 0); @@ -184,14 +184,15 @@ static void menu_list_build_scroll_indices(file_list_t *list) bool is_dir = menu_list_elem_is_dir(list, i); if ((current_is_dir && !is_dir) || (first > current)) - nav->scroll.indices.list[scroll_indices++] = i; + menu_navigation_ctl(MENU_NAVIGATION_CTL_ADD_SCROLL_INDEX, &i); current = first; current_is_dir = is_dir; } - nav->scroll.indices.list[scroll_indices++] = list->size - 1; - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SCROLL_INDICES, &scroll_indices); + + scroll_value = list->size - 1; + menu_navigation_ctl(MENU_NAVIGATION_CTL_ADD_SCROLL_INDEX, &scroll_value); } /** @@ -204,15 +205,12 @@ static void menu_list_build_scroll_indices(file_list_t *list) static void menu_list_refresh(file_list_t *list) { size_t list_size, selection; - size_t scroll_indices = 0; menu_list_t *menu_list = menu_list_get_ptr(); if (!menu_list || !list) return; if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) return; - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SCROLL_INDICES, &scroll_indices); - menu_list_build_scroll_indices(list); list_size = menu_list_get_size(menu_list); diff --git a/menu/menu_navigation.c b/menu/menu_navigation.c index 744d0ddd27..3564643e01 100644 --- a/menu/menu_navigation.c +++ b/menu/menu_navigation.c @@ -182,12 +182,19 @@ bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data) nav->selection_ptr = *sel; } return true; - case MENU_NAVIGATION_CTL_SET_SCROLL_INDICES: + case MENU_NAVIGATION_CTL_CLEAR_SCROLL_INDICES: + { + if (!nav) + return false; + nav->scroll.indices.size = 0; + } + return true; + case MENU_NAVIGATION_CTL_ADD_SCROLL_INDEX: { size_t *sel = (size_t*)data; if (!nav || !sel) return false; - nav->scroll.indices.size = *sel; + nav->scroll.indices.list[nav->scroll.indices.size++] = *sel; } return true; } diff --git a/menu/menu_navigation.h b/menu/menu_navigation.h index 4dbe574d18..ec04b21f17 100644 --- a/menu/menu_navigation.h +++ b/menu/menu_navigation.h @@ -55,7 +55,8 @@ enum menu_navigation_ctl_state MENU_NAVIGATION_CTL_ASCEND_ALPHABET, MENU_NAVIGATION_CTL_SET_SELECTION, MENU_NAVIGATION_CTL_GET_SELECTION, - MENU_NAVIGATION_CTL_SET_SCROLL_INDICES + MENU_NAVIGATION_CTL_CLEAR_SCROLL_INDICES, + MENU_NAVIGATION_CTL_ADD_SCROLL_INDEX }; bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data);