Refactor menu_navigation_decrement

This commit is contained in:
twinaphex 2015-09-25 14:32:04 +02:00
parent a57595ad94
commit f0b76fa5b0
4 changed files with 43 additions and 39 deletions

View File

@ -30,7 +30,7 @@ static int action_bind_up_generic(unsigned type, const char *label)
if (menu_list_get_size(menu_list) <= 0)
return 0;
menu_navigation_decrement(nav, scroll_speed);
menu_navigation_ctl(MENU_NAVIGATION_CTL_DECREMENT, &scroll_speed);
return 0;
}

View File

@ -905,7 +905,10 @@ static int menu_input_mouse_frame(
menu_navigation_increment(nav, 1);
if (BIT64_GET(input_mouse, MOUSE_ACTION_WHEEL_UP))
menu_navigation_decrement(nav, 1);
{
unsigned decrement_by = 1;
menu_navigation_ctl(MENU_NAVIGATION_CTL_DECREMENT, &decrement_by);
}
return 0;
}

View File

@ -28,12 +28,17 @@
bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data)
{
const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr();
menu_navigation_t *nav = menu_navigation_get_ptr();
switch (state)
{
case MENU_NAVIGATION_CTL_CLEAR:
{
bool *pending_push = (bool*)data;
if (!pending_push)
return false;
if (driver->navigation_clear)
driver->navigation_clear(*pending_push);
}
@ -43,13 +48,38 @@ bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data)
driver->navigation_increment();
return true;
case MENU_NAVIGATION_CTL_DECREMENT:
{
menu_list_t *menu_list = menu_list_get_ptr();
settings_t *settings = config_get_ptr();
size_t selection = nav->selection_ptr;
unsigned *scroll_speed = (unsigned*)data;
if (!scroll_speed)
return false;
if (selection >= *scroll_speed)
menu_navigation_set(nav, selection - *scroll_speed, true);
else
{
if (settings->menu.navigation.wraparound.vertical_enable)
menu_navigation_set(nav,
menu_list_get_size(menu_list) - 1, true);
else
menu_navigation_set(nav, 0, true);
}
menu_navigation_ctl(MENU_NAVIGATION_CTL_DECREMENT, NULL);
if (driver->navigation_decrement)
driver->navigation_decrement();
}
return true;
case MENU_NAVIGATION_CTL_SET:
{
bool *scroll = (bool*)data;
if (!scroll)
return false;
if (driver->navigation_set)
driver->navigation_set(*scroll);
}
@ -62,6 +92,9 @@ bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data)
{
size_t *ptr_out = (size_t*)data;
if (!ptr_out)
return false;
if (driver->navigation_ascend_alphabet)
driver->navigation_ascend_alphabet(ptr_out);
}
@ -70,6 +103,9 @@ bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data)
{
size_t *ptr_out = (size_t*)data;
if (!ptr_out)
return false;
if (driver->navigation_descend_alphabet)
driver->navigation_descend_alphabet(ptr_out);
}
@ -94,34 +130,6 @@ void menu_navigation_clear(menu_navigation_t *nav, bool pending_push)
menu_navigation_ctl(MENU_NAVIGATION_CTL_CLEAR, &pending_push);
}
/**
* menu_navigation_decrement:
*
* Decrement the navigation pointer.
**/
void menu_navigation_decrement(menu_navigation_t *nav, unsigned scroll_speed)
{
menu_list_t *menu_list = menu_list_get_ptr();
settings_t *settings = config_get_ptr();
size_t selection = nav->selection_ptr;
if (!nav)
return;
if (selection >= scroll_speed)
menu_navigation_set(nav, selection - scroll_speed, true);
else
{
if (settings->menu.navigation.wraparound.vertical_enable)
menu_navigation_set(nav,
menu_list_get_size(menu_list) - 1, true);
else
menu_navigation_set(nav, 0, true);
}
menu_navigation_ctl(MENU_NAVIGATION_CTL_DECREMENT, NULL);
}
/**
* menu_navigation_increment:
*

View File

@ -63,13 +63,6 @@ enum menu_navigation_ctl_state
**/
void menu_navigation_clear(menu_navigation_t *nav, bool pending_push);
/**
* menu_navigation_decrement:
*
* Decrement the navigation pointer.
**/
void menu_navigation_decrement(menu_navigation_t *nav, unsigned scroll_speed);
/**
* menu_navigation_increment:
*