Merge pull request #14367 from sonninnos/menu-paging

Menu paging navigation adjustments
This commit is contained in:
LibretroAdmin 2022-08-31 22:47:26 +02:00 committed by GitHub
commit 67afa426e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 106 additions and 32 deletions

View File

@ -235,7 +235,7 @@ static int action_left_scroll(unsigned type, const char *label,
return false; return false;
scroll_speed = (unsigned)((MAX(scroll_accel, 2) - 2) / 4 + 1); scroll_speed = (unsigned)((MAX(scroll_accel, 2) - 2) / 4 + 1);
fast_scroll_speed = 4 + 4 * scroll_speed; fast_scroll_speed = 10 * scroll_speed;
if (selection > fast_scroll_speed) if (selection > fast_scroll_speed)
{ {

View File

@ -246,8 +246,8 @@ static int action_right_scroll(unsigned type, const char *label,
if (!menu_driver_ctl(MENU_NAVIGATION_CTL_GET_SCROLL_ACCEL, &scroll_accel)) if (!menu_driver_ctl(MENU_NAVIGATION_CTL_GET_SCROLL_ACCEL, &scroll_accel))
return false; return false;
scroll_speed = (unsigned)((MAX(scroll_accel, 2) - 2) / 4 + 1); scroll_speed = (unsigned)((MAX(scroll_accel, 2) - 2) / 4 + 1);
fast_scroll_speed = 4 + 4 * scroll_speed; fast_scroll_speed = 10 * scroll_speed;
if (selection + fast_scroll_speed < (menu_entries_get_size())) if (selection + fast_scroll_speed < (menu_entries_get_size()))
{ {

View File

@ -237,6 +237,12 @@ struct key_desc key_descriptors[RARCH_MAX_KEYS] =
{RETROK_OEM_102, "OEM-102"} {RETROK_OEM_102, "OEM-102"}
}; };
enum menu_scroll_mode
{
MENU_SCROLL_PAGE = 0,
MENU_SCROLL_START_LETTER
};
static void *null_menu_init(void **userdata, bool video_is_threaded) static void *null_menu_init(void **userdata, bool video_is_threaded)
{ {
menu_handle_t *menu = (menu_handle_t*)calloc(1, sizeof(*menu)); menu_handle_t *menu = (menu_handle_t*)calloc(1, sizeof(*menu));
@ -5938,9 +5944,25 @@ unsigned menu_event(
} }
if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_L)) if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_L))
{
menu_st->scroll.mode = MENU_SCROLL_PAGE;
ret = MENU_ACTION_SCROLL_UP; ret = MENU_ACTION_SCROLL_UP;
}
else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_R)) else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_R))
{
menu_st->scroll.mode = MENU_SCROLL_PAGE;
ret = MENU_ACTION_SCROLL_DOWN; ret = MENU_ACTION_SCROLL_DOWN;
}
else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_L2))
{
menu_st->scroll.mode = MENU_SCROLL_START_LETTER;
ret = MENU_ACTION_SCROLL_UP;
}
else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_R2))
{
menu_st->scroll.mode = MENU_SCROLL_START_LETTER;
ret = MENU_ACTION_SCROLL_DOWN;
}
else if (ok_trigger) else if (ok_trigger)
ret = MENU_ACTION_OK; ret = MENU_ACTION_OK;
else if (BIT256_GET_PTR(p_trigger_input, menu_cancel_btn)) else if (BIT256_GET_PTR(p_trigger_input, menu_cancel_btn))
@ -6361,7 +6383,7 @@ static int menu_input_pointer_post_iterate(
{ {
/* Pointer has moved - check if this is a swipe */ /* Pointer has moved - check if this is a swipe */
float dpi = menu ? menu_input_get_dpi(menu, p_disp, float dpi = menu ? menu_input_get_dpi(menu, p_disp,
video_st->width, video_st->height) : 0.0f; video_st->width, video_st->height) : 0.0f;
if ((dpi > 0.0f) if ((dpi > 0.0f)
&& &&
@ -7705,6 +7727,7 @@ int generic_menu_entry_action(
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
void *menu_userdata = menu_st->userdata; void *menu_userdata = menu_st->userdata;
bool wraparound_enable = settings->bools.menu_navigation_wraparound_enable; bool wraparound_enable = settings->bools.menu_navigation_wraparound_enable;
bool scroll_mode = menu_st->scroll.mode;
size_t scroll_accel = menu_st->scroll.acceleration; size_t scroll_accel = menu_st->scroll.acceleration;
menu_list_t *menu_list = menu_st->entries.list; menu_list_t *menu_list = menu_st->entries.list;
file_list_t *selection_buf = menu_list ? MENU_LIST_GET_SELECTION(menu_list, (unsigned)0) : NULL; file_list_t *selection_buf = menu_list ? MENU_LIST_GET_SELECTION(menu_list, (unsigned)0) : NULL;
@ -7775,46 +7798,96 @@ int generic_menu_entry_action(
} }
break; break;
case MENU_ACTION_SCROLL_UP: case MENU_ACTION_SCROLL_UP:
if ( if (scroll_mode == MENU_SCROLL_PAGE)
menu_st->scroll.index_size
&& menu_st->selection_ptr != 0
)
{ {
size_t l = menu_st->scroll.index_size - 1; if (selection_buf_size > 0)
{
unsigned scroll_speed = (unsigned)((MAX(scroll_accel, 2) - 2) / 4 + 10);
if (!(menu_st->selection_ptr == 0 && !wraparound_enable))
{
size_t idx = 0;
if (menu_st->selection_ptr >= scroll_speed)
idx = menu_st->selection_ptr - scroll_speed;
else
idx = 0;
while (l menu_st->selection_ptr = idx;
&& menu_st->scroll.index_list[l - 1] menu_driver_navigation_set(true);
>= menu_st->selection_ptr)
l--;
if (l > 0) if (menu_driver_ctx->navigation_decrement)
menu_st->selection_ptr = menu_st->scroll.index_list[l - 1]; menu_driver_ctx->navigation_decrement(menu_userdata);
}
}
}
else /* MENU_SCROLL_START_LETTER */
{
if (
menu_st->scroll.index_size
&& menu_st->selection_ptr != 0
)
{
size_t l = menu_st->scroll.index_size - 1;
if (menu_driver_ctx->navigation_descend_alphabet) while (l
menu_driver_ctx->navigation_descend_alphabet( && menu_st->scroll.index_list[l - 1]
menu_userdata, &menu_st->selection_ptr); >= menu_st->selection_ptr)
l--;
if (l > 0)
menu_st->selection_ptr = menu_st->scroll.index_list[l - 1];
if (menu_driver_ctx->navigation_descend_alphabet)
menu_driver_ctx->navigation_descend_alphabet(
menu_userdata, &menu_st->selection_ptr);
}
} }
break; break;
case MENU_ACTION_SCROLL_DOWN: case MENU_ACTION_SCROLL_DOWN:
if (menu_st->scroll.index_size) if (scroll_mode == MENU_SCROLL_PAGE)
{ {
if (menu_st->selection_ptr == menu_st->scroll.index_list[menu_st->scroll.index_size - 1]) if (selection_buf_size > 0)
menu_st->selection_ptr = selection_buf_size - 1;
else
{ {
size_t l = 0; unsigned scroll_speed = (unsigned)((MAX(scroll_accel, 2) - 2) / 4 + 10);
while (l < menu_st->scroll.index_size - 1 if (!(menu_st->selection_ptr >= selection_buf_size - 1
&& menu_st->scroll.index_list[l + 1] <= menu_st->selection_ptr) && !wraparound_enable))
l++; {
menu_st->selection_ptr = menu_st->scroll.index_list[l + 1]; if ((menu_st->selection_ptr + scroll_speed) < selection_buf_size)
{
size_t idx = menu_st->selection_ptr + scroll_speed;
if (menu_st->selection_ptr >= selection_buf_size) menu_st->selection_ptr = idx;
menu_st->selection_ptr = selection_buf_size - 1; menu_driver_navigation_set(true);
}
else
menu_driver_ctl(MENU_NAVIGATION_CTL_SET_LAST, NULL);
if (menu_driver_ctx->navigation_increment)
menu_driver_ctx->navigation_increment(menu_userdata);
}
} }
}
else /* MENU_SCROLL_START_LETTER */
{
if (menu_st->scroll.index_size)
{
if (menu_st->selection_ptr == menu_st->scroll.index_list[menu_st->scroll.index_size - 1])
menu_st->selection_ptr = selection_buf_size - 1;
else
{
size_t l = 0;
while (l < menu_st->scroll.index_size - 1
&& menu_st->scroll.index_list[l + 1] <= menu_st->selection_ptr)
l++;
menu_st->selection_ptr = menu_st->scroll.index_list[l + 1];
if (menu_driver_ctx->navigation_ascend_alphabet) if (menu_st->selection_ptr >= selection_buf_size)
menu_driver_ctx->navigation_ascend_alphabet( menu_st->selection_ptr = selection_buf_size - 1;
menu_userdata, &menu_st->selection_ptr); }
if (menu_driver_ctx->navigation_ascend_alphabet)
menu_driver_ctx->navigation_ascend_alphabet(
menu_userdata, &menu_st->selection_ptr);
}
} }
break; break;
case MENU_ACTION_CANCEL: case MENU_ACTION_CANCEL:

View File

@ -488,6 +488,7 @@ struct menu_state
size_t index_list[SCROLL_INDEX_SIZE]; size_t index_list[SCROLL_INDEX_SIZE];
unsigned index_size; unsigned index_size;
unsigned acceleration; unsigned acceleration;
bool mode;
} scroll; } scroll;
/* unsigned alignment */ /* unsigned alignment */