Add convenience function ncplane_home(). Add an ncblitter_e param to ncplane_qrcode(), and split int maxversion into value-result int* ymax and int* xmax. Write the actual sizes of the resulting visual into these parameters. Update the qrcode demo. Add the qrcode PoC. Update demos to ncplane_home(), where possible. ncplane_qrcode() now takes an ncblitter_e and two value-result int*s in the place of a single value int. The final size of the displayed qrcode is written to *ymax and *xmax. If the code can't fit within the specified dimensions, an error is returned. Standard rules for pluggable blitters apply regarding fallback etc. #699pull/715/head
parent
22dc5014cc
commit
0084dbaa6d
@ -0,0 +1,47 @@
|
||||
#include <unistd.h>
|
||||
#include <locale.h>
|
||||
#include <notcurses/notcurses.h>
|
||||
|
||||
static int
|
||||
render_qrcode(struct ncplane* n, int dimy, int dimx, const char* text){
|
||||
int y = dimy, x = dimx;
|
||||
ncplane_home(n);
|
||||
int ver = ncplane_qrcode(n, NCBLIT_DEFAULT, &y, &x, text, strlen(text));
|
||||
if(ver < 0){
|
||||
return -1;
|
||||
}
|
||||
if(ncplane_putstr_yx(n, y + 1, 0, text) < 0){
|
||||
return -1;
|
||||
}
|
||||
if(notcurses_render(ncplane_notcurses(n))){
|
||||
return -1;
|
||||
}
|
||||
sleep(2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, const char** argv){
|
||||
if(setlocale(LC_ALL, "") == NULL){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
struct notcurses_options opts = {
|
||||
.flags = NCOPTION_INHIBIT_SETLOCALE | NCOPTION_NO_ALTERNATE_SCREEN,
|
||||
};
|
||||
struct notcurses* nc = notcurses_init(&opts, NULL);
|
||||
int dimy, dimx;
|
||||
struct ncplane* std = notcurses_stddim_yx(nc, &dimy, &dimx);
|
||||
while(*++argv){
|
||||
if(render_qrcode(std, dimy, dimx, *argv)){
|
||||
notcurses_stop(nc);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
if(argc < 2){
|
||||
if(render_qrcode(std, dimy, dimx, "https://nick-black.com")){
|
||||
notcurses_stop(nc);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
notcurses_stop(nc);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in New Issue