]> Pileus Git - lackey/commitdiff
Fix some resize issues
authorAndy Spencer <andy753421@gmail.com>
Sat, 8 Jun 2013 08:43:24 +0000 (08:43 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 10 Jun 2013 04:54:02 +0000 (04:54 +0000)
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.

src/main.c
src/view.c
src/view.h
views/day.c
views/week.c

index bec3b1c09616555ff72d6308a51735f92e056b69..af019b36d17f41953b0a05b1dd111fdab4dcba3b 100644 (file)
@@ -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;
                }
index 691154d07481d724cee3b01f06062e5d9e523bc4..437e69c1ec693e260afedf6d14988e31b40a5c10 100644 (file)
@@ -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);
        }
 }
 
index 845ca41daec0a9b81f562ac2fd22a4ecf8d56eca..da63b8c8179c5e9a7f8108225600bc1cc2736c41 100644 (file)
 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);
index 672f855cf66eddb26764fda74bc1f47719985597..d3ead1cd97eb980db033095dba479ebb11bdeec6 100644 (file)
@@ -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 */
index b8b512730601ed8fbf38098b144bd671174e0fa7..1fe5e17ec33ce1e665da0c23dc0dea0af24a522a 100644 (file)
 /* 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 */