X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=src%2Fview.c;h=3417676c783a7d163cc36bb612a1f186a94d81e2;hb=6ce9d3a06c405a01c05366689978daa60e225725;hp=6aa6f70126364436dfafcc68d53d2374a7de6f08;hpb=335d816efb8dd7c003e285a19e9434c4119ec13f;p=lackey diff --git a/src/view.c b/src/view.c index 6aa6f70..3417676 100644 --- a/src/view.c +++ b/src/view.c @@ -36,6 +36,23 @@ typedef struct { WINDOW *win; } view_t; +/* Macros */ +#define VIEW(name) \ + void name##_init(WINDOW *win); \ + void name##_size(int,int); \ + void name##_draw(void); \ + int name##_run(int,mmask_t,int,int) + +/* Prototypes */ +VIEW(day); +VIEW(week); +VIEW(month); +VIEW(year); +VIEW(events); +VIEW(todo); +VIEW(settings); +VIEW(help); + /* View data */ view_t views[] = { { "Day", day_init, day_size, day_draw, day_run, {KEY_F(1), '1', } }, @@ -75,9 +92,9 @@ static void draw_header(void) static int get_color(const char *cat) { return cat == NULL ? 0 : - !strcmp(cat, "class") ? COLOR_CLASS : - !strcmp(cat, "ec") ? COLOR_EC : - !strcmp(cat, "work") ? COLOR_WORK : COLOR_OTHER ; + match(cat, "class") ? COLOR_CLASS : + match(cat, "ec") ? COLOR_EC : + match(cat, "work") ? COLOR_WORK : COLOR_OTHER ; } /* Helper functions */ @@ -174,6 +191,29 @@ void todo_line(WINDOW *win, todo_t *todo, int y, int x, int w, int full) mvwprintw(win, y, x, "%s", desc); } +/* Curses functions */ +void wmvresize(WINDOW *win, int top, int left, int rows, int cols) +{ + int y = getpary(win); + if (top < y) + mvderwin(win, top, left); + wresize(win, rows, cols); + if (top > y) + mvderwin(win, top, left); +} + +void wshrink(WINDOW *win, int top) +{ + int x = getparx(win); + int y = getpary(win); + int r = getmaxy(win); + int c = getmaxx(win); + int rows = r + (y - top); + if (top < y) mvderwin(win, top, x); + if (rows != r) wresize(win, rows, c); + if (top > y) mvderwin(win, top, x); +} + /* View init */ void view_init(void) { @@ -183,6 +223,8 @@ void view_init(void) views[i].win = newwin(LINES-hdr, COLS, hdr, 0); views[i].init(views[i].win); } + if (views[i].size) + views[i].size(LINES-hdr, COLS); } }