diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index 60b27d1ae7..30db3c1150 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -2278,18 +2278,22 @@ API void ncselector_destroy(struct ncselector* n, char** item); // multiselection widget -- a selector supporting multiple selections. // -// ╭──────────────────────────╮ -// │This is the primary header│ -// ╭──────────────────────this is the secondary header──────╮ -// │ │ -// │ [ ] option1 Long text #1 │ -// │ [X] option2 Long text #2 │ -// │ [ ] option3 Long text #3 │ -// │ [ ] option4 Long text #4 │ -// │ [X] option5 Long text #5 │ -// │ [ ] option6 Long text #6 │ -// │ │ -// ╰────────────────────────────────────here's the footer───╯ +// ╭────────────────────────────────────────────────────────────────╮ +// │ this is truly an awfully long example of a MULTISELECTOR title │ +//╭─────┴─────────────────────────────pick one (you will die regardless)─┤ +//│ ↑ │ +//│ ☐ 1 Across the Atlantic Ocean, there was a place called North America│ +//│ ☐ 2 Discovered by an Italian in the employ of the queen of Spain │ +//│ ☐ 3 Colonized extensively by the Spanish and the French │ +//│ ☐ 4 Developed into a rich nation by Dutch-supplied African slaves │ +//│ ☐ 5 And thus became the largest English-speaking nation on earth │ +//│ ☐ 6 Namely, the United States of America │ +//│ ☐ 7 The inhabitants of the United States called themselves Yankees │ +//│ ☐ 8 For some reason │ +//│ ☐ 9 And, eventually noticing the rest of the world was there, │ +//│ ☐ 10 Decided to rule it. │ +//│ ↓ │ +//╰─────────────────────────press q to exit (there is sartrev("no exit")─╯ // // Unlike the selector widget, zero to all of the items can be selected, but // also the widget does not support adding or removing items at runtime. diff --git a/src/lib/internal.h b/src/lib/internal.h index 1982a06dca..d4990d9f1c 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -187,8 +187,7 @@ typedef struct ncmultiselector { unsigned current; // index of highlighted item unsigned startdisp; // index of first option displayed unsigned maxdisplay; // max number of items to display, 0 -> no limit - int longop; // columns occupied by longest option - int longdesc; // columns occupied by longest description + int longitem; // columns occupied by longest item struct selector_item* items; // list of items and descriptions, heap-copied unsigned itemcount; // number of pairs in 'items' char* title; // can be NULL, in which case there's no riser diff --git a/src/lib/selector.c b/src/lib/selector.c index 0b7b89cc79..607bf1e661 100644 --- a/src/lib/selector.c +++ b/src/lib/selector.c @@ -404,8 +404,8 @@ ncmultiselector_body_width(const ncmultiselector* n){ if(n->secondarycols + 2 > cols){ cols = n->secondarycols + 2; } - if(n->longop + n->longdesc + 5 > cols){ - cols = n->longop + n->longdesc + 5; + if(n->longitem + 7 > cols){ + cols = n->longitem + 7; } return cols; } @@ -470,7 +470,7 @@ ncmultiselector_draw(ncmultiselector* n){ const int bodyoffset = dimx - bodywidth + 2; if(n->maxdisplay && n->maxdisplay < n->itemcount){ n->ncp->channels = n->descchannels; - n->arrowx = bodyoffset + 3; + n->arrowx = bodyoffset + 1; ncplane_putegc_yx(n->ncp, yoff, n->arrowx, "↑", NULL); }else{ n->arrowx = -1; @@ -652,9 +652,8 @@ ncmultiselector* ncmultiselector_create(ncplane* n, int y, int x, const multisel ns->footercols = opts->footer ? mbswidth(opts->footer) : 0; ns->current = 0; ns->startdisp = 0; - ns->longop = 0; + ns->longitem = 0; ns->maxdisplay = opts->maxdisplay; - ns->longdesc = 0; ns->opchannels = opts->opchannels; ns->boxchannels = opts->boxchannels; ns->descchannels = opts->descchannels; @@ -675,13 +674,13 @@ ncmultiselector* ncmultiselector_create(ncplane* n, int y, int x, const multisel const struct selector_item* src = &opts->items[ns->itemcount]; int cols = mbswidth(src->option); ns->items[ns->itemcount].opcolumns = cols; - if(cols > ns->longop){ - ns->longop = cols; + if(cols > ns->longitem){ + ns->longitem = cols; } - cols = mbswidth(src->desc); - ns->items[ns->itemcount].desccolumns = cols; - if(cols > ns->longdesc){ - ns->longdesc = cols; + int cols2 = mbswidth(src->desc); + ns->items[ns->itemcount].desccolumns = cols2; + if(cols + cols2 > ns->longitem){ + ns->longitem = cols + cols2; } ns->items[ns->itemcount].option = strdup(src->option); ns->items[ns->itemcount].desc = strdup(src->desc); diff --git a/src/poc/multiselect.c b/src/poc/multiselect.c index cc8932c8e9..61be0b7a48 100644 --- a/src/poc/multiselect.c +++ b/src/poc/multiselect.c @@ -4,17 +4,19 @@ #include #include +// http://theboomerbible.com/tbb112.html static struct selector_item items[] = { - { "first", "this is the first option", }, - { "2nd", "this is the second option", }, - { "3", "third, third, third option am i", }, - { "fourth", "i have another option here", }, - { "five", "golden rings", }, - { "666", "now it is time for me to REIGN IN BLOOD", }, - { "7seven7", "this monkey's gone to heaven", }, - { "8 8 8", "the chinese 平仮名平平仮名仮名love me, i'm told", }, - { "nine", "nine, nine, nine 'cause you left me", }, - { "ten", "stunning and brave", }, + { "1", "Across the Atlantic Ocean, there was a place called North America", }, + { "2", "Discovered by an Italian in the employ of the queen of Spain", }, + { "3", "Colonized extensively by the Spanish and the French", }, + { "4", "Developed into a rich nation by Dutch-supplied African slaves", }, + { "5", "And thus became the largest English-speaking nation on earth", }, + { "6", "Namely, the United States of America", }, + { "7", "The inhabitants of the United States called themselves Yankees", }, + { "8", "For some reason", }, + { "9", "And, eventually noticing the rest of the world was there,", }, + { "10", "Decided to rule it.", }, + { "11", "This is their story.", }, }; static void @@ -63,16 +65,16 @@ int main(void){ sopts.maxdisplay = 10; sopts.items = items; sopts.itemcount = sizeof(items) / sizeof(*items); - sopts.title = "this is truly, absolutely an awfully long example of a selector title"; + sopts.title = "this is truly an awfully long example of a MULTISELECTOR title"; sopts.secondary = "pick one (you will die regardless)"; - sopts.footer = "press q to exit (there is no exit)"; - channels_set_fg(&sopts.boxchannels, 0x20e040); + sopts.footer = "press q to exit (there is sartrev(\"no exit\")"; + channels_set_fg(&sopts.boxchannels, 0x20e0e0); channels_set_fg(&sopts.opchannels, 0xe08040); - channels_set_fg(&sopts.descchannels, 0x80e040); + channels_set_fg(&sopts.descchannels, 0xe0e040); channels_set_bg(&sopts.opchannels, 0); channels_set_bg(&sopts.descchannels, 0); channels_set_fg(&sopts.footchannels, 0xe00040); - channels_set_fg(&sopts.titlechannels, 0xffff80); + channels_set_fg(&sopts.titlechannels, 0x80ffff); channels_set_fg(&sopts.bgchannels, 0x002000); channels_set_bg(&sopts.bgchannels, 0x002000); channels_set_fg_alpha(&sopts.bgchannels, CELL_ALPHA_BLEND);