download, progress, improved screen updates...
[oftp] / src / tui.c
index 106b28f..3ad62eb 100644 (file)
--- a/src/tui.c
+++ b/src/tui.c
@@ -6,6 +6,7 @@
 #include "tuipriv.h"
 #include "tgfx.h"
 #include "darray.h"
+#include "util.h"
 
 
 int tui_init(void)
@@ -78,6 +79,16 @@ struct tui_widget *tui_parent(struct tui_widget *w)
        return w->par;
 }
 
+void tui_invalidate(struct tui_widget *w)
+{
+       w->dirty = 1;
+}
+
+int tui_isdirty(struct tui_widget *w)
+{
+       return w->dirty;
+}
+
 void tui_draw(struct tui_widget *w)
 {
        struct tui_widget *iter;
@@ -85,6 +96,7 @@ void tui_draw(struct tui_widget *w)
        if(w->cbfunc[TUI_DRAW]) {
                w->cbfunc[TUI_DRAW](w, 0);
        }
+       w->dirty = 0;
 
        iter = w->child;
        while(iter) {
@@ -101,6 +113,36 @@ void tui_set_callback(struct tui_widget *w, int type, tui_callback func, void *c
        w->cbcls[type] = cls;
 }
 
+void tui_call_callback(struct tui_widget *w, int type)
+{
+       if(w->cbfunc[type]) {
+               w->cbfunc[type](w, w->cbcls[type]);
+       }
+}
+
+void tui_focus(struct tui_widget *w, int focus)
+{
+       focus = focus ? 1 : 0;
+       if(w->focus == focus) {
+               return;
+       }
+       w->focus = focus;
+       w->dirty = 1;
+       tui_call_callback(w, TUI_ONFOCUS);
+}
+
+int tui_set_title(struct tui_widget *w, const char *s)
+{
+       free(w->title);
+       w->title = strdup_nf(s);
+       return 0;
+}
+
+const char *tui_get_title(struct tui_widget *w)
+{
+       return w->title;
+}
+
 struct tui_widget *tui_window(const char *title, int x, int y, int width, int height)
 {
        struct tui_widget *w;
@@ -169,9 +211,6 @@ void tui_status(int type, const char *fmt, ...)
 void tui_vstatus(int type, const char *fmt, va_list ap)
 {
        /* TODO */
-       tg_color(15);
-       tg_bgcolor(0);
-       tg_vtext(0, 25, fmt, ap);
 }
 
 void tui_msgbox(int type, const char *title, const char *msg, ...)
@@ -185,7 +224,4 @@ void tui_msgbox(int type, const char *title, const char *msg, ...)
 void tui_vmsgbox(int type, const char *title, const char *msg, va_list ap)
 {
        /* TODO */
-       tg_color(15);
-       tg_bgcolor(0);
-       tg_vtext(0, 25, msg, ap);
 }