17 void tui_shutdown(void)
22 struct tui_widget *tui_widget(int type)
26 if(!(w = calloc(1, sizeof *w))) {
33 void tui_free(struct tui_widget *w)
36 if(w->cbfunc[TUI_FREE]) {
37 w->cbfunc[TUI_FREE](w, 0);
44 void tui_add_widget(struct tui_widget *par, struct tui_widget *w)
46 if(w->par == par) return;
53 void tui_remove_widget(struct tui_widget *par, struct tui_widget *w)
55 struct tui_widget *iter, dummy;
58 fprintf(stderr, "failed to remove widget %p from %p\n", (void*)w, (void*)par);
62 dummy.next = par->child;
71 par->child = dummy.next;
77 struct tui_widget *tui_parent(struct tui_widget *w)
82 int tui_isdirty(struct tui_widget *w)
87 void tui_draw(struct tui_widget *w)
89 struct tui_widget *iter;
91 if(w->cbfunc[TUI_DRAW]) {
92 w->cbfunc[TUI_DRAW](w, 0);
105 void tui_set_callback(struct tui_widget *w, int type, tui_callback func, void *cls)
107 w->cbfunc[type] = func;
108 w->cbcls[type] = cls;
111 void tui_call_callback(struct tui_widget *w, int type)
113 if(w->cbfunc[type]) {
114 w->cbfunc[type](w, w->cbcls[type]);
118 void tui_focus(struct tui_widget *w, int focus)
120 focus = focus ? 1 : 0;
121 if(w->focus == focus) {
126 tui_call_callback(w, TUI_ONFOCUS);
129 int tui_set_title(struct tui_widget *w, const char *s)
132 w->title = strdup_nf(s);
136 const char *tui_get_title(struct tui_widget *w)
141 struct tui_widget *tui_window(const char *title, int x, int y, int width, int height)
143 struct tui_widget *w;
145 if(!(w = tui_widget(TUI_WINDOW))) {
148 w->title = strdup(title);
156 struct tui_widget *tui_button(const char *title, int x, int y, tui_callback cbfunc, void *cbdata)
158 struct tui_widget *w;
160 if(!(w = tui_widget(TUI_BUTTON))) {
163 w->title = strdup(title);
166 w->width = strlen(title) + 2;
170 tui_set_callback(w, TUI_ONCLICK, cbfunc, cbdata);
175 void tui_wtoscr(struct tui_widget *w, int x, int y, int *retx, int *rety)
186 void tui_scrtow(struct tui_widget *w, int x, int y, int *retx, int *rety)
198 void tui_status(int type, const char *fmt, ...)
202 tui_vstatus(type, fmt, ap);
206 void tui_vstatus(int type, const char *fmt, va_list ap)
211 tg_vtext(0, 25, fmt, ap);
214 void tui_msgbox(int type, const char *title, const char *msg, ...)
218 tui_vmsgbox(type, title, msg, ap);
222 void tui_vmsgbox(int type, const char *title, const char *msg, va_list ap)
227 tg_vtext(0, 25, msg, ap);