Menu refactors:

- Get rid of menu_driver_search_list_clear
- Get rid of contentlist_switch callback - was only ever one
function callback implementation
This commit is contained in:
twinaphex 2021-03-11 03:37:19 +01:00
parent f502cd9e16
commit 839a270a97
11 changed files with 50 additions and 120 deletions

View File

@ -1040,7 +1040,6 @@ ifeq ($(HAVE_MENU_COMMON), 1)
menu/cbs/menu_cbs_label.o \
menu/cbs/menu_cbs_sublabel.o \
menu/cbs/menu_cbs_title.o \
menu/cbs/menu_cbs_contentlist_switch.o \
menu/menu_displaylist.o
endif

View File

@ -1388,7 +1388,6 @@ MENU
#include "../menu/cbs/menu_cbs_get_value.c"
#include "../menu/cbs/menu_cbs_label.c"
#include "../menu/cbs/menu_cbs_sublabel.c"
#include "../menu/cbs/menu_cbs_contentlist_switch.c"
#include "../menu/menu_displaylist.c"
#ifdef HAVE_LIBRETRODB
#include "../menu/menu_explore.c"

View File

@ -1,56 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2017 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "../menu_driver.h"
#include "../menu_cbs.h"
#ifndef BIND_ACTION_CONTENT_LIST_SWITCH
#define BIND_ACTION_CONTENT_LIST_SWITCH(cbs, name) (cbs)->action_content_list_switch = (name)
#endif
static int deferred_push_content_list(void *data, void *userdata,
const char *path,
const char *label, unsigned type)
{
menu_displaylist_ctx_entry_t entry;
file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0);
/* Must clear any existing menu search terms
* when switching 'tabs', since doing so
* bypasses standard backwards navigation
* (i.e. 'cancel' actions would normally
* pop the search stack - this will not
* happen if we jump to a new list directly) */
menu_driver_search_clear();
menu_navigation_set_selection(0);
entry.list = (file_list_t*)data;
entry.stack = selection_buf;
if (!menu_displaylist_push(&entry))
return -1;
return 0;
}
int menu_cbs_init_bind_content_list_switch(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx)
{
if (!cbs)
return -1;
BIND_ACTION_CONTENT_LIST_SWITCH(cbs, deferred_push_content_list);
return -1;
}

View File

