From 66f80c77f9fdafd709f47f117ffe793faede5c86 Mon Sep 17 00:00:00 2001 From: nick black Date: Sat, 29 Aug 2020 15:50:45 -0400 Subject: [PATCH] add ncplane_y() and ncplane_x() --- NEWS.md | 4 ++++ USAGE.md | 2 ++ doc/man/man3/notcurses_plane.3.md | 4 ++++ include/notcurses/notcurses.h | 2 ++ python/src/notcurses/build_notcurses.py | 2 ++ src/lib/notcurses.c | 26 +++++++++++++++---------- 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/NEWS.md b/NEWS.md index 39cd37ed6..0299b3f01 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,10 @@ This document attempts to list user-visible changes and any major internal rearrangements of Notcurses. +* 1.6.20 (not yet released) + * Added convenience functions `ncplane_y()` and `ncplane_x()`, components + of longstanding `ncplane_yx()`. + * 1.6.19 (2020-08-27) * Direct mode now places the terminal into "cbreak mode". This disables echo and line-buffering of input. If this is undesirable, you can restore diff --git a/USAGE.md b/USAGE.md index e5d553c81..48f2317d9 100644 --- a/USAGE.md +++ b/USAGE.md @@ -743,6 +743,8 @@ int ncplane_move_yx(struct ncplane* n, int y, int x); // Get the origin of this plane relative to the standard plane, or the plane to // which it is bound (if it is bound to a plane). void ncplane_yx(const struct ncplane* n, int* restrict y, int* restrict x); +int ncplane_y(const struct ncplane* n); +int ncplane_x(const struct ncplane* n); // Return the dimensions of this ncplane. void ncplane_dim_yx(struct ncplane* n, int* restrict rows, int* restrict cols); diff --git a/doc/man/man3/notcurses_plane.3.md b/doc/man/man3/notcurses_plane.3.md index bdedbd242..03f9d6f48 100644 --- a/doc/man/man3/notcurses_plane.3.md +++ b/doc/man/man3/notcurses_plane.3.md @@ -36,6 +36,10 @@ notcurses_plane - operations on ncplanes **void ncplane_yx(const struct ncplane* n, int* restrict y, int* restrict x);** +**int ncplane_y(const struct ncplane* n);** + +**int ncplane_x(const struct ncplane* n);** + **struct ncplane* ncplane_parent(struct ncplane* n);** **const struct ncplane* ncplane_parent_const(const struct ncplane* n);** diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index 2269d1215..536197dde 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -1185,6 +1185,8 @@ API int ncplane_move_yx(struct ncplane* n, int y, int x); // Get the origin of this plane relative to the standard plane, or the plane to // which it is bound (if it is bound to a plane). API void ncplane_yx(const struct ncplane* n, int* RESTRICT y, int* RESTRICT x); +API int ncplane_y(const struct ncplane* n); +API int ncplane_x(const struct ncplane* n); // Get the plane to which the plane 'n' is bound, if any. API struct ncplane* ncplane_parent(struct ncplane* n); diff --git a/python/src/notcurses/build_notcurses.py b/python/src/notcurses/build_notcurses.py index 4dedc2d81..cea8401a8 100644 --- a/python/src/notcurses/build_notcurses.py +++ b/python/src/notcurses/build_notcurses.py @@ -98,6 +98,8 @@ int ncplane_cursor_move_yx(struct ncplane* n, int y, int x); void ncplane_cursor_yx(struct ncplane* n, int* y, int* x); int ncplane_move_yx(struct ncplane* n, int y, int x); void ncplane_yx(struct ncplane* n, int* y, int* x); +int ncplane_y(const struct ncplane* n); +int ncplane_x(const struct ncplane* n); void ncplane_dim_yx(const struct ncplane* n, int* rows, int* cols); int ncplane_putc_yx(struct ncplane* n, int y, int x, const cell* c); void ncplane_move_top(struct ncplane* n); diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index cefe1d44c..2523c4aa2 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -1870,20 +1870,26 @@ int ncplane_move_yx(ncplane* n, int y, int x){ return 0; } +int ncplane_y(const ncplane* n){ + if(n->boundto == NULL){ + return n->absy - n->nc->stdplane->absy; + } + return n->absy - n->boundto->absy; +} + +int ncplane_x(const ncplane* n){ + if(n->boundto == NULL){ + return n->absx - n->nc->stdplane->absx; + } + return n->absx - n->boundto->absx; +} + void ncplane_yx(const ncplane* n, int* y, int* x){ if(y){ - if(n->boundto == NULL){ - *y = n->absy - n->nc->stdplane->absy; - }else{ - *y = n->absy - n->boundto->absy; - } + *y = ncplane_y(n); } if(x){ - if(n->boundto == NULL){ - *x = n->absx - n->nc->stdplane->absx; - }else{ - *x = n->absx - n->boundto->absx; - } + *x = ncplane_x(n); } }