ncreader: horizontal scrolling mostly works #839

This commit is contained in:
nick black 2020-08-25 08:55:30 -04:00
parent afc06a0271
commit 70a28feb63
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
8 changed files with 41 additions and 6 deletions

View File

@ -17,6 +17,7 @@ rearrangements of Notcurses.
* `int ncreader_move_up(struct ncreader* n);` * `int ncreader_move_up(struct ncreader* n);`
* `int ncreader_move_down(struct ncreader* n);` * `int ncreader_move_down(struct ncreader* n);`
* `int ncreader_write_egc(struct ncreader* n, const char* egc);` * `int ncreader_write_egc(struct ncreader* n, const char* egc);`
* Added `ncplane_above()` and `notcurses_bottom()`.
* 1.6.17 (2020-08-22) * 1.6.17 (2020-08-22)
* `ncdirect_flush()` now takes a `const struct ncdirect*`. * `ncdirect_flush()` now takes a `const struct ncdirect*`.

View File

@ -214,6 +214,9 @@ Utility functions operating on the toplevel `notcurses` object include:
// Return the topmost ncplane, of which there is always at least one. // Return the topmost ncplane, of which there is always at least one.
struct ncplane* notcurses_top(struct notcurses* n); struct ncplane* notcurses_top(struct notcurses* n);
// Return the bottommost ncplane, of which there is always at least one.
struct ncplane* notcurses_bottom(struct notcurses* n);
// Return our current idea of the terminal dimensions in rows and cols. // Return our current idea of the terminal dimensions in rows and cols.
static inline void static inline void
notcurses_term_dim_yx(const struct notcurses* n, int* restrict rows, notcurses_term_dim_yx(const struct notcurses* n, int* restrict rows,
@ -826,6 +829,9 @@ int ncplane_move_above(struct ncplane* restrict n, struct ncplane* restrict abov
// Return the ncplane below this one, or NULL if this is at the stack's bottom. // Return the ncplane below this one, or NULL if this is at the stack's bottom.
struct ncplane* ncplane_below(struct ncplane* n); struct ncplane* ncplane_below(struct ncplane* n);
// Return the ncplane above this one, or NULL if this is at the stack's top.
struct ncplane* ncplane_above(struct ncplane* n);
``` ```
Each plane holds a user pointer which can be retrieved and set (or ignored). In Each plane holds a user pointer which can be retrieved and set (or ignored). In

View File

@ -10,6 +10,10 @@ notcurses_plane - operations on ncplanes
**#include <notcurses/notcurses.h>** **#include <notcurses/notcurses.h>**
**struct ncplane* notcurses_top(struct notcurses* n);**
**struct ncplane* notcurses_bottom(struct notcurses* n);**
**struct ncplane* ncplane_new(struct notcurses* nc, int rows, int cols, int yoff, int xoff, void* opaque);** **struct ncplane* ncplane_new(struct notcurses* nc, int rows, int cols, int yoff, int xoff, void* opaque);**
**struct ncplane* ncplane_new_named(struct notcurses* nc, int rows, int cols, int yoff, int xoff, void* opaque, const char* name);** **struct ncplane* ncplane_new_named(struct notcurses* nc, int rows, int cols, int yoff, int xoff, void* opaque, const char* name);**
@ -52,6 +56,8 @@ notcurses_plane - operations on ncplanes
**struct ncplane* ncplane_below(struct ncplane* n);** **struct ncplane* ncplane_below(struct ncplane* n);**
**struct ncplane* ncplane_above(struct ncplane* n);**
**char* ncplane_at_cursor(struct ncplane* n, uint16_t* stylemask, uint64_t* channels);** **char* ncplane_at_cursor(struct ncplane* n, uint16_t* stylemask, uint64_t* channels);**
**int ncplane_at_cursor_cell(struct ncplane* n, cell* c);** **int ncplane_at_cursor_cell(struct ncplane* n, cell* c);**

View File

@ -858,6 +858,9 @@ API int notcurses_render_to_file(struct notcurses* nc, FILE* fp);
// Return the topmost ncplane, of which there is always at least one. // Return the topmost ncplane, of which there is always at least one.
API struct ncplane* notcurses_top(struct notcurses* n); API struct ncplane* notcurses_top(struct notcurses* n);
// Return the bottommost ncplane, of which there is always at least one.
API struct ncplane* notcurses_bottom(struct notcurses* n);
// Destroy all ncplanes other than the stdplane. // Destroy all ncplanes other than the stdplane.
API void notcurses_drop_planes(struct notcurses* nc); API void notcurses_drop_planes(struct notcurses* nc);
@ -1197,6 +1200,7 @@ API int ncplane_move_below(struct ncplane* RESTRICT 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);
API struct ncplane* ncplane_above(struct ncplane* n);
// Rotate the plane π/2 radians clockwise or counterclockwise. This cannot // Rotate the plane π/2 radians clockwise or counterclockwise. This cannot
// be performed on arbitrary planes, because glyphs cannot be arbitrarily // be performed on arbitrary planes, because glyphs cannot be arbitrarily

View File

@ -62,6 +62,7 @@ int ncplane_set_base_cell(struct ncplane* ncp, const cell* c);
int ncplane_set_base(struct ncplane* ncp, const char* egc, uint32_t styles, uint64_t channels); int ncplane_set_base(struct ncplane* ncp, const char* egc, uint32_t styles, uint64_t channels);
int ncplane_base(struct ncplane* ncp, cell* c); int ncplane_base(struct ncplane* ncp, cell* c);
struct ncplane* notcurses_top(struct notcurses* n); struct ncplane* notcurses_top(struct notcurses* n);
struct ncplane* notcurses_bottom(struct notcurses* n);
void notcurses_drop_planes(struct notcurses* nc); void notcurses_drop_planes(struct notcurses* nc);
int notcurses_refresh(struct notcurses* n, int* restrict y, int* restrict x); int notcurses_refresh(struct notcurses* n, int* restrict y, int* restrict x);
struct ncplane* ncplane_reparent(struct ncplane* n, struct ncplane* newparent); struct ncplane* ncplane_reparent(struct ncplane* n, struct ncplane* newparent);
@ -102,6 +103,7 @@ void ncplane_move_bottom(struct ncplane* n);
int ncplane_move_below(struct ncplane* restrict n, struct ncplane* restrict below); int ncplane_move_below(struct ncplane* restrict n, struct ncplane* restrict below);
int ncplane_move_above(struct ncplane* restrict n, struct ncplane* restrict above); int ncplane_move_above(struct ncplane* restrict n, struct ncplane* restrict above);
struct ncplane* ncplane_below(struct ncplane* n); struct ncplane* ncplane_below(struct ncplane* n);
struct ncplane* ncplane_above(struct ncplane* n);
char* notcurses_at_yx(struct notcurses* nc, int yoff, int xoff, uint16_t* stylemask, uint64_t* channels); char* notcurses_at_yx(struct notcurses* nc, int yoff, int xoff, uint16_t* stylemask, uint64_t* channels);
char* ncplane_at_cursor(struct ncplane* n, uint16_t* stylemask, uint64_t* channels); char* ncplane_at_cursor(struct ncplane* n, uint16_t* stylemask, uint64_t* channels);
char* ncplane_at_yx(const struct ncplane* n, int y, int x, uint16_t* stylemask, uint64_t* channels); char* ncplane_at_yx(const struct ncplane* n, int y, int x, uint16_t* stylemask, uint64_t* channels);

View File

@ -1888,10 +1888,18 @@ ncplane* notcurses_top(notcurses* n){
return n->top; return n->top;
} }
ncplane* notcurses_bottom(notcurses* n){
return n->bottom;
}
ncplane* ncplane_below(ncplane* n){ ncplane* ncplane_below(ncplane* n){
return n->below; return n->below;
} }
ncplane* ncplane_above(ncplane* n){
return n->above;
}
#define SET_BTN_EVENT_MOUSE "1002" #define SET_BTN_EVENT_MOUSE "1002"
#define SET_FOCUS_EVENT_MOUSE "1004" #define SET_FOCUS_EVENT_MOUSE "1004"
#define SET_SGR_MODE_MOUSE "1006" #define SET_SGR_MODE_MOUSE "1006"

View File

@ -181,10 +181,15 @@ int ncreader_write_egc(ncreader* n, const char* egc){
logerror(n->ncp->nc, "Fed illegal UTF-8 [%s]\n", egc); logerror(n->ncp->nc, "Fed illegal UTF-8 [%s]\n", egc);
return -1; return -1;
} }
if(n->textarea->x >= n->textarea->lenx - (cols + 1)){ if(n->textarea->x >= n->textarea->lenx - cols){
if(n->horscroll){ if(n->horscroll){
// FIXME resize if(ncplane_resize_simple(n->textarea, n->textarea->leny, n->textarea->lenx + cols)){
return -1;
}
++n->xproject;
} }
}else if(n->ncp->x >= n->ncp->lenx){
++n->xproject;
} }
// use ncplane_putegc on both planes because it'll get cursor movement right // use ncplane_putegc on both planes because it'll get cursor movement right
if(ncplane_putegc(n->textarea, egc, NULL) < 0){ if(ncplane_putegc(n->textarea, egc, NULL) < 0){
@ -193,7 +198,6 @@ int ncreader_write_egc(ncreader* n, const char* egc){
if(ncplane_putegc(n->ncp, egc, NULL) < 0){ if(ncplane_putegc(n->ncp, egc, NULL) < 0){
return -1; return -1;
} }
// FIXME pan right if necessary
return 0; return 0;
} }
@ -225,6 +229,7 @@ bool ncreader_offer_input(ncreader* n, const ncinput* ni){
} }
ncplane_putegc_yx(n->textarea, y, x, "", NULL); ncplane_putegc_yx(n->textarea, y, x, "", NULL);
ncplane_cursor_move_yx(n->textarea, y, x); ncplane_cursor_move_yx(n->textarea, y, x);
ncplane_cursor_move_yx(n->ncp, n->ncp->y, n->ncp->x - 1);
ncreader_redraw(n); ncreader_redraw(n);
return true; return true;
} }

