@@ -76,14 +76,57 @@ static void prv_menu_select_long_click_handler(ClickRecognizerRef recognizer,
7676 }
7777}
7878
79+ static inline uint16_t prv_menu_layer_get_num_sections (MenuLayer * menu_layer );
80+ static inline uint16_t prv_menu_layer_get_num_rows (MenuLayer * menu_layer , uint16_t section_index );
81+
82+ //! Handle the menu scroll wrap around
83+ //! @param menu_layer reference to the current MenuLayer
84+ //! @param recognizer reference to the ClickRecognizer struct
85+ //! @param scrolling_up `true` if scrolling up, `false` if scrolling down
86+ //! @return `true` if a wrap around has been applied
87+ static bool prv_menu_scroll_handle_wrap_around (MenuLayer * menu_layer , ClickRecognizerRef recognizer , bool scrolling_up ) {
88+ const uint8_t current_scroll_action = scrolling_up ? MenuLayerRepeatScrollingUp : MenuLayerRepeatScrollingDown ;
89+ const bool is_repeating = click_recognizer_is_repeating (recognizer );
90+
91+ if (is_repeating ) {
92+ menu_layer -> cache .button_repeat_scrolling = current_scroll_action ;
93+ return false;
94+ }
95+ menu_layer -> cache .button_repeat_scrolling = MenuLayerNoRepeatScrolling ;
96+
97+ MenuIndex current_index = menu_layer -> selection .index ;
98+ int last_index_section = prv_menu_layer_get_num_sections (menu_layer ) - 1 ;
99+ int last_index_row = prv_menu_layer_get_num_rows (menu_layer , last_index_section ) - 1 ;
100+ MenuIndex first_index = MenuIndex (0 , 0 );
101+ MenuIndex last_index = MenuIndex (last_index_section , last_index_row );
102+ MenuIndex * wraparound_dest_index ;
103+ if ((menu_index_compare (& current_index , & first_index ) == 0 ) && scrolling_up ) {
104+ wraparound_dest_index = & last_index ;
105+ } else if ((menu_index_compare (& current_index , & last_index ) == 0 ) && !scrolling_up ) {
106+ wraparound_dest_index = & first_index ;
107+ } else {
108+ return false;
109+ }
110+
111+ const bool animated = true;
112+ menu_layer_set_selected_index (menu_layer , * wraparound_dest_index , MenuRowAlignCenter , animated );
113+ return true;
114+ }
115+
79116void menu_up_click_handler (ClickRecognizerRef recognizer , MenuLayer * menu_layer ) {
80117 const bool up = true;
118+ if (menu_layer -> scroll_wrap_around && prv_menu_scroll_handle_wrap_around (menu_layer , recognizer , up )) {
119+ return ;
120+ }
81121 const bool animated = true;
82122 menu_layer_set_selected_next (menu_layer , up , MenuRowAlignCenter , animated );
83123}
84124
85125void menu_down_click_handler (ClickRecognizerRef recognizer , MenuLayer * menu_layer ) {
86126 const bool up = false;
127+ if (menu_layer -> scroll_wrap_around && prv_menu_scroll_handle_wrap_around (menu_layer , recognizer , up )) {
128+ return ;
129+ }
87130 const bool animated = true;
88131 menu_layer_set_selected_next (menu_layer , up , MenuRowAlignCenter , animated );
89132}
@@ -1293,3 +1336,14 @@ void menu_layer_set_center_focused(MenuLayer *menu_layer, bool center_focused) {
12931336 prv_set_center_focused (menu_layer , center_focused );
12941337 menu_layer_update_caches (menu_layer );
12951338}
1339+
1340+ bool menu_layer_get_scroll_wrap_around (MenuLayer * menu_layer ) {
1341+ return menu_layer -> scroll_wrap_around ;
1342+ }
1343+
1344+ void menu_layer_set_scroll_wrap_around (MenuLayer * menu_layer , bool scroll_wrap_around ) {
1345+ if (!menu_layer ) {
1346+ return ;
1347+ }
1348+ menu_layer -> scroll_wrap_around = scroll_wrap_around ;
1349+ }
0 commit comments