diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index 46ca04ce4..1c0efa74c 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -68,6 +68,7 @@ typedef enum { // Alignment within a plane or terminal. Left/right-justified, or centered. typedef enum { + NCALIGN_UNALIGNED, NCALIGN_LEFT, NCALIGN_CENTER, NCALIGN_RIGHT, @@ -1293,7 +1294,10 @@ notcurses_align(int availcols, ncalign_e align, int cols){ if(align == NCALIGN_CENTER){ return (availcols - cols) / 2; } - return availcols - cols; // NCALIGN_RIGHT + if(align == NCALIGN_RIGHT){ + return availcols - cols; + } + return -INT_MAX; } // Return the column at which 'c' cols ought start in order to be aligned diff --git a/src/lib/internal.h b/src/lib/internal.h index 558c0aca0..3c878af92 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -85,6 +85,7 @@ typedef struct ncplane { cell basecell; // cell written anywhere that fb[i].gcluster == 0 struct notcurses* nc; // notcurses object of which we are a part char* name; // used only for debugging + ncalign_e align; // relative to parent plane, for automatic realignment uint16_t stylemask; // same deal as in a cell bool scrolling; // is scrolling enabled? always disabled by default } ncplane; diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 3dc50ba82..e8dd8695a 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -320,9 +320,11 @@ ncplane* ncplane_new_internal(notcurses* nc, ncplane* n, const ncplane_options* p->logrow = 0; p->blist = NULL; p->name = nopts->name ? strdup(nopts->name) : NULL; + p->align = NCALIGN_UNALIGNED; if( (p->boundto = n) ){ if(nopts->flags & NCPLANE_OPTION_HORALIGNED){ p->absx = ncplane_align(n, nopts->horiz.align, nopts->cols); + p->align = nopts->horiz.align; }else{ p->absx = nopts->horiz.x; } @@ -2007,6 +2009,20 @@ const ncplane* ncplane_parent_const(const ncplane* n){ return n->boundto; } +int ncplane_resize_realign(ncplane* n){ + const ncplane* parent = ncplane_parent_const(n); + if(parent == n){ // somehow got stdplane, should never get here + logerror(ncplane_notcurses(n), "Passed the standard plane"); + return -1; + } + if(n->align == NCALIGN_UNALIGNED){ + logerror(ncplane_notcurses(n), "Passed a non-aligned plane"); + return -1; + } + int xpos = ncplane_align(parent, n->align, ncplane_dim_x(n)); + return ncplane_move_yx(n, ncplane_y(n), xpos); +} + ncplane* ncplane_reparent(ncplane* n, ncplane* newparent){ if(n == n->nc->stdplane){ return NULL; // can't reparent standard plane