mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 17:19:03 -04:00
[widgettrack] hook up nctabbed, nctree, ncreel, nc[ud]plot #2342
This commit is contained in:
parent
416f2eb6df
commit
bead8cbffc
@ -60,7 +60,7 @@ typedef struct ncmenu_options {
|
||||
|
||||
**bool ncmenu_offer_input(struct ncmenu* ***n***, const ncinput* ***nc***);**
|
||||
|
||||
**int ncmenu_destroy(struct ncmenu* ***n***);**
|
||||
**void ncmenu_destroy(struct ncmenu* ***n***);**
|
||||
|
||||
# DESCRIPTION
|
||||
|
||||
|
@ -55,7 +55,7 @@ typedef struct ncselector_options {
|
||||
|
||||
**bool ncselector_offer_input(struct ncselector* ***n***, const ncinput* ***nc***);**
|
||||
|
||||
**void ncselector_destroy(struct ncselector* ***n***, char\*\* ***item***);**
|
||||
**void ncselector_destroy(struct ncselector* ***n***);**
|
||||
|
||||
# DESCRIPTION
|
||||
|
||||
|
@ -38,7 +38,7 @@ namespace ncpp
|
||||
~Selector ()
|
||||
{
|
||||
if (!is_notcurses_stopped ())
|
||||
ncselector_destroy (selector, nullptr);
|
||||
ncselector_destroy (selector);
|
||||
}
|
||||
|
||||
int additem (const ncselector_item *item) const NOEXCEPT_MAYBE
|
||||
|
@ -3608,9 +3608,8 @@ API const char* ncselector_nextitem(struct ncselector* n)
|
||||
API bool ncselector_offer_input(struct ncselector* n, const ncinput* nc)
|
||||
__attribute__ ((nonnull (1, 2)));
|
||||
|
||||
// Destroy the ncselector. If 'item' is not NULL, the last selected option will
|
||||
// be strdup()ed and assigned to '*item' (and must be free()d by the caller).
|
||||
API void ncselector_destroy(struct ncselector* n, char** item);
|
||||
// Destroy the ncselector.
|
||||
API void ncselector_destroy(struct ncselector* n);
|
||||
|
||||
struct ncmselector_item {
|
||||
const char* option;
|
||||
@ -3825,7 +3824,7 @@ API bool ncmenu_offer_input(struct ncmenu* n, const ncinput* nc)
|
||||
__attribute__ ((nonnull (1, 2)));
|
||||
|
||||
// Destroy a menu created with ncmenu_create().
|
||||
API int ncmenu_destroy(struct ncmenu* n);
|
||||
API void ncmenu_destroy(struct ncmenu* n);
|
||||
|
||||
// Progress bars. They proceed linearly in any of four directions. The entirety
|
||||
// of the plane will be used -- any border should be provided by the caller on
|
||||
|
@ -429,7 +429,7 @@ reader_demo(struct notcurses* nc){
|
||||
}
|
||||
|
||||
done:
|
||||
ncselector_destroy(selector, NULL);
|
||||
ncselector_destroy(selector);
|
||||
ncmultiselector_destroy(mselector);
|
||||
ncplane_destroy(rp);
|
||||
return ret;
|
||||
|
@ -412,7 +412,7 @@ ncmenu* ncmenu_create(ncplane* n, const ncmenu_options* opts){
|
||||
};
|
||||
ret->ncp = ncplane_create(n, &nopts);
|
||||
if(ret->ncp){
|
||||
ncplane_set_widget(ret->ncp, ret, ncmenu_destroy);
|
||||
ncplane_set_widget(ret->ncp, ret, (void(*)(void*))ncmenu_destroy);
|
||||
ret->unrolledsection = -1;
|
||||
ret->headerchannels = opts->headerchannels;
|
||||
ret->dissectchannels = opts->headerchannels;
|
||||
@ -766,8 +766,7 @@ ncplane* ncmenu_plane(ncmenu* menu){
|
||||
return menu->ncp;
|
||||
}
|
||||
|
||||
int ncmenu_destroy(ncmenu* n){
|
||||
int ret = 0;
|
||||
void ncmenu_destroy(ncmenu* n){
|
||||
if(n){
|
||||
free_menu_sections(n);
|
||||
if(ncplane_set_widget(n->ncp, NULL, NULL) == 0){
|
||||
@ -775,5 +774,4 @@ int ncmenu_destroy(ncmenu* n){
|
||||
}
|
||||
free(n);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -531,6 +531,7 @@ create_##T(nc##X##plot* ncpp, ncplane* n, const ncplot_options* opts, const T mi
|
||||
} \
|
||||
} \
|
||||
redraw_plot_##T(ncpp); \
|
||||
ncplane_set_widget(ncpp->plot.ncp, ncpp, (void(*)(void*))nc##X##plot_destroy); \
|
||||
return bset; \
|
||||
} \
|
||||
/* if x is less than the window, return -1, as the sample will be thrown away. \
|
||||
@ -606,7 +607,9 @@ CREATE(double, d)
|
||||
static void
|
||||
ncplot_destroy(ncplot* n){
|
||||
free(n->title);
|
||||
ncplane_destroy(n->ncp);
|
||||
if(ncplane_set_widget(n->ncp, NULL, NULL) == 0){
|
||||
ncplane_destroy(n->ncp);
|
||||
}
|
||||
ncplane_destroy(n->pixelp);
|
||||
free(n->channels);
|
||||
}
|
||||
|
@ -781,6 +781,7 @@ ncreel* ncreel_create(ncplane* n, const ncreel_options* ropts){
|
||||
free(nr);
|
||||
return NULL;
|
||||
}
|
||||
ncplane_set_widget(nr->p, nr, (void(*)(void*))ncreel_destroy);
|
||||
return nr;
|
||||
}
|
||||
|
||||
@ -857,7 +858,9 @@ void ncreel_destroy(ncreel* nreel){
|
||||
while( (t = nreel->tablets) ){
|
||||
ncreel_del(nreel, t);
|
||||
}
|
||||
ncplane_destroy(nreel->p);
|
||||
if(ncplane_set_widget(nreel->p, NULL, NULL) == 0){
|
||||
ncplane_destroy(nreel->p);
|
||||
}
|
||||
free(nreel);
|
||||
}
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ ncselector* ncselector_create(ncplane* n, const ncselector_options* opts){
|
||||
goto freeitems;
|
||||
}
|
||||
ncselector_draw(ns); // deal with error here?
|
||||
ncplane_set_widget(ns->ncp, ns, ncselector_destroy);
|
||||
ncplane_set_widget(ns->ncp, ns, (void(*)(void*))ncselector_destroy);
|
||||
return ns;
|
||||
|
||||
freeitems:
|
||||
@ -549,12 +549,8 @@ bool ncselector_offer_input(ncselector* n, const ncinput* nc){
|
||||
return false;
|
||||
}
|
||||
|
||||
void ncselector_destroy(ncselector* n, char** item){
|
||||
void ncselector_destroy(ncselector* n){
|
||||
if(n){
|
||||
if(item){
|
||||
*item = n->items[n->selected].option;
|
||||
n->items[n->selected].option = NULL;
|
||||
}
|
||||
while(n->itemcount--){
|
||||
free(n->items[n->itemcount].option);
|
||||
free(n->items[n->itemcount].desc);
|
||||
@ -948,7 +944,7 @@ ncmultiselector* ncmultiselector_create(ncplane* n, const ncmultiselector_option
|
||||
goto freeitems;
|
||||
}
|
||||
ncmultiselector_draw(ns); // deal with error here?
|
||||
ncplane_set_widget(ns->ncp, ns, ncmultiselector_destroy);
|
||||
ncplane_set_widget(ns->ncp, ns, (void(*)(void*))ncmultiselector_destroy);
|
||||
return ns;
|
||||
|
||||
freeitems:
|
||||
|
@ -223,6 +223,7 @@ nctabbed* nctabbed_create(ncplane* n, const nctabbed_options* topts){
|
||||
}
|
||||
}
|
||||
nctabbed_redraw(nt);
|
||||
ncplane_set_widget(nt->p, nt, (void(*)(void*))nctabbed_destroy);
|
||||
return nt;
|
||||
}
|
||||
|
||||
@ -424,7 +425,9 @@ void nctabbed_destroy(nctabbed* nt){
|
||||
free(t);
|
||||
t = tmp;
|
||||
}
|
||||
ncplane_destroy_family(nt->ncp);
|
||||
if(ncplane_set_widget(nt->ncp, NULL, NULL) == 0){
|
||||
ncplane_destroy_family(nt->ncp);
|
||||
}
|
||||
free(nt->opts.separator);
|
||||
free(nt);
|
||||
}
|
||||
|
@ -117,6 +117,7 @@ nctree_inner_create(ncplane* n, const nctree_options* opts){
|
||||
}
|
||||
ret->items.ncp = n;
|
||||
ret->items.curry = NULL;
|
||||
ncplane_set_widget(n, ret, (void(*)(void*))nctree_destroy);
|
||||
nctree_redraw(ret);
|
||||
}
|
||||
return ret;
|
||||
@ -153,6 +154,9 @@ error:
|
||||
void nctree_destroy(nctree* n){
|
||||
if(n){
|
||||
free_tree_items(&n->items);
|
||||
if(ncplane_set_widget(n->items.ncp, NULL, NULL) == 0){
|
||||
ncplane_destroy(n->items.ncp);
|
||||
}
|
||||
free(n->currentpath);
|
||||
free(n);
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ run_selector(struct notcurses* nc, struct ncselector* ns){
|
||||
continue;
|
||||
}
|
||||
switch(keypress){
|
||||
case NCKEY_ENTER: ncselector_destroy(ns, NULL); return;
|
||||
case 'M': case 'J': if(ni.ctrl){ ncselector_destroy(ns, NULL); return; }
|
||||
case NCKEY_ENTER: ncselector_destroy(ns); return;
|
||||
case 'M': case 'J': if(ni.ctrl){ ncselector_destroy(ns); return; }
|
||||
}
|
||||
if(keypress == 'q'){
|
||||
break;
|
||||
@ -48,7 +48,7 @@ run_selector(struct notcurses* nc, struct ncselector* ns){
|
||||
}
|
||||
notcurses_render(nc);
|
||||
}
|
||||
ncselector_destroy(ns, NULL);
|
||||
ncselector_destroy(ns);
|
||||
}
|
||||
|
||||
int main(void){
|
||||
|
@ -32,7 +32,7 @@ TEST_CASE("Selectors") {
|
||||
ncplane_dim_yx(ncsp, &dimy, &dimx);
|
||||
CHECK(4 == dimy);
|
||||
CHECK(5 == dimx);
|
||||
ncselector_destroy(ncs, nullptr);
|
||||
ncselector_destroy(ncs);
|
||||
}
|
||||
|
||||
SUBCASE("TitledSelector") {
|
||||
@ -57,7 +57,7 @@ TEST_CASE("Selectors") {
|
||||
ncplane_dim_yx(ncsp, &dimy, &dimx);
|
||||
CHECK(6 == dimy);
|
||||
CHECK(strlen(opts.title) + 4 == dimx);
|
||||
ncselector_destroy(ncs, nullptr);
|
||||
ncselector_destroy(ncs);
|
||||
}
|
||||
|
||||
SUBCASE("SecondarySelector") {
|
||||
@ -82,7 +82,7 @@ TEST_CASE("Selectors") {
|
||||
ncplane_dim_yx(ncsp, &dimy, &dimx);
|
||||
CHECK(4 == dimy);
|
||||
CHECK(strlen(opts.secondary) + 2 == dimx);
|
||||
ncselector_destroy(ncs, nullptr);
|
||||
ncselector_destroy(ncs);
|
||||
}
|
||||
|
||||
SUBCASE("FooterSelector") {
|
||||
@ -107,7 +107,7 @@ TEST_CASE("Selectors") {
|
||||
ncplane_dim_yx(ncsp, &dimy, &dimx);
|
||||
CHECK(4 == dimy);
|
||||
CHECK(strlen(opts.footer) + 2 == dimx);
|
||||
ncselector_destroy(ncs, nullptr);
|
||||
ncselector_destroy(ncs);
|
||||
}
|
||||
|
||||
SUBCASE("PopulatedSelector") {
|
||||
@ -137,7 +137,7 @@ TEST_CASE("Selectors") {
|
||||
ncplane_dim_yx(ncsp, &dimy, &dimx);
|
||||
CHECK(7 == dimy);
|
||||
CHECK(15 < dimx);
|
||||
ncselector_destroy(ncs, nullptr);
|
||||
ncselector_destroy(ncs);
|
||||
}
|
||||
|
||||
SUBCASE("EmptySelectorMovement") {
|
||||
@ -162,7 +162,7 @@ TEST_CASE("Selectors") {
|
||||
sel = ncselector_previtem(ncs);
|
||||
REQUIRE(nullptr == sel);
|
||||
CHECK(0 == notcurses_render(nc_));
|
||||
ncselector_destroy(ncs, nullptr);
|
||||
ncselector_destroy(ncs);
|
||||
}
|
||||
|
||||
SUBCASE("SelectorMovement") {
|
||||
@ -207,7 +207,7 @@ TEST_CASE("Selectors") {
|
||||
REQUIRE(nullptr != sel);
|
||||
CHECK(0 == strcmp(sel, items[0].option));
|
||||
CHECK(0 == notcurses_render(nc_));
|
||||
ncselector_destroy(ncs, nullptr);
|
||||
ncselector_destroy(ncs);
|
||||
}
|
||||
|
||||
// Provide three items, limited to 1 shown at a time
|
||||
@ -259,7 +259,7 @@ TEST_CASE("Selectors") {
|
||||
unsigned dimy, dimx;
|
||||
ncplane_dim_yx(ncsp, &dimy, &dimx);
|
||||
CHECK(5 == dimy);
|
||||
ncselector_destroy(ncs, nullptr);
|
||||
ncselector_destroy(ncs);
|
||||
}
|
||||
|
||||
// Provide three items, limited to 2 shown at a time
|
||||
@ -310,7 +310,7 @@ TEST_CASE("Selectors") {
|
||||
unsigned dimy, dimx;
|
||||
ncplane_dim_yx(ncsp, &dimy, &dimx);
|
||||
CHECK(6 == dimy);
|
||||
ncselector_destroy(ncs, nullptr);
|
||||
ncselector_destroy(ncs);
|
||||
}
|
||||
|
||||
CHECK(0 == notcurses_stop(nc_));
|
||||
|
Loading…
x
Reference in New Issue
Block a user