From: Andy Spencer Date: Sat, 8 Jun 2013 08:43:24 +0000 (+0000) Subject: Fix some resize issues X-Git-Url: http://pileus.org/git/?p=lackey;a=commitdiff_plain;h=95a4a1492b982e64458a2b0ed0260cf853c728a4 Fix some resize issues This adds a few curses like functions to view which can be used to resize windows that are at the bottom of the screen. It also removes the (useless) header window form the day and week views. --- diff --git a/src/main.c b/src/main.c index bec3b1c..af019b3 100644 --- a/src/main.c +++ b/src/main.c @@ -88,9 +88,10 @@ int main(int argc, char **argv) view_resize(); view_draw(); continue; - case '\14': + case '\14': // Ctrl-L clear(); - case '\7': + case '\7': // Ctrl-G + view_resize(); view_draw(); continue; } diff --git a/src/view.c b/src/view.c index 691154d..437e69c 100644 --- a/src/view.c +++ b/src/view.c @@ -174,6 +174,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 +206,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); } } diff --git a/src/view.h b/src/view.h index 845ca41..da63b8c 100644 --- a/src/view.h +++ b/src/view.h @@ -32,6 +32,10 @@ extern int COMPACT; extern int ACTIVE; +/* Curses functions */ +void wmvresize(WINDOW *win, int top, int left, int rows, int cols); +void wshrink(WINDOW *win, int top); + /* Helper functions */ void event_box(WINDOW *win, event_t *event, int y, int x, int h, int w); void event_line(WINDOW *win, event_t *event, int y, int x, int w, int full); diff --git a/views/day.c b/views/day.c index 672f855..d3ead1c 100644 --- a/views/day.c +++ b/views/day.c @@ -28,7 +28,6 @@ /* Static data */ static int line; static WINDOW *win; -static WINDOW *head; static WINDOW *times; static WINDOW *body; @@ -92,21 +91,18 @@ static int get_col(event_t **list, int n, event_t *event, int *ncols) /* Day init */ void day_init(WINDOW *_win) { - win = _win; // lines cols y x - head = derwin(win, 1, COLS, 0, 0); - times = derwin(win, LINES-2-2, 5, 2, 0); - body = derwin(win, LINES-2-2, COLS-6, 2, 6); + win = _win; // lines cols y x + times = derwin(win, LINES-2, 5, 0, 0); + body = derwin(win, LINES-2, COLS-5, 0, 5); line = 10*4; // 10:00 } /* Day size */ void day_size(int rows, int cols) { - mvderwin(times, 2-COMPACT, 0); - mvderwin(body, 2-COMPACT, 6); - wresize(head, 1, cols); - wresize(times, rows-2-COMPACT, 5); - wresize(body, rows-2-COMPACT, cols-6); + int hdr = 2-COMPACT; + wmvresize(times, hdr, 0, rows-hdr, 5); + wmvresize(body, hdr, 5, rows-hdr, cols-5); } /* Day draw */ @@ -115,12 +111,18 @@ void day_draw(void) const char *mstr = month_to_string(MONTH); const char *dstr = day_to_string(day_of_week(YEAR, MONTH, DAY)); - /* Print Header */ - if (COMPACT) wattron(head, A_REVERSE | A_BOLD); - mvwprintw(head, 0, 0, "%s, %s %-*d", dstr, mstr, COLS, DAY+1); - mvwprintw(head, 0, COLS-10, "%d-%02d-%02d", YEAR, MONTH, DAY+1); - if (COMPACT) wattroff(head, A_REVERSE | A_BOLD); + int y = !COMPACT+1; + /* Print Header */ + if (COMPACT) wattron(win, A_REVERSE | A_BOLD); + mvwhline(win, 0, 0, ' ', COLS); + mvwprintw(win, 0, 0, "%s, %s %d", dstr, mstr, DAY+1); + mvwprintw(win, 0, COLS-10, "%d-%02d-%02d", YEAR, MONTH, DAY+1); + if (COMPACT) wattroff(win, A_REVERSE | A_BOLD); + + /* Resize body */ + wshrink(times, y); + wshrink(body, y); /* Print times */ mvwprintw(times, 0, 0, "%02d:%02d", ((line/4)-1)%12+1, (line*15)%60); for (int h = 0; h < 24; h++) @@ -136,8 +138,8 @@ void day_draw(void) YEAR, MONTH, DAY, h+(m+15)/60, (m+15)%60)) { if (!before(&event->start, YEAR, MONTH, DAY, h, m)) { int col = get_col(active, N_ELEMENTS(active), event, &ncols); - int left = ROUND((col+0.0)*(COLS-6)/ncols); - int right = ROUND((col+1.0)*(COLS-6)/ncols); + int left = ROUND((col+0.0)*(COLS-6)/ncols) + 1; + int right = ROUND((col+1.0)*(COLS-6)/ncols) + 1; int row = h*4 + m/15 - line; int height = (get_mins(&event->start, &event->end)-1)/15+1; event_box(body, event, row, left, height, right-left); @@ -148,7 +150,7 @@ void day_draw(void) /* Print lines */ if (!COMPACT) mvwhline(win, 1, 0, ACS_HLINE, COLS); - mvwvline(win, 2-COMPACT, 5, ACS_VLINE, LINES-4+COMPACT+COMPACT); + mvwvline(body, 0, 0, ACS_VLINE, LINES-4+COMPACT+COMPACT); } /* Day run */ diff --git a/views/week.c b/views/week.c index b8b5127..1fe5e17 100644 --- a/views/week.c +++ b/views/week.c @@ -27,17 +27,15 @@ /* Static data */ static int line; static WINDOW *win; -static WINDOW *head; static WINDOW *times; static WINDOW *body; /* Week init */ void week_init(WINDOW *_win) { - win = _win; // lines cols y x - head = derwin(win, 2, COLS, 0, 0); - times = derwin(win, LINES-2-3, 5, 3, 0); - body = derwin(win, LINES-2-3, COLS-6, 3, 6); + win = _win; // lines cols y x + times = derwin(win, LINES-2, 5, 0, 0); + body = derwin(win, LINES-2, COLS-5, 0, 5); line = 10*4; // 10:00 } @@ -45,11 +43,8 @@ void week_init(WINDOW *_win) void week_size(int rows, int cols) { int hdr = 3-COMPACT; - wresize(head, 2, cols ); - wresize(times, rows-hdr, 5); - wresize(body, rows-hdr, cols-6); - mvderwin(times, hdr, 0); - mvderwin(body, hdr, 6); + wmvresize(times, hdr, 0, rows-hdr, 5); + wmvresize(body, hdr, 5, rows-hdr, cols-5); } /* Week draw */ @@ -67,32 +62,35 @@ void week_draw(void) add_days(&year, &month, &day, -shift); /* For today */ - int l = x+ROUND((shift+0)*hstep)-1; - int r = x+ROUND((shift+1)*hstep)-1; + int l = ROUND((shift+0)*hstep); + int r = ROUND((shift+1)*hstep); /* Print Header */ int rev = COMPACT ? A_REVERSE | A_BOLD : 0; - wattron(head, rev); - mvwprintw(head, 0, 0, "%-*s", COLS, month_to_str(MONTH)); - mvwprintw(head, 1, 0, "%-0*d", COLS, YEAR); - wattroff(head, rev); - mvwhline(head, 0, l+1, ' ', r-l-1); - mvwhline(head, 1, l+1, ' ', r-l-1); - wattron(head, rev); + wattron(win, rev); + mvwprintw(win, 0, 0, "%-*s", COLS, month_to_str(MONTH)); + mvwprintw(win, 1, 0, "%-0*d", COLS, YEAR); + wattroff(win, rev); + mvwhline(win, 0, x+l, ' ', r-l-1); + mvwhline(win, 1, x+l, ' ', r-l-1); + wattron(win, rev); for (int d = 0; d < 7; d++) { const char *str = hstep >= 10 ? day_to_string(d) : day_to_str(d); - if (d == shift) wattrset(head, A_BOLD); - mvwprintw(head, 0, x+ROUND(d*hstep), "%s", str); - mvwprintw(head, 1, x+ROUND(d*hstep), "%02d/%02d", month+1, day+1); - if (d == shift) wattrset(head, rev); + if (d == shift) wattrset(win, A_BOLD); + mvwprintw(win, 0, x+ROUND(d*hstep), "%s", str); + mvwprintw(win, 1, x+ROUND(d*hstep), "%02d/%02d", month+1, day+1); + if (d == shift) wattrset(win, rev); add_days(&year, &month, &day, 1); } - wattroff(head, rev); + wattroff(win, rev); + /* Resize body */ + wshrink(times, y-!COMPACT); + wshrink(body, y-!COMPACT); /* Print times */ - mvwprintw(times, 0, 0, "%02d:%02d", ((line/4)-1)%12+1, (line*15)%60); + mvwprintw(times, !COMPACT, 0, "%02d:%02d", ((line/4)-1)%12+1, (line*15)%60); for (int h = 0; h < 24; h++) - mvwprintw(times, h*4-line, 0, "%02d:%02d", (h-1)%12+1, 0); + mvwprintw(times, !COMPACT+h*4-line, 0, "%02d:%02d", (h-1)%12+1, 0); /* Print events */ event_t *event = EVENTS; @@ -103,30 +101,30 @@ void week_draw(void) while (event && before(&event->start, year, month, day, h+(m+15)/60, (m+15)%60)) { if (!before(&event->start, year, month, day, h, m)) { - int y = h*4 + m/15 - line; - int x = ROUND(d*hstep); + int y = h*4 + m/15 - line + !COMPACT; + int x = ROUND(d*hstep) + 1; int h = (get_mins(&event->start, &event->end)-1)/15+1; - int w = ROUND((d+1)*hstep) - 1 - x; + int w = ROUND((d+1)*hstep) - x; event_box(body, event, y, x, h, w); } event = event->next; } - /* Print lines */ + /* Print header lines */ if (!COMPACT) mvwhline(win, y-1, 0, ACS_HLINE, COLS); - for (int d = 0; d < 7; d++) - mvwvline(win, y, x+ROUND(d*hstep)-1, ACS_VLINE, LINES-y-2+COMPACT); - /* Draw today */ - if (!COMPACT) - mvwhline(win, y-1, l, ACS_BLOCK, r-l+1); - mvwvline_set(win, y, l, WACS_T_VLINE, LINES-y-2); - mvwvline_set(win, y, r, WACS_T_VLINE, LINES-y-2); + /* Print day lines */ + for (int d = 0; d < 7; d++) + mvwvline(body, !COMPACT, ROUND(d*hstep), ACS_VLINE, LINES-y-2+COMPACT); + mvwvline_set(body, 0, l, WACS_T_VLINE, LINES-y-1+COMPACT); + mvwvline_set(body, 0, r, WACS_T_VLINE, LINES-y-1+COMPACT); for (int h = (line+3)/4; h < 24; h++) { - mvwadd_wch(win, y+h*4-line, l, WACS_T_LTEE); - mvwadd_wch(win, y+h*4-line, r, WACS_T_RTEE); + mvwadd_wch(body, h*4-line+!COMPACT, l, WACS_T_LTEE); + mvwadd_wch(body, h*4-line+!COMPACT, r, WACS_T_RTEE); } + if (!COMPACT) + mvwhline(body, 0, l, ACS_BLOCK, r-l+1); } /* Week run */