diff --git a/include/notcurses.h b/include/notcurses.h index 4b8eca460..7a3c937d0 100644 --- a/include/notcurses.h +++ b/include/notcurses.h @@ -2217,6 +2217,8 @@ struct ncmenu_section { ncinput shortcut; // shortcut, all should be distinct }* items; int itemcount; + int xoff; // used only in library copy, ignored in request + int bodycols; // used only in library copy, ignored in request }; typedef struct ncmenu_options { diff --git a/src/lib/menu.c b/src/lib/menu.c index 731e3ed9a..871b0ab29 100644 --- a/src/lib/menu.c +++ b/src/lib/menu.c @@ -96,6 +96,8 @@ write_header(ncmenu* ncm){ return -1; } for(int i = 0 ; i < ncm->sectioncount ; ++i){ + ncm->sections[i].xoff = xoff; + ncm->sections[i].bodycols = 10; // FIXME if(ncplane_putstr(ncm->ncp, ncm->sections[i].name) < 0){ return -1; } @@ -157,11 +159,16 @@ ncmenu* ncmenu_create(notcurses* nc, const ncmenu_options* opts){ return NULL; } -static int +static inline int section_height(const ncmenu* n, int sectionidx){ return n->sections[sectionidx].itemcount + 2; } +static inline int +section_width(const ncmenu* n, int sectionidx){ + return n->sections[sectionidx].bodycols + 2; +} + int ncmenu_unroll(ncmenu* n, int sectionidx){ if(sectionidx < 0 || sectionidx >= n->sectioncount){ return -1; @@ -172,13 +179,14 @@ int ncmenu_unroll(ncmenu* n, int sectionidx){ n->unrolledsection = sectionidx; int dimy, dimx; ncplane_dim_yx(n->ncp, &dimy, &dimx); - int height = section_height(n, sectionidx); - int width = 10; // FIXME - int ypos = n->bottom ? dimy - height - 1 : 1; - if(ncplane_cursor_move_yx(n->ncp, ypos, 1)){ + const int height = section_height(n, sectionidx); + const int width = section_width(n, sectionidx); + const int ypos = n->bottom ? dimy - height - 1 : 1; + const int xpos = n->sections[sectionidx].xoff; + if(ncplane_cursor_move_yx(n->ncp, ypos, xpos)){ return -1; } - if(ncplane_rounded_box_sized(n->ncp, 0, n->sectionchannels, height, width, 0)){ + if(ncplane_rounded_box_sized(n->ncp, 0, n->headerchannels, height, width, 0)){ return -1; } // FIXME