summaryrefslogtreecommitdiff
path: root/apps/gui/list.c
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2022-09-19 13:12:14 +0100
committerAidan MacDonald <amachronic@protonmail.com>2022-10-05 11:23:01 -0400
commit1c5a0497cf7735009b26dd0da82ea2820a2486a2 (patch)
treea37bf2866ee459d1d02381ea5ae3cda217e2fa6a /apps/gui/list.c
parentd5a081cbd1b871baf4e5d2c276fbabbc30c7994b (diff)
downloadrockbox-1c5a0497cf7735009b26dd0da82ea2820a2486a2.tar.gz
rockbox-1c5a0497cf7735009b26dd0da82ea2820a2486a2.zip
gui: Remove list "limit_scroll" member
Get rid of the "limit_scroll" member from lists and make it a local variable of gui_synclist_do_button(). Bump plugin API version since struct gui_synclist was changed. Change-Id: Ie3244a85e5a1022a2f6e238a506fdbba67724962
Diffstat (limited to 'apps/gui/list.c')
-rw-r--r--apps/gui/list.c62
1 files changed, 33 insertions, 29 deletions
diff --git a/apps/gui/list.c b/apps/gui/list.c
index 85404b7f0c..bb5d1a922e 100644
--- a/apps/gui/list.c
+++ b/apps/gui/list.c
@@ -47,8 +47,6 @@
47 */ 47 */
48#define FRAMEDROP_TRIGGER 6 48#define FRAMEDROP_TRIGGER 6
49 49
50static void gui_list_select_at_offset(struct gui_synclist * gui_list,
51 int offset);
52void list_draw(struct screen *display, struct gui_synclist *list); 50void list_draw(struct screen *display, struct gui_synclist *list);
53 51
54static long last_dirty_tick; 52static long last_dirty_tick;
@@ -178,7 +176,6 @@ void gui_synclist_init(struct gui_synclist * gui_list,
178 list_init_viewports(gui_list); 176 list_init_viewports(gui_list);
179 FOR_NB_SCREENS(i) 177 FOR_NB_SCREENS(i)
180 list_init_item_height(gui_list, i); 178 list_init_item_height(gui_list, i);
181 gui_list->limit_scroll = false;
182 gui_list->data = data; 179 gui_list->data = data;
183 gui_list->scroll_all = scroll_all; 180 gui_list->scroll_all = scroll_all;
184 gui_list->selected_size = selected_size; 181 gui_list->selected_size = selected_size;
@@ -382,7 +379,7 @@ void gui_synclist_select_item(struct gui_synclist * gui_list, int item_number)
382} 379}
383 380
384static void gui_list_select_at_offset(struct gui_synclist * gui_list, 381static void gui_list_select_at_offset(struct gui_synclist * gui_list,
385 int offset) 382 int offset, bool allow_wrap)
386{ 383{
387 int new_selection; 384 int new_selection;
388 if (gui_list->selected_size > 1) 385 if (gui_list->selected_size > 1)
@@ -394,15 +391,13 @@ static void gui_list_select_at_offset(struct gui_synclist * gui_list,
394 391
395 if (new_selection >= gui_list->nb_items) 392 if (new_selection >= gui_list->nb_items)
396 { 393 {
397 new_selection = gui_list->limit_scroll ? 394 new_selection = allow_wrap ? 0 : gui_list->nb_items - gui_list->selected_size;
398 gui_list->nb_items - gui_list->selected_size : 0; 395 edge_beep(gui_list, allow_wrap);
399 edge_beep(gui_list, !gui_list->limit_scroll);
400 } 396 }
401 else if (new_selection < 0) 397 else if (new_selection < 0)
402 { 398 {
403 new_selection = gui_list->limit_scroll ? 399 new_selection = allow_wrap ? gui_list->nb_items - gui_list->selected_size : 0;
404 0 : gui_list->nb_items - gui_list->selected_size; 400 edge_beep(gui_list, allow_wrap);
405 edge_beep(gui_list, !gui_list->limit_scroll);
406 } 401 }
407 402
408 gui_synclist_select_item(gui_list, new_selection); 403 gui_synclist_select_item(gui_list, new_selection);
@@ -508,21 +503,25 @@ void gui_synclist_set_sel_color(struct gui_synclist * lists,
508#endif 503#endif
509 504
510static void gui_synclist_select_next_page(struct gui_synclist * lists, 505static void gui_synclist_select_next_page(struct gui_synclist * lists,
511 enum screen_type screen) 506 enum screen_type screen,
507 bool allow_wrap)
512{ 508{
513 int nb_lines = list_get_nb_lines(lists, screen); 509 int nb_lines = list_get_nb_lines(lists, screen);
514 if (lists->selected_size > 1) 510 if (lists->selected_size > 1)
515 nb_lines = MAX(1, nb_lines/lists->selected_size); 511 nb_lines = MAX(1, nb_lines/lists->selected_size);
516 gui_list_select_at_offset(lists, nb_lines); 512
513 gui_list_select_at_offset(lists, nb_lines, allow_wrap);
517} 514}
518 515
519static void gui_synclist_select_previous_page(struct gui_synclist * lists, 516static void gui_synclist_select_previous_page(struct gui_synclist * lists,
520 enum screen_type screen) 517 enum screen_type screen,
518 bool allow_wrap)
521{ 519{
522 int nb_lines = list_get_nb_lines(lists, screen); 520 int nb_lines = list_get_nb_lines(lists, screen);
523 if (lists->selected_size > 1) 521 if (lists->selected_size > 1)
524 nb_lines = MAX(1, nb_lines/lists->selected_size); 522 nb_lines = MAX(1, nb_lines/lists->selected_size);
525 gui_list_select_at_offset(lists, -nb_lines); 523
524 gui_list_select_at_offset(lists, -nb_lines, allow_wrap);
526} 525}
527 526
528/* 527/*
@@ -561,16 +560,22 @@ bool gui_synclist_keyclick_callback(int action, void* data)
561{ 560{
562 struct gui_synclist *lists = (struct gui_synclist *)data; 561 struct gui_synclist *lists = (struct gui_synclist *)data;
563 562
564 /* block the beep if we are at the end of the list and we are not wrapping. 563 /* Block the beep if we're at the end of the list and we're not wrapping. */
565 * CAVEAT: mosts lists don't set limit_scroll untill it sees a repeat
566 * press at the end of the list so this can cause an extra beep.
567 */
568 if (lists->limit_scroll == false)
569 return true;
570 if (lists->selected_item == 0) 564 if (lists->selected_item == 0)
571 return (action != ACTION_STD_PREV && action != ACTION_STD_PREVREPEAT); 565 {
566 if (action == ACTION_STD_PREVREPEAT)
567 return false;
568 if (action == ACTION_STD_PREV && !lists->wraparound)
569 return false;
570 }
571
572 if (lists->selected_item == lists->nb_items - lists->selected_size) 572 if (lists->selected_item == lists->nb_items - lists->selected_size)
573 return (action != ACTION_STD_NEXT && action != ACTION_STD_NEXTREPEAT); 573 {
574 if (action == ACTION_STD_NEXTREPEAT)
575 return false;
576 if (action == ACTION_STD_NEXT && !lists->wraparound)
577 return false;
578 }
574 579
575 return action != ACTION_NONE; 580 return action != ACTION_NONE;
576} 581}
@@ -643,13 +648,12 @@ bool gui_synclist_do_button(struct gui_synclist * lists, int *actionptr)
643 current_lists = NULL; 648 current_lists = NULL;
644 649
645 /* Prevent list wraparound by repeating actions */ 650 /* Prevent list wraparound by repeating actions */
651 bool allow_wrap = lists->wraparound;
646 if (action == ACTION_STD_PREVREPEAT || 652 if (action == ACTION_STD_PREVREPEAT ||
647 action == ACTION_STD_NEXTREPEAT || 653 action == ACTION_STD_NEXTREPEAT ||
648 action == ACTION_LISTTREE_PGUP || 654 action == ACTION_LISTTREE_PGUP ||
649 action == ACTION_LISTTREE_PGDOWN) 655 action == ACTION_LISTTREE_PGDOWN)
650 lists->limit_scroll = true; 656 allow_wrap = false;
651 else
652 lists->limit_scroll = !lists->wraparound;
653 657
654 switch (action) 658 switch (action)
655 { 659 {
@@ -669,7 +673,7 @@ bool gui_synclist_do_button(struct gui_synclist * lists, int *actionptr)
669#endif 673#endif
670 case ACTION_STD_PREV: 674 case ACTION_STD_PREV:
671 case ACTION_STD_PREVREPEAT: 675 case ACTION_STD_PREVREPEAT:
672 gui_list_select_at_offset(lists, -next_item_modifier); 676 gui_list_select_at_offset(lists, -next_item_modifier, allow_wrap);
673#ifndef HAVE_WHEEL_ACCELERATION 677#ifndef HAVE_WHEEL_ACCELERATION
674 if (button_queue_count() < FRAMEDROP_TRIGGER) 678 if (button_queue_count() < FRAMEDROP_TRIGGER)
675#endif 679#endif
@@ -680,7 +684,7 @@ bool gui_synclist_do_button(struct gui_synclist * lists, int *actionptr)
680 684
681 case ACTION_STD_NEXT: 685 case ACTION_STD_NEXT:
682 case ACTION_STD_NEXTREPEAT: 686 case ACTION_STD_NEXTREPEAT:
683 gui_list_select_at_offset(lists, next_item_modifier); 687 gui_list_select_at_offset(lists, next_item_modifier, allow_wrap);
684#ifndef HAVE_WHEEL_ACCELERATION 688#ifndef HAVE_WHEEL_ACCELERATION
685 if (button_queue_count() < FRAMEDROP_TRIGGER) 689 if (button_queue_count() < FRAMEDROP_TRIGGER)
686#endif 690#endif
@@ -731,7 +735,7 @@ bool gui_synclist_do_button(struct gui_synclist * lists, int *actionptr)
731 SCREEN_REMOTE : 735 SCREEN_REMOTE :
732#endif 736#endif
733 SCREEN_MAIN; 737 SCREEN_MAIN;
734 gui_synclist_select_previous_page(lists, screen); 738 gui_synclist_select_previous_page(lists, screen, allow_wrap);
735 gui_synclist_draw(lists); 739 gui_synclist_draw(lists);
736 yield(); 740 yield();
737 *actionptr = ACTION_STD_NEXT; 741 *actionptr = ACTION_STD_NEXT;
@@ -746,7 +750,7 @@ bool gui_synclist_do_button(struct gui_synclist * lists, int *actionptr)
746 SCREEN_REMOTE : 750 SCREEN_REMOTE :
747#endif 751#endif
748 SCREEN_MAIN; 752 SCREEN_MAIN;
749 gui_synclist_select_next_page(lists, screen); 753 gui_synclist_select_next_page(lists, screen, allow_wrap);
750 gui_synclist_draw(lists); 754 gui_synclist_draw(lists);
751 yield(); 755 yield();
752 *actionptr = ACTION_STD_PREV; 756 *actionptr = ACTION_STD_PREV;