diff --git a/src/ui/core.c b/src/ui/core.c index 22708464..1361b106 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -128,7 +128,7 @@ ui_update(void) { ProfWin *current = wins_get_current(); if (current->layout->scroll == TRUE) { - win_move_to_end(current); + win_scroll(current); } win_update_virtual(current); diff --git a/src/ui/window.c b/src/ui/window.c index 906bf89f..82aa59b0 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -464,11 +464,26 @@ win_free(ProfWin* window) free(window); } +static gboolean +_scrollable(ProfWin *window) +{ + int win_rows = getmaxy(stdscr); + int page_start = window->layout->display_start; + int curr_row = getcury(window->layout->win); + + if (curr_row - page_start < win_rows) { + return TRUE; + } else { + return FALSE; + } +} + + void win_page_up(ProfWin *window) { int *page_start = &(window->layout->display_start); - int page_rows = getmaxy(stdscr) - 4; + int page_rows = getmaxy(stdscr) - 3; *page_start -= page_rows; @@ -477,54 +492,32 @@ win_page_up(ProfWin *window) *page_start = 0; } - window->layout->scroll = FALSE; + window->layout->scroll = _scrollable(window); win_update_virtual(window); - - // switch off page if last line and space line visible - int curr_row = getcury(window->layout->win); - if (curr_row - *page_start == page_rows) { - window->layout->scroll = TRUE; - } } void win_page_down(ProfWin *window) { - window->layout->scroll = TRUE; - int *page_start = &(window->layout->display_start); - int page_rows = getmaxy(stdscr) - 4; + int page_rows = getmaxy(stdscr) - 3; int curr_row = getcury(window->layout->win); - if (curr_row - *page_start < page_rows) { - return; - } - *page_start += page_rows; - // only got half a screen, show full screen - if (curr_row - *page_start < page_rows) { - *page_start = curr_row - page_rows; - - // went past end, show full screen - } else if (*page_start >= curr_row) { - *page_start = curr_row - page_rows - 1; + // went past end, show last line + if (*page_start > curr_row) { + *page_start = curr_row - 1; } - window->layout->scroll = FALSE; + window->layout->scroll = _scrollable(window); win_update_virtual(window); - - // switch off page if last line and space line visible - if (curr_row - *page_start == page_rows) { - window->layout->scroll = TRUE; - } } void win_line_up(ProfWin *window) { int *page_start = &(window->layout->display_start); - int page_rows = getmaxy(stdscr) - 4; *page_start -= 1; @@ -533,14 +526,8 @@ win_line_up(ProfWin *window) *page_start = 0; } - window->layout->scroll = FALSE; + window->layout->scroll = _scrollable(window); win_update_virtual(window); - - // switch off page if last line and space line visible - int curr_row = getcury(window->layout->win); - if (curr_row - *page_start == page_rows) { - window->layout->scroll = TRUE; - } } void @@ -549,31 +536,41 @@ win_line_down(ProfWin *window) window->layout->scroll = TRUE; int *page_start = &(window->layout->display_start); - int page_rows = getmaxy(stdscr) - 4; +// int page_rows = getmaxy(stdscr) - 4; int curr_row = getcury(window->layout->win); - if (curr_row - *page_start < page_rows) { - return; - } - *page_start += 1; - // only got half a screen, show full screen - if (curr_row - *page_start < page_rows) { - *page_start = curr_row - page_rows; - - // went past end, show full screen - } else if (*page_start >= curr_row) { - *page_start = curr_row - page_rows - 1; + // went past end, show last line + if (*page_start > curr_row -1) { + *page_start = curr_row - 1; } - window->layout->scroll = FALSE; + window->layout->scroll = _scrollable(window); win_update_virtual(window); +} - // switch off page if last line and space line visible - if (curr_row - *page_start == page_rows) { - window->layout->scroll = TRUE; - } +void +win_scroll(ProfWin *window) +{ +// int page_rows = getmaxy(stdscr) - 4; +// int curr_row = getcury(window->layout->win); +// int *page_start = &(window->layout->display_start); +// +// if (curr_row > *page_start + page_rows) { +// *page_start = curr_row - page_rows; +// if (*page_start < 0) { +// *page_start = 0; +// } +// } +} + +void +win_clear(ProfWin *window) +{ + window->layout->display_start = getcury(window->layout->win); + window->layout->scroll = TRUE; + win_update_virtual(window); } void @@ -626,33 +623,6 @@ win_sub_page_up(ProfWin *window) win_update_virtual(window); } -void -win_move_to_end(ProfWin *window) -{ - window->layout->scroll = TRUE; - - int page_rows = getmaxy(stdscr) - 4; - int curr_row = getcury(window->layout->win); - int *page_start = &(window->layout->display_start); - - if (curr_row - *page_start < page_rows) { - return; - } - - *page_start = curr_row - page_rows; - if (*page_start < 0) { - *page_start = 0; - } -} - -void -win_clear(ProfWin *window) -{ - window->layout->display_start = getcury(window->layout->win); - window->layout->scroll = TRUE; - win_update_virtual(window); -} - void win_resize(ProfWin *window) { diff --git a/src/ui/window.h b/src/ui/window.h index 67955f7d..4b488331 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -54,7 +54,7 @@ #define PAD_SIZE 1000 -void win_move_to_end(ProfWin *window); +void win_scroll(ProfWin *window); void win_show_status_string(ProfWin *window, const char *const from, const char *const show, const char *const status, GDateTime *last_activity, const char *const pre,