@ -232,20 +232,14 @@ static int action_left_goto_tab(void)
menu_ctx_list_t list_info;
file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0);
file_list_t *menu_stack = menu_entries_get_menu_stack_ptr(0);
size_t selection = menu_navigation_get_selection();
menu_file_list_cbs_t *cbs = selection_buf ? (menu_file_list_cbs_t*)
selection_buf->list[selection].actiondata : NULL;
list_info.type = MENU_LIST_HORIZONTAL;
list_info.action = MENU_ACTION_LEFT;
menu_driver_list_cache(&list_info);
if (cbs && cbs->action_content_list_switch)
return cbs->action_content_list_switch(selection_buf, menu_stack,
"", "", 0);
return 0;
return menu_driver_deferred_push_content_list(selection_buf, menu_stack,
"", "", 0);
}
static int action_left_mainmenu(unsigned type, const char *label,

View File

@ -257,20 +257,14 @@ static int action_right_goto_tab(void)
menu_ctx_list_t list_info;
file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0);
file_list_t *menu_stack = menu_entries_get_menu_stack_ptr(0);
size_t selection = menu_navigation_get_selection();
menu_file_list_cbs_t *cbs = selection_buf ? (menu_file_list_cbs_t*)
selection_buf->list[selection].actiondata : NULL;
list_info.type = MENU_LIST_HORIZONTAL;
list_info.action = MENU_ACTION_RIGHT;
menu_driver_list_cache(&list_info);
if (cbs && cbs->action_content_list_switch)
return cbs->action_content_list_switch(selection_buf, menu_stack,
"", "", 0);
return 0;
return menu_driver_deferred_push_content_list(selection_buf, menu_stack,
"", "", 0);
}
static int action_right_mainmenu(unsigned type, const char *label,

View File

@ -8477,24 +8477,18 @@ static int materialui_switch_tabs(
file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0);
file_list_t *menu_stack = menu_entries_get_menu_stack_ptr(0);
size_t selection = menu_navigation_get_selection();
menu_file_list_cbs_t *cbs = selection_buf ?
(menu_file_list_cbs_t*)file_list_get_actiondata_at_offset(
selection_buf, selection) : NULL;
bool stack_flushed = false;
int ret = 0;
/* Sanity check */
if (!selection_buf || !menu_stack || !cbs)
return -1;
if (!cbs->action_content_list_switch)
if (!selection_buf || !menu_stack)
return -1;
/* Perform pre-switch operations */
stack_flushed = materialui_preswitch_tabs(mui, target_tab);
/* Perform switch */
ret = cbs->action_content_list_switch(
ret = menu_driver_deferred_push_content_list(
selection_buf, menu_stack, "", "", 0);
/* Note: If materialui_preswitch_tabs() flushes

View File

@ -750,15 +750,10 @@ void ozone_change_tab(ozone_handle_t *ozone,
enum msg_hash_enums tab,
enum menu_settings_type type)
{
file_list_t *menu_stack = menu_entries_get_menu_stack_ptr(0);
size_t stack_size;
file_list_t *menu_stack = menu_entries_get_menu_stack_ptr(0);
file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0);
size_t selection = menu_navigation_get_selection();
menu_file_list_cbs_t *cbs = selection_buf ?
(menu_file_list_cbs_t*)file_list_get_actiondata_at_offset(selection_buf,
selection) : NULL;
stack_size = menu_stack->size;
size_t selection = menu_navigation_get_selection();
size_t stack_size = menu_stack->size;
if (menu_stack->list[stack_size - 1].label)
free(menu_stack->list[stack_size - 1].label);
@ -772,8 +767,7 @@ void ozone_change_tab(ozone_handle_t *ozone,
ozone_list_cache(ozone, MENU_LIST_HORIZONTAL,
MENU_ACTION_LEFT);
if (cbs && cbs->action_content_list_switch)
cbs->action_content_list_switch(selection_buf, menu_stack, "", "", 0);
menu_driver_deferred_push_content_list(selection_buf, menu_stack, "", "", 0);
}
void ozone_init_horizontal_list(ozone_handle_t *ozone)

View File

@ -278,9 +278,6 @@ int menu_cbs_init_bind_info(menu_file_list_cbs_t *cbs,
int menu_cbs_init_bind_start(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx);
int menu_cbs_init_bind_content_list_switch(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx);
int menu_cbs_init_bind_cancel(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx);

View File

@ -477,6 +477,11 @@ void menu_driver_frame(bool menu_is_alive, video_frame_info_t *video_info);
bool menu_driver_iterate(menu_ctx_iterate_t *iterate,
retro_time_t current_time);
int menu_driver_deferred_push_content_list(
void *data, void *userdata,
const char *path,
const char *label, unsigned type);
bool menu_driver_list_cache(menu_ctx_list_t *list);
void menu_driver_navigation_set(bool scroll);
@ -537,7 +542,6 @@ void menu_explore_free(void);
bool menu_driver_search_filter_enabled(const char *label, unsigned type);
bool menu_driver_search_push(const char *search_term);
bool menu_driver_search_pop(void);
void menu_driver_search_clear(void);
struct string_list *menu_driver_search_get_terms(void);
/* Convenience function: Appends list of current
* search terms to specified string */

View File

@ -108,8 +108,6 @@ typedef struct menu_file_list_cbs
int (*action_start)(const char *path, const char *label, unsigned type,
size_t idx, size_t entry_idx);
int (*action_info)(unsigned type, const char *label);
int (*action_content_list_switch)(void *data, void *userdata, const char
*path, const char *label, unsigned type);
int (*action_left)(unsigned type, const char *label, bool wraparound);
int (*action_right)(unsigned type, const char *label, bool wraparound);
int (*action_label)(file_list_t *list,

View File

@ -1652,10 +1652,6 @@ static void menu_cbs_init(
* menu_cbs_info.c, then map this callback to the entry. */
menu_cbs_init_bind_info(cbs, path, label, type, idx);
/* It will try to find a corresponding callback function inside
* menu_cbs_bind_content_list_switch.c, then map this callback to the entry. */
menu_cbs_init_bind_content_list_switch(cbs, path, label, type, idx);
/* It will try to find a corresponding callback function inside
* menu_cbs_left.c, then map this callback to the entry. */
menu_cbs_init_bind_left(cbs, path, label, type, idx, menu_label);
@ -3002,7 +2998,6 @@ void menu_entries_append(
cbs->action_scan = NULL;
cbs->action_start = NULL;
cbs->action_info = NULL;
cbs->action_content_list_switch = NULL;
cbs->action_left = NULL;
cbs->action_right = NULL;
cbs->action_label = NULL;
@ -3087,7 +3082,6 @@ bool menu_entries_append_enum(
cbs->action_scan = NULL;
cbs->action_start = NULL;
cbs->action_info = NULL;
cbs->action_content_list_switch = NULL;
cbs->action_left = NULL;
cbs->action_right = NULL;
cbs->action_label = NULL;
@ -3172,7 +3166,6 @@ void menu_entries_prepend(file_list_t *list,
cbs->action_scan = NULL;
cbs->action_start = NULL;
cbs->action_info = NULL;
cbs->action_content_list_switch = NULL;
cbs->action_left = NULL;
cbs->action_right = NULL;
cbs->action_label = NULL;
@ -4104,6 +4097,37 @@ bool menu_driver_iterate(menu_ctx_iterate_t *iterate,
return false;
}
int menu_driver_deferred_push_content_list(
void *data, void *userdata,
const char *path,
const char *label, unsigned type)
{
menu_displaylist_ctx_entry_t entry;
struct rarch_state *p_rarch = &rarch_st;
struct menu_state *menu_st = &p_rarch->menu_driver_state;
menu_handle_t *menu_data = p_rarch->menu_driver_data;
menu_list_t *menu_list = menu_st->entries.list;
file_list_t *selection_buf = MENU_LIST_GET_SELECTION(menu_list, (unsigned)0);
/* Must clear any existing menu search terms
* when switching 'tabs', since doing so
* bypasses standard backwards navigation
* (i.e. 'cancel' actions would normally
* pop the search stack - this will not
* happen if we jump to a new list directly) */
if (menu_data->search_terms)
string_list_free(menu_data->search_terms);
menu_data->search_terms = NULL;
menu_st->selection_ptr = 0;
entry.list = (file_list_t*)data;
entry.stack = selection_buf;
if (!menu_displaylist_push(&entry))
return -1;
return 0;
}
bool menu_driver_list_cache(menu_ctx_list_t *list)
{
struct rarch_state *p_rarch = &rarch_st;
@ -4491,20 +4515,6 @@ free_list:
return true;
}
void menu_driver_search_clear(void)
{
struct rarch_state *p_rarch = &rarch_st;
menu_handle_t *menu = p_rarch->menu_driver_data;
if (!menu)
return;
if (menu->search_terms)
string_list_free(menu->search_terms);
menu->search_terms = NULL;
}
struct string_list *menu_driver_search_get_terms(void)
{
struct rarch_state *p_rarch = &rarch_st;
@ -4844,6 +4854,7 @@ bool menu_driver_ctl(enum rarch_menu_ctl_state state, void *data)
{
struct rarch_state *p_rarch = &rarch_st;
gfx_display_t *p_disp = &p_rarch->dispgfx;
menu_handle_t *menu_data = p_rarch->menu_driver_data;
struct menu_state *menu_st = &p_rarch->menu_driver_state;
switch (state)
@ -4956,7 +4967,9 @@ bool menu_driver_ctl(enum rarch_menu_ctl_state state, void *data)
free(p_rarch->menu_driver_data->core_buf);
p_rarch->menu_driver_data->core_buf = NULL;
menu_driver_search_clear();
if (menu_data->search_terms)
string_list_free(menu_data->search_terms);
menu_data->search_terms = NULL;
menu_st->entries_need_refresh = false;
menu_st->entries_nonblocking_refresh = false;