View File

@ -56,13 +56,16 @@ auto main(int argc, const char** argv) -> int {
int y, x; int y, x;
struct ncplane* ncp = ncreader_plane(nr); struct ncplane* ncp = ncreader_plane(nr);
ncplane_cursor_yx(ncp, &y, &x); ncplane_cursor_yx(ncp, &y, &x);
nc.cursor_enable(y + 2, x + 2); nc.cursor_enable(y + 2, 2 + (x >= ncplane_dim_x(ncp) ? ncplane_dim_x(ncp) - 1 : x));
int ncpy, ncpx; int ncpy, ncpx;
ncplane_cursor_yx(ncp, &ncpy, &ncpx); ncplane_cursor_yx(ncp, &ncpy, &ncpx);
struct ncplane* tplane = ncplane_above(ncp);
int tgeomy, tgeomx, vgeomy, vgeomx; int tgeomy, tgeomx, vgeomy, vgeomx;
(*n)->get_dim(&tgeomy, &tgeomx); ncplane_dim_yx(tplane, &tgeomy, &tgeomx);
ncplane_dim_yx(ncp, &vgeomy, &vgeomx); ncplane_dim_yx(ncp, &vgeomy, &vgeomx);
(*n)->printf(0, 0, "Cursor: %d/%d Viewgeom: %d/%d Textgeom: %d/%d", ncpy, ncpx, vgeomy, vgeomx, tgeomy, tgeomx); (*n)->printf(0, 0, "Scroll: %lc Cursor: %d/%d Viewgeom: %d/%d Textgeom: %d/%d",
horscroll ? L'' : L'🗴',
ncpy, ncpx, vgeomy, vgeomx, tgeomy, tgeomx);
nc.render(); nc.render();
} }
nc.render(); nc.render();