export ncplane_family_destroy() #2839

This commit is contained in:
nick black 2025-01-13 23:04:11 -05:00
parent cc9444c644
commit c68db9963d
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
8 changed files with 35 additions and 20 deletions

View File

@ -1,6 +1,9 @@
This document attempts to list user-visible changes and any major internal This document attempts to list user-visible changes and any major internal
rearrangements of Notcurses. rearrangements of Notcurses.
* 3.0.14 (not yet released)
* `ncplane_family_destroy()` has been added to the API.
* 3.0.13 (2025-01-11) * 3.0.13 (2025-01-11)
* Fix regression when building with `USE_CXX=off`. * Fix regression when building with `USE_CXX=off`.
* Use `distutils` from its own Python component rather than assuming * Use `distutils` from its own Python component rather than assuming

View File

@ -863,6 +863,15 @@ struct ncplane* ncplane_reparent(struct ncplane* n, struct ncplane* newparent);
// with it to its new destination. Their z-order is maintained. // with it to its new destination. Their z-order is maintained.
struct ncplane* ncplane_reparent_family(struct ncplane* n, struct ncplane* newparent); struct ncplane* ncplane_reparent_family(struct ncplane* n, struct ncplane* newparent);
// Destroy ncplane 'n'. None of its contents will be visible after the next
// call to notcurses_render(). It is an error to attempt to destroy the
// standard plane. It is a noop if 'n' is NULL.
int ncplane_destroy(struct ncplane* n);
// Destroy ncplane 'n' and all its bound descendants. It is a noop if 'n'
// is NULL. It is an error to attempt to destroy the standard plane.
int ncplane_family_destroy(struct ncplane *n);
// Replace the ncplane's existing resizecb with 'resizecb' (which may be NULL). // Replace the ncplane's existing resizecb with 'resizecb' (which may be NULL).
void ncplane_set_resizecb(struct ncplane* n, int(*resizecb)(struct ncplane*)); void ncplane_set_resizecb(struct ncplane* n, int(*resizecb)(struct ncplane*));

View File

@ -205,7 +205,9 @@ typedef struct ncplane_options {
**int ncplane_blit_rgba(struct ncplane* ***nc***, int ***placey***, int ***placex***, int ***linesize***, ncblitter_e ***blitter***, const unsigned char* ***data***, int ***begy***, int ***begx***, int ***leny***, int ***lenx***);** **int ncplane_blit_rgba(struct ncplane* ***nc***, int ***placey***, int ***placex***, int ***linesize***, ncblitter_e ***blitter***, const unsigned char* ***data***, int ***begy***, int ***begx***, int ***leny***, int ***lenx***);**
**int ncplane_destroy(struct ncplane* ***ncp***);** **int ncplane_destroy(struct ncplane* ***n***);**
**int ncplane_family_destroy(struct ncplane ***n***);**
**void notcurses_drop_planes(struct notcurses* ***nc***);** **void notcurses_drop_planes(struct notcurses* ***nc***);**

View File

@ -1865,9 +1865,9 @@ ncplane_resize_simple(struct ncplane* n, unsigned ylen, unsigned xlen){
return ncplane_resize(n, 0, 0, keepleny, keeplenx, 0, 0, ylen, xlen); return ncplane_resize(n, 0, 0, keepleny, keeplenx, 0, 0, ylen, xlen);
} }
// Destroy the specified ncplane. None of its contents will be visible after // Destroy ncplane 'n'. None of its contents will be visible after the next
// the next call to notcurses_render(). It is an error to attempt to destroy // call to notcurses_render(). It is an error to attempt to destroy the
// the standard plane. // standard plane. It is a noop if 'n' is NULL.
API int ncplane_destroy(struct ncplane* n); API int ncplane_destroy(struct ncplane* n);
// Set the ncplane's base nccell to 'c'. The base cell is used for purposes of // Set the ncplane's base nccell to 'c'. The base cell is used for purposes of
@ -1984,6 +1984,10 @@ ncplane_move_family_bottom(struct ncplane* n){
ncplane_move_family_above(n, NULL); ncplane_move_family_above(n, NULL);
} }
// Destroy ncplane 'n' and all its bound descendants. It is a noop if 'n'
// is NULL. It is an error to attempt to destroy the standard plane.
API int ncplane_family_destroy(struct ncplane *n);
// Return the plane below this one, or NULL if this is at the bottom. // Return the plane below this one, or NULL if this is at the bottom.
API struct ncplane* ncplane_below(struct ncplane* n) API struct ncplane* ncplane_below(struct ncplane* n)
__attribute__ ((nonnull (1))); __attribute__ ((nonnull (1)));

