16 void tui_shutdown(void)
21 struct tui_widget *tui_widget(int type)
25 if(!(w = calloc(1, sizeof *w))) {
32 void tui_free(struct tui_widget *w)
40 void tui_set_callback(struct tui_widget *w, int type, tui_callback func, void *cls)
42 w->cbfunc[type] = func;
46 struct tui_widget *tui_window(const char *title, int x, int y, int width, int height)
50 if(!(w = tui_widget(TUI_WINDOW))) {
53 w->title = strdup(title);
61 struct tui_widget *tui_button(const char *title, int x, int y, tui_callback cbfunc, void *cbdata)
65 if(!(w = tui_widget(TUI_BUTTON))) {
68 w->title = strdup(title);
71 w->width = strlen(title) + 2;
75 tui_set_callback(w, TUI_ONCLICK, cbfunc, cbdata);
80 struct tui_widget *tui_list(const char *title, int x, int y, int width, int height, tui_callback cbfunc, void *cbdata)
84 if(!(w = calloc(1, sizeof *w))) {
88 w->title = strdup(title);
95 tui_set_callback((struct tui_widget*)w, TUI_ONMODIFY, cbfunc, cbdata);
97 return (struct tui_widget*)w;
101 void tui_clear_list(struct tui_widget *w)
103 struct tui_list *wl = (struct tui_list*)w;
104 assert(wl->type == TUI_LIST);
105 darr_clear(wl->entries);
108 void tui_add_list_item(struct tui_widget *w, const char *text)
110 struct tui_list *wl = (struct tui_list*)w;
111 assert(wl->type == TUI_LIST);
112 darr_push(wl->entries, &text);