From 6084105c68a82bd8b082a9a96157d29c871dcbe1 Mon Sep 17 00:00:00 2001 From: nick black Date: Wed, 18 Nov 2020 07:49:22 -0500 Subject: [PATCH] add ncplane_set_resizecb() #1124 --- NEWS.md | 1 + USAGE.md | 7 +++++++ doc/man/man3/notcurses_plane.3.md | 4 ++++ include/notcurses/notcurses.h | 5 ++++- src/lib/notcurses.c | 4 ++++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index e62b281c0..04fbd621d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,7 @@ rearrangements of Notcurses. self-documenting `struct ncplane_options` argument. So long as the arguments to `ncplane_new()` do not have side-effects, calls can be mechanically translated to their `ncplane_create()` equivalents. + * Added `nplane_set_resize()`. * 2.0.4 (2020-11-10) * Fixed unit tests for non UTF-8 case, brown bagger, alas. diff --git a/USAGE.md b/USAGE.md index b5081b8ee..5b76c8575 100644 --- a/USAGE.md +++ b/USAGE.md @@ -670,6 +670,13 @@ struct ncplane* ncplane_create(struct ncplane* n, const ncplane_options* nopts); // and will be made a bound child of 'newparent', if 'newparent' is not NULL. struct ncplane* ncplane_reparent(struct ncplane* n, struct ncplane* newparent); +// Replace the ncplane's existing resizecb with 'resizecb' (which may be NULL). +void ncplane_set_resizecb(struct ncplane* n, int(*resizecb)(struct ncplane*)); + +// Suitable for use as a 'resizecb'. This will realign the plane 'n' against its +// parent, using the alignment specified at ncplane_create()-time. +int ncplane_resize_realign(struct ncplane* n); + // Get the plane to which the plane 'n' is bound, if any. struct ncplane* ncplane_parent(struct ncplane* n); const struct ncplane* ncplane_parent_const(const struct ncplane* n); diff --git a/doc/man/man3/notcurses_plane.3.md b/doc/man/man3/notcurses_plane.3.md index 55c239c58..b7d252591 100644 --- a/doc/man/man3/notcurses_plane.3.md +++ b/doc/man/man3/notcurses_plane.3.md @@ -33,6 +33,10 @@ typedef struct ncplane_options { **struct ncplane* ncplane_reparent(struct ncplane* ***n***, struct ncplane* ***newparent***);** +**int ncplane_resize_realign(struct ncplane* ***n***);** + +**void ncplane_set_resizecb(struct ncplane* ***n***, int(*resizecb)(struct ncplane*));** + **struct ncplane* ncplane_dup(struct ncplane* ***n***, void* ***opaque***);** **int ncplane_resize(struct ncplane* ***n***, int ***keepy***, int ***keepx***, int ***keepleny***, int ***keeplenx***, int ***yoff***, int ***xoff***, int ***ylen***, int ***xlen***);** diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index ccfd16587..66dd5bf31 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -1049,10 +1049,13 @@ API struct ncplane* ncplane_create(struct ncplane* n, const ncplane_options* nop API struct ncplane* ncplane_new(struct ncplane* n, int rows, int cols, int y, int x, void* opaque, const char* name) __attribute__ ((deprecated)); -// Suitable for use as a `resizecb`. This will realign the plane 'n' against its +// Suitable for use as a 'resizecb'. This will realign the plane 'n' against its // parent, using the alignment specified at ncplane_create()-time. API int ncplane_resize_realign(struct ncplane* n); +// Replace the ncplane's existing resizecb with 'resizecb' (which may be NULL). +API void ncplane_set_resizecb(struct ncplane* n, int(*resizecb)(struct ncplane*)); + // Plane 'n' will be unbound from its parent plane, if it is currently bound, // and will be made a bound child of 'newparent', if 'newparent' is not NULL. API struct ncplane* ncplane_reparent(struct ncplane* n, struct ncplane* newparent); diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 176a044cb..5df61aca3 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -2036,6 +2036,10 @@ const ncplane* ncplane_parent_const(const ncplane* n){ return n->boundto; } +void ncplane_set_resizecb(ncplane* n, int(*resizecb)(ncplane*)){ + n->resizecb = resizecb; +} + int ncplane_resize_realign(ncplane* n){ const ncplane* parent = ncplane_parent_const(n); if(parent == n){ // somehow got stdplane, should never get here