Navigation in menubar: wrap around when using arrow past end or start of menubar.

Fix some border cases.
This commit is contained in:
ManoloFLTK 2024-06-25 13:23:49 +02:00
parent f44c163234
commit fe4c94b4dc

View File

@ -699,13 +699,14 @@ static int forward(int menu) { // go to next item in menu menu if possible
menu = 0;
menuwindow &m = *(pp.p[menu]);
int item = (menu == pp.menu_number) ? pp.item_number : m.selected;
while (m.numitems >= 2) {
do {
while (++item < m.numitems) {
const Fl_Menu_Item* m1 = m.menu->next(item);
if (m1->activevisible()) {setitem(m1, menu, item); return 1;}
}
item = -1;
}
while (pp.menubar && pp.menu_number <= 0 && (!m.menu || m.menu->submenu()));
return 0;
}
@ -716,13 +717,14 @@ static int backward(int menu) { // previous item in menu menu if possible
menustate &pp = *p;
menuwindow &m = *(pp.p[menu]);
int item = (menu == pp.menu_number) ? pp.item_number : m.selected;
while (m.numitems >= 2) {
do {
while (--item >= 0) {
const Fl_Menu_Item* m1 = m.menu->next(item);
if (m1->activevisible()) {setitem(m1, menu, item); return 1;}
}
item = m.numitems;
}
while (pp.menubar && (!m.menu || m.menu->submenu()));
return 0;
}