mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 09:09:03 -04:00
[ncmenu] detect cycles in section with all-disabled items #2606
This commit is contained in:
parent
a7e630043a
commit
1a0e254699
@ -87,6 +87,11 @@ menu sections, clicks to dismiss the menu, Escape to dismiss the menu, left
|
||||
and right to change menu sections, and up and down to change menu items (these
|
||||
latter are only consumed if there is an actively unrolled section).
|
||||
|
||||
Items can be disabled with **ncmenu_item_set_status**. Pass **false** to
|
||||
disable the item, or **true** to enable it. All items are enabled by
|
||||
default. A disabled item will not be returned with **ncmenu_mouse_selected**,
|
||||
nor reached with **ncmenu_nextsection** nor **ncmenu_prevsection**.
|
||||
|
||||
# RETURN VALUES
|
||||
|
||||
**ncmenu_create** returns **NULL** on error, or a pointer to a valid new ncmenu.
|
||||
|
@ -588,11 +588,14 @@ int ncmenu_nextitem(ncmenu* n){
|
||||
}
|
||||
}
|
||||
ncmenu_int_section* sec = &n->sections[n->unrolledsection];
|
||||
// FIXME probably best to detect cycles
|
||||
int origselected = sec->itemselected;
|
||||
do{
|
||||
if((unsigned)++sec->itemselected == sec->itemcount){
|
||||
sec->itemselected = 0;
|
||||
}
|
||||
if(sec->itemselected == origselected){
|
||||
break;
|
||||
}
|
||||
}while(!sec->items[sec->itemselected].desc || sec->items[sec->itemselected].disabled);
|
||||
return ncmenu_unroll(n, n->unrolledsection);
|
||||
}
|
||||
@ -604,11 +607,14 @@ int ncmenu_previtem(ncmenu* n){
|
||||
}
|
||||
}
|
||||
ncmenu_int_section* sec = &n->sections[n->unrolledsection];
|
||||
// FIXME probably best to detect cycles
|
||||
int origselected = sec->itemselected;
|
||||
do{
|
||||
if(sec->itemselected-- == 0){
|
||||
sec->itemselected = sec->itemcount - 1;
|
||||
}
|
||||
if(sec->itemselected == origselected){
|
||||
break;
|
||||
}
|
||||
}while(!sec->items[sec->itemselected].desc || sec->items[sec->itemselected].disabled);
|
||||
return ncmenu_unroll(n, n->unrolledsection);
|
||||
}
|
||||
@ -734,7 +740,7 @@ int ncmenu_item_set_status(ncmenu* n, const char* section, const char* item,
|
||||
for(unsigned ii = 0 ; ii < sec->itemcount ; ++ii){
|
||||
struct ncmenu_int_item* i = &sec->items[ii];
|
||||
if(strcmp(i->desc, item) == 0){
|
||||
const bool changed = i->disabled == enabled;
|
||||
const bool changed = (i->disabled != enabled);
|
||||
i->disabled = !enabled;
|
||||
if(changed){
|
||||
if(i->disabled){
|
||||
|
Loading…
x
Reference in New Issue
Block a user