From f13dc6c014992298254692d689579fd523867b0e Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 25 Sep 2015 18:04:25 +0200 Subject: [PATCH] Go through menu_navigation_ctl for ascend/descend alphabet --- menu/menu_entry.c | 5 ++- menu/menu_navigation.c | 73 ++++++++++-------------------------------- menu/menu_navigation.h | 24 -------------- 3 files changed, 19 insertions(+), 83 deletions(-) diff --git a/menu/menu_entry.c b/menu/menu_entry.c index 63fc5b0693..b84983e835 100644 --- a/menu/menu_entry.c +++ b/menu/menu_entry.c @@ -369,12 +369,11 @@ int menu_entry_action(menu_entry_t *entry, unsigned i, enum menu_action action) ret = cbs->action_down(entry->type, entry->label); break; case MENU_ACTION_SCROLL_UP: - menu_navigation_descend_alphabet(nav, &nav->selection_ptr); + menu_navigation_ctl(MENU_NAVIGATION_CTL_DESCEND_ALPHABET, &nav->selection_ptr); break; case MENU_ACTION_SCROLL_DOWN: - menu_navigation_ascend_alphabet(nav, &nav->selection_ptr); + menu_navigation_ctl(MENU_NAVIGATION_CTL_ASCEND_ALPHABET, &nav->selection_ptr); break; - case MENU_ACTION_CANCEL: if (cbs && cbs->action_cancel) ret = cbs->action_cancel(entry->path, entry->label, entry->type, i); diff --git a/menu/menu_navigation.c b/menu/menu_navigation.c index 9458aa65a9..744d0ddd27 100644 --- a/menu/menu_navigation.c +++ b/menu/menu_navigation.c @@ -133,9 +133,16 @@ bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data) case MENU_NAVIGATION_CTL_ASCEND_ALPHABET: { size_t *ptr_out = (size_t*)data; - - if (!ptr_out) + size_t i = 0, ptr = *ptr_out; + if (!nav || !nav->scroll.indices.size || !ptr_out) return false; + if (ptr == nav->scroll.indices.list[nav->scroll.indices.size - 1]) + return false; + + while (i < nav->scroll.indices.size - 1 + && nav->scroll.indices.list[i + 1] <= ptr) + i++; + *ptr_out = nav->scroll.indices.list[i + 1]; if (driver->navigation_ascend_alphabet) driver->navigation_ascend_alphabet(ptr_out); @@ -144,10 +151,17 @@ bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data) case MENU_NAVIGATION_CTL_DESCEND_ALPHABET: { size_t *ptr_out = (size_t*)data; + size_t i, ptr = *ptr_out; - if (!ptr_out) + if (!nav || !nav->scroll.indices.size || ptr == 0 || !ptr_out) return false; + i = nav->scroll.indices.size - 1; + + while (i && nav->scroll.indices.list[i - 1] >= ptr) + i--; + *ptr_out = nav->scroll.indices.list[i - 1]; + if (driver->navigation_descend_alphabet) driver->navigation_descend_alphabet(ptr_out); } @@ -180,56 +194,3 @@ bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data) return false; } - -/** - * menu_navigation_descend_alphabet: - * @ptr_out : Amount of indices to 'scroll' to get - * to the next entry. - * - * Descends alphabet. - * E.g.: - * If navigation points to an entry called 'Beta', - * navigation pointer will be set to an entry called 'Alpha'. - **/ -void menu_navigation_descend_alphabet(menu_navigation_t *nav, size_t *ptr_out) -{ - size_t i, ptr = *ptr_out; - - if (!nav || !nav->scroll.indices.size || ptr == 0) - return; - - i = nav->scroll.indices.size - 1; - - while (i && nav->scroll.indices.list[i - 1] >= ptr) - i--; - *ptr_out = nav->scroll.indices.list[i - 1]; - - menu_navigation_ctl(MENU_NAVIGATION_CTL_DESCEND_ALPHABET, ptr_out); -} - -/** - * menu_navigation_ascends_alphabet: - * @ptr_out : Amount of indices to 'scroll' to get - * to the next entry. - * - * Ascends alphabet. - * E.g.: - * If navigation points to an entry called 'Alpha', - * navigation pointer will be set to an entry called 'Beta'. - **/ -void menu_navigation_ascend_alphabet(menu_navigation_t *nav, size_t *ptr_out) -{ - size_t i = 0, ptr = *ptr_out; - if (!nav || !nav->scroll.indices.size) - return; - - if (ptr == nav->scroll.indices.list[nav->scroll.indices.size - 1]) - return; - - while (i < nav->scroll.indices.size - 1 - && nav->scroll.indices.list[i + 1] <= ptr) - i++; - *ptr_out = nav->scroll.indices.list[i + 1]; - - menu_navigation_ctl(MENU_NAVIGATION_CTL_ASCEND_ALPHABET, ptr_out); -} diff --git a/menu/menu_navigation.h b/menu/menu_navigation.h index bac8eb4cfd..4dbe574d18 100644 --- a/menu/menu_navigation.h +++ b/menu/menu_navigation.h @@ -58,30 +58,6 @@ enum menu_navigation_ctl_state MENU_NAVIGATION_CTL_SET_SCROLL_INDICES }; -/** - * menu_navigation_descend_alphabet: - * @ptr_out : Amount of indices to 'scroll' to get - * to the next entry. - * - * Descends alphabet. - * E.g.: - * If navigation points to an entry called 'Beta', - * navigation pointer will be set to an entry called 'Alpha'. - **/ -void menu_navigation_descend_alphabet(menu_navigation_t *nav, size_t *ptr_out); - -/** - * menu_navigation_ascends_alphabet: - * @ptr_out : Amount of indices to 'scroll' to get - * to the next entry. - * - * Ascends alphabet. - * E.g.: - * If navigation points to an entry called 'Alpha', - * navigation pointer will be set to an entry called 'Beta'. - **/ -void menu_navigation_ascend_alphabet(menu_navigation_t *nav, size_t *ptr_out); - bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data); #ifdef __cplusplus