Go to the source code of this file.
◆ ncmultiselector
◆ ncselector
◆ ncmultiselector_create()
Definition at line 885 of file selector.c.
885 {
887 logerror(
"won't use the standard plane");
889 }
893 }
896 }
897 unsigned itemcount = 0;
900 ++itemcount;
901 }
902 }
906 }
907 memset(ns, 0, sizeof(*ns));
925 if(itemcount){
926 if(!(ns->
items = malloc(
sizeof(*ns->
items) * itemcount))){
927 goto freeitems;
928 }
929 }else{
931 }
935 if(unsafe < 0){
936 goto freeitems;
937 }
938 unsigned cols = unsafe;
941 }
943 if(unsafe < 0){
944 goto freeitems;
945 }
946 unsigned cols2 = unsafe;
949 }
956 goto freeitems;
957 }
958 }
959 unsigned dimy, dimx;
961 if(ncmultiselector_dim_yx(ns, &dimy, &dimx)){
962 goto freeitems;
963 }
964 if(ncplane_resize_simple(ns->
ncp, dimy, dimx)){
965 goto freeitems;
966 }
968 goto freeitems;
969 }
970 ncmultiselector_draw(ns);
971 return ns;
972
973freeitems:
977 }
983}
#define logerror(fmt,...)
ncplane * notcurses_stdplane(notcurses *nc)
int ncplane_destroy(ncplane *ncp)
int ncstrwidth(const char *egcs, int *validbytes, int *validwidth)
notcurses * ncplane_notcurses(const ncplane *n)
const struct ncplane_options * opts
void ncmultiselector_destroy(ncmultiselector *n)
struct ncmselector_int * items
◆ ncmultiselector_destroy()
Definition at line 985 of file selector.c.
985 {
987 while(
n->itemcount--){
988 free(
n->items[
n->itemcount].option);
989 free(
n->items[
n->itemcount].desc);
990 }
991 if(ncplane_set_widget(
n->ncp,
NULL,
NULL) == 0){
993 }
999 }
1000}
◆ ncmultiselector_nextitem()
Definition at line 762 of file selector.c.
762 {
763 const char* ret =
NULL;
764 if(
n->itemcount == 0){
766 }
767 unsigned lastdisp =
n->startdisp;
768 lastdisp +=
n->maxdisplay &&
n->maxdisplay <
n->itemcount ?
n->maxdisplay :
n->itemcount;
769 --lastdisp;
770 lastdisp %=
n->itemcount;
771 if(lastdisp ==
n->current){
772 if(++
n->startdisp ==
n->itemcount){
774 }
775 }
777 if(
n->current ==
n->itemcount){
779 }
780 ret =
n->items[
n->current].option;
781 ncmultiselector_draw(
n);
782 return ret;
783}
◆ ncmultiselector_offer_input()
Definition at line 785 of file selector.c.
785 {
786 const int items_shown = ncplane_dim_y(
n->ncp) - 4 - (
n->title ? 2 : 0);
788 int y = nc->
y,
x = nc->
x;
790 return false;
791 }
792 if(
y ==
n->uarrowy &&
x ==
n->arrowx){
794 return true;
795 }
else if(
y ==
n->darrowy &&
x ==
n->arrowx){
797 return true;
798 }
else if(
n->uarrowy <
y && y < n->darrowy){
799
800
801
802
803
804 int cury = (
n->current +
n->itemcount -
n->startdisp) %
n->itemcount;
805 int click =
y -
n->uarrowy - 1;
806 while(click > cury){
808 ++cury;
809 }
810 while(click < cury){
812 --cury;
813 }
814 return true;
815 }
818 n->items[
n->current].selected = !
n->items[
n->current].selected;
819 ncmultiselector_draw(
n);
820 return true;
823 return true;
826 return true;
828 if(items_shown > 0){
829 for(int i = 0 ; i < items_shown ; ++i){
831 }
832 }
833 return true;
835 if(items_shown > 0){
836 for(int i = 0 ; i < items_shown ; ++i){
838 }
839 }
840 return true;
843 return true;
846 return true;
847 }
848 }
849 return false;
850}
#define NCKEY_SCROLL_DOWN
bool ncplane_translate_abs(const ncplane *n, int *restrict y, int *restrict x)
const char * ncmultiselector_nextitem(ncmultiselector *n)
const char * ncmultiselector_previtem(ncmultiselector *n)
◆ ncmultiselector_plane()
◆ ncmultiselector_previtem()
Definition at line 743 of file selector.c.
743 {
744 const char* ret =
NULL;
745 if(
n->itemcount == 0){
746 return ret;
747 }
748 if(
n->current ==
n->startdisp){
749 if(
n->startdisp-- == 0){
750 n->startdisp =
n->itemcount - 1;
751 }
752 }
754 n->current =
n->itemcount;
755 }
757 ret =
n->items[
n->current].option;
758 ncmultiselector_draw(
n);
759 return ret;
760}
◆ ncmultiselector_selected()
int ncmultiselector_selected |
( |
ncmultiselector * |
n, |
|
|
bool * |
selected, |
|
|
unsigned |
count |
|
) |
| |
Definition at line 1002 of file selector.c.
1002 {
1003 if(
n->itemcount != count ||
n->itemcount < 1){
1004 return -1;
1005 }
1006 while(--count){
1007 selected[count] =
n->items[count].selected;
1008 }
1009 return 0;
1010}
◆ ncselector_additem()
Definition at line 392 of file selector.c.
392 {
393 unsigned origdimy, origdimx;
394 ncselector_dim_yx(
n, &origdimy, &origdimx);
395 size_t newsize =
sizeof(*
n->items) * (
n->itemcount + 1);
397 if(!items){
398 return -1;
399 }
403 n->items[
n->itemcount].desc = strdup(
desc);
405 if(usafecols < 0){
406 return -1;
407 }
408 unsigned cols = usafecols;
409 n->items[
n->itemcount].opcolumns = cols;
410 if(cols >
n->longop){
412 }
414 n->items[
n->itemcount].desccolumns = cols;
415 if(cols >
n->longdesc){
417 }
419 unsigned dimy, dimx;
420 ncselector_dim_yx(
n, &dimy, &dimx);
421 if(origdimx < dimx || origdimy < dimy){
422 ncplane_resize_simple(
n->ncp, dimy, dimx);
423 }
424 return ncselector_draw(
n);
425}
◆ ncselector_create()
Definition at line 280 of file selector.c.
280 {
282 logerror(
"won't use the standard plane");
284 }
288 }
289 unsigned itemcount = 0;
292 }
295 ++itemcount;
296 }
297 }
301 }
302 memset(ns, 0, sizeof(*ns));
303 if(
opts->defidx &&
opts->defidx >= itemcount){
304 logerror(
"default index %u too large (%u items)",
opts->defidx, itemcount);
305 goto freeitems;
306 }
318 }else{
320 }
321 }else{
323 }
332 if(itemcount){
333 if(!(ns->
items = malloc(
sizeof(*ns->
items) * itemcount))){
334 goto freeitems;
335 }
336 }else{
338 }
342 if(unsafe < 0){
343 goto freeitems;
344 }
345 unsigned cols = unsafe;
349 }
352 if(unsafe < 0){
353 goto freeitems;
354 }
355 cols = unsafe;
359 }
365 goto freeitems;
366 }
367 }
368 unsigned dimy, dimx;
370 ncselector_dim_yx(ns, &dimy, &dimx);
371 if(ncplane_resize_simple(
n, dimy, dimx)){
372 goto freeitems;
373 }
374 if(ncplane_set_widget(ns->
ncp, ns, (
void(*)(
void*))ncselector_destroy_internal)){
375 goto freeitems;
376 }
377 ncselector_draw(ns);
378 return ns;
379
380freeitems:
384 }
390}
struct ncselector_int * items
◆ ncselector_delitem()
int ncselector_delitem |
( |
ncselector * |
n, |
|
|
const char * |
item |
|
) |
| |
Definition at line 427 of file selector.c.
427 {
428 unsigned origdimy, origdimx;
429 ncselector_dim_yx(
n, &origdimy, &origdimx);
430 bool found = false;
431 int maxop = 0, maxdesc = 0;
432 for(
unsigned idx = 0 ;
idx <
n->itemcount ; ++
idx){
433 if(strcmp(
n->items[
idx].option, item) == 0){
436 if(idx < n->itemcount - 1){
437 memmove(
n->items +
idx,
n->items +
idx + 1,
sizeof(*
n->items) * (
n->itemcount -
idx - 1));
438 }else{
441 }
442 }
444 found = true;
446 }else{
448 if(cols > maxop){
449 maxop = cols;
450 }
452 if(cols > maxdesc){
453 maxdesc = cols;
454 }
455 }
456 }
457 if(found){
459 n->longdesc = maxdesc;
460 unsigned dimy, dimx;
461 ncselector_dim_yx(
n, &dimy, &dimx);
462 if(origdimx > dimx || origdimy > dimy){
463 ncplane_resize_simple(
n->ncp, dimy, dimx);
464 }
465 return ncselector_draw(
n);
466 }
467 return -1;
468}
◆ ncselector_destroy()
void ncselector_destroy |
( |
ncselector * |
n, |
|
|
char ** |
item |
|
) |
| |
Definition at line 270 of file selector.c.
270 {
272 if(item){
273 *item =
n->items[
n->selected].option;
274 n->items[
n->selected].option =
NULL;
275 }
276 ncselector_destroy_internal(
n);
277 }
278}
◆ ncselector_nextitem()
const char * ncselector_nextitem |
( |
ncselector * |
n | ) |
|
Definition at line 500 of file selector.c.
500 {
501 const char* ret =
NULL;
502 if(
n->itemcount == 0){
504 }
505 unsigned lastdisp =
n->startdisp;
506 lastdisp +=
n->maxdisplay &&
n->maxdisplay <
n->itemcount ?
n->maxdisplay :
n->itemcount;
507 --lastdisp;
508 lastdisp %=
n->itemcount;
509 if(lastdisp ==
n->selected){
510 if(++
n->startdisp ==
n->itemcount){
512 }
513 }
515 if(
n->selected ==
n->itemcount){
517 }
518 ret =
n->items[
n->selected].option;
520 return ret;
521}
◆ ncselector_offer_input()
Definition at line 523 of file selector.c.
523 {
524 const int items_shown = ncplane_dim_y(
n->ncp) - 4 - (
n->title ? 2 : 0);
526 int y = nc->
y,
x = nc->
x;
528 return false;
529 }
530 if(
y ==
n->uarrowy &&
x ==
n->arrowx){
532 return true;
533 }
else if(
y ==
n->darrowy &&
x ==
n->arrowx){
535 return true;
536 }
else if(
n->uarrowy <
y && y < n->darrowy){
537
538
539
540
541
542 int cury = (
n->selected +
n->itemcount -
n->startdisp) %
n->itemcount;
543 int click =
y -
n->uarrowy - 1;
544 while(click > cury){
546 ++cury;
547 }
548 while(click < cury){
550 --cury;
551 }
552 return true;
553 }
557 return true;
560 return true;
563 return true;
566 return true;
568 if(items_shown > 0){
569 for(int i = 0 ; i < items_shown ; ++i){
571 }
572 }
573 return true;
575 if(items_shown > 0){
576 for(int i = 0 ; i < items_shown ; ++i){
578 }
579 }
580 return true;
581 }
582 }
583 return false;
584}
const char * ncselector_nextitem(ncselector *n)
const char * ncselector_previtem(ncselector *n)
◆ ncselector_plane()
◆ ncselector_previtem()
const char * ncselector_previtem |
( |
ncselector * |
n | ) |
|
Definition at line 481 of file selector.c.
481 {
482 const char* ret =
NULL;
483 if(
n->itemcount == 0){
484 return ret;
485 }
486 if(
n->selected ==
n->startdisp){
487 if(
n->startdisp-- == 0){
488 n->startdisp =
n->itemcount - 1;
489 }
490 }
491 if(
n->selected == 0){
492 n->selected =
n->itemcount;
493 }
495 ret =
n->items[
n->selected].option;
497 return ret;
498}
◆ ncselector_selected()
const char * ncselector_selected |
( |
const ncselector * |
n | ) |
|
Definition at line 474 of file selector.c.
474 {
475 if(
n->itemcount == 0){
477 }
478 return n->items[
n->selected].option;
479}