pull/500/head
nick black 5 years ago committed by Nick Black
parent d9884a5f74
commit 6ec9b2d250

@ -219,7 +219,7 @@ int main(void){
popts.minchannel = popts.maxchannel = 0;
channels_set_fg_rgb(&popts.minchannel, 0x40, 0x50, 0xb0);
channels_set_fg_rgb(&popts.maxchannel, 0x40, 0xff, 0xd0);
popts.gridtype = static_cast<ncgridgeom_e>(NCPLOT_8x1);
popts.gridtype = static_cast<ncgridgeom_e>(NCPLOT_2x1);
plot = ncplot_create(pplane, &popts);
if(!plot){
return EXIT_FAILURE;

@ -19,6 +19,7 @@ redraw_plot(ncplot* n){
ncplane_erase(ncplot_plane(n));
int dimy, dimx;
ncplane_dim_yx(ncplot_plane(n), &dimy, &dimx);
const int scaleddim = dimx * geomdata[n->gridtype].width;
// each transition is worth this much change in value
const size_t states = wcslen(geomdata[n->gridtype].egcs);
// FIXME can we not rid ourselves of this meddlesome double?
@ -26,7 +27,7 @@ redraw_plot(ncplot* n){
const int startx = n->labelaxisd ? PREFIXSTRLEN : 0; // plot cols begin here
// if we want fewer slots than there are available columns, our final column
// will be other than the plane's final column. most recent x goes here.
const int finalx = (n->slotcount < dimx - 1 - startx ? startx + n->slotcount - 1 : dimx - 1);
const int finalx = (n->slotcount < scaleddim - 1 - (startx * geomdata[n->gridtype].width) ? startx + (n->slotcount / geomdata[n->gridtype].width) - 1 : dimx - 1);
if(n->labelaxisd){
// show the *top* of each interval range
for(int y = 0 ; y < dimy ; ++y){
@ -68,7 +69,7 @@ redraw_plot(ncplot* n){
}
intervalbase += (states * interval);
}
if(--idx < 0){
if((idx -= geomdata[n->gridtype].width) < 0){
idx = n->slotcount - 1;
}
}
@ -105,16 +106,20 @@ ncplot* ncplot_create(ncplane* n, const ncplot_options* opts){
ncplot* ret = malloc(sizeof(*ret));
if(ret){
ret->rangex = opts->rangex;
// if we're sizing the plot based off the plane dimensions, scale it by the
// plot geometry's width for all calculations
const int scaleddim = dimx * geomdata[opts->gridtype].width;
const int scaledprefixlen = PREFIXSTRLEN * geomdata[opts->gridtype].width;
if((ret->slotcount = ret->rangex) == 0){
ret->slotcount = dimx;
ret->slotcount = scaleddim;
}
if(dimx < ret->rangex){
ret->slotcount = dimx;
ret->slotcount = scaleddim;
}
if( (ret->labelaxisd = opts->labelaxisd) ){
if(ret->slotcount + PREFIXSTRLEN > dimx){
if(dimx > PREFIXSTRLEN){
ret->slotcount = dimx - PREFIXSTRLEN;
if(ret->slotcount + scaledprefixlen > scaleddim){
if(scaleddim > scaledprefixlen){
ret->slotcount = scaleddim - scaledprefixlen;
}
}
}

@ -0,0 +1,30 @@
#include <stdlib.h>
#include <locale.h>
#include <notcurses/notcurses.h>
int main(void){
setlocale(LC_ALL, "");
struct notcurses* nc = notcurses_init(NULL, stdout);
if(nc == NULL){
return EXIT_FAILURE;
}
int dimy, dimx, y, x;
struct ncplane* n = notcurses_stddim_yx(nc, &dimy, &dimx);
wchar_t wc = 0x4e00;
ncplane_set_scrolling(n, true);
while(true){
struct timespec req = { .tv_sec = 0, .tv_nsec = 1000000, };
nanosleep(&req, NULL);
if(ncplane_putwc(n, wc) <= 0){
break;
}
if(++wc == 0x9fa5){
wc = 0x4e00;
}
if(notcurses_render(nc)){
break;
}
}
notcurses_stop(nc);
return EXIT_FAILURE;
}
Loading…
Cancel
Save