View File

@ -1287,9 +1287,6 @@ cell_set_blitquadrants(nccell* c, unsigned tl, unsigned tr, unsigned bl, unsigne
c->channels = ((c->channels & ~NC_BLITTERSTACK_MASK) | newval); c->channels = ((c->channels & ~NC_BLITTERSTACK_MASK) | newval);
} }
// Destroy a plane and all its bound descendants.
int ncplane_destroy_family(ncplane *ncp);
// Extract the 32-bit background channel from a cell. // Extract the 32-bit background channel from a cell.
static inline uint32_t static inline uint32_t
cell_bchannel(const nccell* cl){ cell_bchannel(const nccell* cl){

View File

@ -1065,7 +1065,7 @@ int ncplane_destroy(ncplane* ncp){
return ret; return ret;
} }
int ncplane_destroy_family(ncplane *ncp){ int ncplane_family_destroy(ncplane *ncp){
if(ncp == NULL){ if(ncp == NULL){
return 0; return 0;
} }
@ -1075,7 +1075,7 @@ int ncplane_destroy_family(ncplane *ncp){
} }
int ret = 0; int ret = 0;
while(ncp->blist){ while(ncp->blist){
ret |= ncplane_destroy_family(ncp->blist); ret |= ncplane_family_destroy(ncp->blist);
} }
ret |= ncplane_destroy(ncp); ret |= ncplane_destroy(ncp);
return ret; return ret;

View File

@ -239,7 +239,7 @@ static void
nctablet_wipeout(nctablet* t){ nctablet_wipeout(nctablet* t){
if(t){ if(t){
if(ncplane_set_widget(t->p, NULL, NULL) == 0){ if(ncplane_set_widget(t->p, NULL, NULL) == 0){
ncplane_destroy_family(t->p); ncplane_family_destroy(t->p);
} }
t->p = NULL; t->p = NULL;
t->cbp = NULL; t->cbp = NULL;
@ -276,7 +276,7 @@ nctablet_delete_internal(struct nctablet* t){
t->next->prev = t->prev; t->next->prev = t->prev;
if(t->p){ if(t->p){
if(ncplane_set_widget(t->p, NULL, NULL) == 0){ if(ncplane_set_widget(t->p, NULL, NULL) == 0){
ncplane_destroy_family(t->p); ncplane_family_destroy(t->p);
} }
} }
free(t); free(t);
@ -379,7 +379,7 @@ ncreel_draw_tablet(const ncreel* nr, nctablet* t, int frontiertop,
if(ll){ // must be smaller than the space we provided; add back bottom if(ll){ // must be smaller than the space we provided; add back bottom
ncplane_resize_simple(t->cbp, ll, cblenx); ncplane_resize_simple(t->cbp, ll, cblenx);
}else{ }else{
ncplane_destroy_family(t->cbp); ncplane_family_destroy(t->cbp);
t->cbp = NULL; t->cbp = NULL;
} }
// resize the borderplane iff we got smaller // resize the borderplane iff we got smaller
@ -491,7 +491,7 @@ trim_reel_overhang(ncreel* r, nctablet* top, nctablet* bottom){
//fprintf(stderr, "top: %dx%d @ %d, miny: %d\n", ylen, xlen, y, miny); //fprintf(stderr, "top: %dx%d @ %d, miny: %d\n", ylen, xlen, y, miny);
if(boty < miny){ if(boty < miny){
//fprintf(stderr, "NUKING top!\n"); //fprintf(stderr, "NUKING top!\n");
ncplane_destroy_family(top->p); ncplane_family_destroy(top->p);
top->p = NULL; top->p = NULL;
top->cbp = NULL; top->cbp = NULL;
top = top->next; top = top->next;
@ -499,7 +499,7 @@ trim_reel_overhang(ncreel* r, nctablet* top, nctablet* bottom){
}else if(y < miny){ }else if(y < miny){
int ynew = ylen - (miny - y); int ynew = ylen - (miny - y);
if(ynew <= 0){ if(ynew <= 0){
ncplane_destroy_family(top->p); ncplane_family_destroy(top->p);
top->p = NULL; top->p = NULL;
top->cbp = NULL; top->cbp = NULL;
}else{ }else{
@ -508,7 +508,7 @@ trim_reel_overhang(ncreel* r, nctablet* top, nctablet* bottom){
} }
if(top->cbp){ if(top->cbp){
if(ynew == !(r->ropts.tabletmask & NCBOXMASK_TOP)){ if(ynew == !(r->ropts.tabletmask & NCBOXMASK_TOP)){
ncplane_destroy_family(top->cbp); ncplane_family_destroy(top->cbp);
top->cbp = NULL; top->cbp = NULL;
}else{ }else{
ncplane_dim_yx(top->cbp, &ylen, &xlen); ncplane_dim_yx(top->cbp, &ylen, &xlen);
@ -532,7 +532,7 @@ trim_reel_overhang(ncreel* r, nctablet* top, nctablet* bottom){
if(maxy < y){ if(maxy < y){
//fprintf(stderr, "NUKING bottom!\n"); //fprintf(stderr, "NUKING bottom!\n");
if(ncplane_set_widget(bottom->p, NULL, NULL) == 0){ if(ncplane_set_widget(bottom->p, NULL, NULL) == 0){
ncplane_destroy_family(bottom->p); ncplane_family_destroy(bottom->p);
} }
bottom->p = NULL; bottom->p = NULL;
bottom->cbp = NULL; bottom->cbp = NULL;
@ -541,7 +541,7 @@ trim_reel_overhang(ncreel* r, nctablet* top, nctablet* bottom){
}if(maxy < boty){ }if(maxy < boty){
int ynew = ylen - (boty - maxy); int ynew = ylen - (boty - maxy);
if(ynew <= 0){ if(ynew <= 0){
ncplane_destroy_family(bottom->p); ncplane_family_destroy(bottom->p);
bottom->p = NULL; bottom->p = NULL;
bottom->cbp = NULL; bottom->cbp = NULL;
}else{ }else{
@ -551,7 +551,7 @@ trim_reel_overhang(ncreel* r, nctablet* top, nctablet* bottom){
//fprintf(stderr, "TRIMMED bottom %p from %d to %d (%d)\n", bottom->p, ylen, ynew, maxy - boty); //fprintf(stderr, "TRIMMED bottom %p from %d to %d (%d)\n", bottom->p, ylen, ynew, maxy - boty);
if(bottom->cbp){ if(bottom->cbp){
if(ynew == !(r->ropts.tabletmask & NCBOXMASK_BOTTOM)){ if(ynew == !(r->ropts.tabletmask & NCBOXMASK_BOTTOM)){
ncplane_destroy_family(bottom->cbp); ncplane_family_destroy(bottom->cbp);
bottom->cbp = NULL; bottom->cbp = NULL;
}else{ }else{
ncplane_dim_yx(bottom->cbp, &ylen, &xlen); ncplane_dim_yx(bottom->cbp, &ylen, &xlen);

View File

@ -220,7 +220,7 @@ nctabbed* nctabbed_create(ncplane* n, const nctabbed_options* topts){
return nt; return nt;
err: err:
ncplane_destroy_family(n); ncplane_family_destroy(n);
if(nt){ if(nt){
free(nt->opts.separator); free(nt->opts.separator);
free(nt); free(nt);
@ -427,7 +427,7 @@ void nctabbed_destroy(nctabbed* nt){
free(t); free(t);
t = tmp; t = tmp;
} }
ncplane_destroy_family(nt->ncp); ncplane_family_destroy(nt->ncp);
free(nt->opts.separator); free(nt->opts.separator);
free(nt); free(nt);
} }