alignment: add NCALIGN_UNALIGNED, preserve align type #364

pull/1027/head
nick black 4 years ago
parent 2d9598b913
commit 2f26f06386
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -68,6 +68,7 @@ typedef enum {
// Alignment within a plane or terminal. Left/right-justified, or centered. // Alignment within a plane or terminal. Left/right-justified, or centered.
typedef enum { typedef enum {
NCALIGN_UNALIGNED,
NCALIGN_LEFT, NCALIGN_LEFT,
NCALIGN_CENTER, NCALIGN_CENTER,
NCALIGN_RIGHT, NCALIGN_RIGHT,
@ -1293,7 +1294,10 @@ notcurses_align(int availcols, ncalign_e align, int cols){
if(align == NCALIGN_CENTER){ if(align == NCALIGN_CENTER){
return (availcols - cols) / 2; 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 // Return the column at which 'c' cols ought start in order to be aligned

@ -85,6 +85,7 @@ typedef struct ncplane {
cell basecell; // cell written anywhere that fb[i].gcluster == 0 cell basecell; // cell written anywhere that fb[i].gcluster == 0
struct notcurses* nc; // notcurses object of which we are a part struct notcurses* nc; // notcurses object of which we are a part
char* name; // used only for debugging 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 uint16_t stylemask; // same deal as in a cell
bool scrolling; // is scrolling enabled? always disabled by default bool scrolling; // is scrolling enabled? always disabled by default
} ncplane; } ncplane;

@ -320,9 +320,11 @@ ncplane* ncplane_new_internal(notcurses* nc, ncplane* n, const ncplane_options*
p->logrow = 0; p->logrow = 0;
p->blist = NULL; p->blist = NULL;
p->name = nopts->name ? strdup(nopts->name) : NULL; p->name = nopts->name ? strdup(nopts->name) : NULL;
p->align = NCALIGN_UNALIGNED;
if( (p->boundto = n) ){ if( (p->boundto = n) ){
if(nopts->flags & NCPLANE_OPTION_HORALIGNED){ if(nopts->flags & NCPLANE_OPTION_HORALIGNED){
p->absx = ncplane_align(n, nopts->horiz.align, nopts->cols); p->absx = ncplane_align(n, nopts->horiz.align, nopts->cols);
p->align = nopts->horiz.align;
}else{ }else{
p->absx = nopts->horiz.x; p->absx = nopts->horiz.x;
} }
@ -2007,6 +2009,20 @@ const ncplane* ncplane_parent_const(const ncplane* n){
return n->boundto; 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){ ncplane* ncplane_reparent(ncplane* n, ncplane* newparent){
if(n == n->nc->stdplane){ if(n == n->nc->stdplane){
return NULL; // can't reparent standard plane return NULL; // can't reparent standard plane

Loading…
Cancel
Save