ncreel: purge {tblr}off fields; these are ncplane properties #627

This commit is contained in:
nick black 2020-07-06 15:59:29 -04:00
parent 8a9a0c35e0
commit 479dd00739
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
6 changed files with 32 additions and 67 deletions

View File

@ -3,6 +3,10 @@ rearrangements of Notcurses.
* 1.6.1 (not yet released)
* Added `notcurses_render_file()` to dump last rendered frame to a `FILE*`.
* The `ncreel` widget has been overhauled to bring it in line with the
others (`ncreel` began life in another project, predating Notcurses).
The `toff`, `boff`, `roff`, and `loff` fields of `ncreel_options` have
been purged.
* 1.6.0 (2020-07-04)
* Behavior has changed regarding use of the provided `FILE*` (which, when

View File

@ -2510,9 +2510,6 @@ typedef struct ncreel_options {
int max_supported_cols;
int max_supported_rows;
// desired offsets within the surrounding ncplane (top right bottom left) upon
// creation / resize. an ncreel_move() operation updates these.
int toff, roff, boff, loff;
// notcurses can draw a border around the ncreel, and also around the
// component tablets. inhibit borders by setting all valid bits in the masks.
// partially inhibit borders by setting individual bits in the masks. the
@ -2532,7 +2529,7 @@ struct nctablet;
struct ncreel;
// Create an ncreel according to the provided specifications. Returns NULL on
// failure. w must be a valid ncplane*, to which offsets are relative. Note that
// failure. nc must be a valid ncplane*, to which offsets are relative. Note that
// there might not be enough room for the specified offsets, in which case the
// ncreel will be clipped on the bottom and right. A minimum number of rows
// and columns can be enforced via popts. efd, if non-negative, is an eventfd

View File

@ -277,6 +277,12 @@ ncreel_demo_core(struct notcurses* nc, int efdr, int efdw){
tabletctx* tctxs = NULL;
bool aborted = false;
int x = 8, y = 4;
int dimy, dimx;
struct ncplane* std = notcurses_stddim_yx(nc, &dimy, &dimx);
struct ncplane* w = ncplane_new(nc, dimy - 8, dimx - 16, y, x, NULL);
if(w == NULL){
return -1;
}
ncreel_options popts = {
.min_supported_cols = 8,
.min_supported_rows = 5,
@ -284,10 +290,6 @@ ncreel_demo_core(struct notcurses* nc, int efdr, int efdw){
.borderchan = 0,
.tabletchan = 0,
.focusedchan = 0,
.toff = y,
.loff = x,
.roff = x,
.boff = y,
.bgchannel = 0,
.flags = NCREEL_OPTION_INFINITESCROLL | NCREEL_OPTION_CIRCULAR,
};
@ -298,25 +300,25 @@ ncreel_demo_core(struct notcurses* nc, int efdr, int efdw){
channels_set_fg_rgb(&popts.borderchan, 136, 23, 152);
channels_set_bg_rgb(&popts.borderchan, 0, 0, 0);
if(channels_set_fg_alpha(&popts.bgchannel, CELL_ALPHA_TRANSPARENT)){
ncplane_destroy(w);
return -1;
}
if(channels_set_bg_alpha(&popts.bgchannel, CELL_ALPHA_TRANSPARENT)){
ncplane_destroy(w);
return -1;
}
int dimy;
struct ncplane* w = notcurses_stddim_yx(nc, &dimy, NULL);
struct ncreel* pr = ncreel_create(w, &popts, efdw);
if(pr == NULL){
fprintf(stderr, "Error creating ncreel\n");
ncplane_destroy(w);
return -1;
}
// Press a for a new nc above the current, c for a new one below the
// current, and b for a new block at arbitrary placement.
ncplane_styles_on(w, NCSTYLE_BOLD | NCSTYLE_ITALIC);
ncplane_set_fg_rgb(w, 58, 150, 221);
ncplane_set_bg_default(w);
ncplane_printf_yx(w, dimy - 1, 1, "a, b, c create tablets, DEL deletes.");
ncplane_styles_off(w, NCSTYLE_BOLD | NCSTYLE_ITALIC);
ncplane_styles_on(std, NCSTYLE_BOLD | NCSTYLE_ITALIC);
ncplane_set_fg_rgb(std, 58, 150, 221);
ncplane_set_bg_default(std);
ncplane_printf_yx(std, 1, 1, "a, b, c create tablets, DEL deletes.");
ncplane_styles_off(std, NCSTYLE_BOLD | NCSTYLE_ITALIC);
// FIXME clrtoeol();
struct timespec deadline;
clock_gettime(CLOCK_MONOTONIC, &deadline);
@ -335,14 +337,14 @@ ncreel_demo_core(struct notcurses* nc, int efdr, int efdw){
tctxs = newtablet;
}
do{
ncplane_styles_set(w, 0);
ncplane_set_fg_rgb(w, 197, 15, 31);
ncplane_styles_set(std, 0);
ncplane_set_fg_rgb(std, 197, 15, 31);
int count = ncreel_tabletcount(pr);
ncplane_styles_on(w, NCSTYLE_BOLD);
ncplane_printf_yx(w, dimy - 2, 2, "%d tablet%s", count, count == 1 ? "" : "s");
ncplane_styles_off(w, NCSTYLE_BOLD);
ncplane_styles_on(std, NCSTYLE_BOLD);
ncplane_printf_yx(std, 2, 2, "%d tablet%s", count, count == 1 ? "" : "s");
ncplane_styles_off(std, NCSTYLE_BOLD);
// FIXME wclrtoeol(w);
ncplane_set_fg_rgb(w, 0, 55, 218);
ncplane_set_fg_rgb(std, 0, 55, 218);
wchar_t rw;
if((rw = handle_input(nc, pr, efdr, &deadline)) == (wchar_t)-1){
break;
@ -364,7 +366,7 @@ ncreel_demo_core(struct notcurses* nc, int efdr, int efdw){
case NCKEY_DOWN: ncreel_next(pr); break;
case NCKEY_DEL: kill_active_tablet(pr, &tctxs); break;
case NCKEY_RESIZE: notcurses_render(nc); break;
default: ncplane_printf_yx(w, 3, 2, "Unknown keycode (0x%x)\n", rw); break;
default: ncplane_printf_yx(std, 3, 2, "Unknown keycode (0x%x)\n", rw); break;
}
if(newtablet){
newtablet->next = tctxs;

View File

@ -599,21 +599,21 @@ ncreel* ncreel_create(ncplane* w, const ncreel_options* ropts, int efd){
--maxy;
--maxx;
int ylen, xlen;
ylen = maxy - ropts->boff - ropts->toff + 1;
ylen = maxy + 1;
if(ylen < 0){
ylen = maxy - ropts->toff;
ylen = maxy;
if(ylen < 0){
ylen = 0; // but this translates to a full-screen window...FIXME
}
}
xlen = maxx - ropts->roff - ropts->loff + 1;
xlen = maxx + 1;
if(xlen < 0){
xlen = maxx - ropts->loff;
xlen = maxx;
if(xlen < 0){
xlen = 0; // FIXME see above...
}
}
if((nr->p = ncplane_new(w->nc, ylen, xlen, ropts->toff + wy, ropts->loff + wx, NULL)) == NULL){
if((nr->p = ncplane_new(w->nc, ylen, xlen, wy, wx, NULL)) == NULL){
free(nr);
return NULL;
}

View File

@ -9,10 +9,6 @@ ncreel_options NcReel::default_options = {
/* min_supported_rows */ 0,
/* max_supported_cols */ 0,
/* max_supported_rows */ 0,
/* toff */ 0,
/* roff */ 0,
/* boff */ 0,
/* loff */ 0,
/* bordermask */ NCBox::MaskBottom | NCBox::MaskTop | NCBox::MaskRight | NCBox::MaskLeft,
/* borderchan */ 0,
/* tabletmask */ 0,

View File

@ -45,53 +45,20 @@ int tabletfxn(struct nctablet* _t, int begx, int begy, int maxx, int maxy,
void usage(const char* argv0, std::ostream& c, int status){
c << "usage: " << argv0 << " [ -h ] | options\n";
c << " --ot: offset from top\n";
c << " --ob: offset from bottom\n";
c << " --ol: offset from left\n";
c << " --or: offset from right\n";
c << " -b bordermask: hex ncreel border mask (0x0..0xf)\n";
c << " -t tabletmask: hex tablet border mask (0x0..0xf)" << std::endl;
exit(status);
}
constexpr int OPT_TOPOFF = 100;
constexpr int OPT_BOTTOMOFF = 101;
constexpr int OPT_LEFTOFF = 102;
constexpr int OPT_RIGHTOFF = 103;
void parse_args(int argc, char** argv, struct notcurses_options* opts,
struct ncreel_options* ropts){
const struct option longopts[] = {
{ .name = "ot", .has_arg = 1, .flag = nullptr, .val = OPT_TOPOFF, },
{ .name = "ob", .has_arg = 1, .flag = nullptr, .val = OPT_BOTTOMOFF, },
{ .name = "ol", .has_arg = 1, .flag = nullptr, .val = OPT_LEFTOFF, },
{ .name = "or", .has_arg = 1, .flag = nullptr, .val = OPT_RIGHTOFF, },
{ .name = nullptr, .has_arg = 0, .flag = nullptr, .val = 0, },
};
int c;
while((c = getopt_long(argc, argv, "b:t:h", longopts, nullptr)) != -1){
switch(c){
case OPT_BOTTOMOFF:{
std::stringstream ss;
ss << optarg;
ss >> ropts->boff;
break;
}case OPT_TOPOFF:{
std::stringstream ss;
ss << optarg;
ss >> ropts->toff;
break;
}case OPT_LEFTOFF:{
std::stringstream ss;
ss << optarg;
ss >> ropts->loff;
break;
}case OPT_RIGHTOFF:{
std::stringstream ss;
ss << optarg;
ss >> ropts->roff;
break;
}case 'b':{
case 'b':{
std::stringstream ss;
ss << std::hex << optarg;
ss >> ropts->bordermask;
@ -130,7 +97,6 @@ int runreels(NotCurses& nc, ncreel_options& nopts){
channels_set_fg(&nopts.focusedchan, 0xffffff);
channels_set_bg(&nopts.focusedchan, 0x00c080);
channels_set_fg(&nopts.borderchan, 0x00c080);
nopts.toff = 3;
std::shared_ptr<NcReel> nr(n->ncreel_create(&nopts));
if(!nr || !nc.render()){
return -1;