From 87a738161a5f48e71d323a4c3c899f1aa3712af3 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Sun, 29 Jan 2017 17:56:59 +0100 Subject: Factor out app_fitting_items() --- nncmpp.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/nncmpp.c b/nncmpp.c index e26df06..0b651ac 100644 --- a/nncmpp.c +++ b/nncmpp.c @@ -1135,11 +1135,17 @@ app_draw_header (void) app_flush_header (&buf, attrs[false]); } +static int +app_fitting_items (void) +{ + // The raw number of items that would have fit on the terminal + return LINES - g.header_height; +} + static int app_visible_items (void) { - // This may eventually include a header bar and/or a status bar - return MAX (0, LINES - g.header_height); + return MAX (0, app_fitting_items ()); } static void @@ -1220,8 +1226,8 @@ app_draw_view (void) bool want_scrollbar = (int) tab->item_count > app_visible_items (); int view_width = COLS - want_scrollbar; - int to_show = MIN (LINES - g.header_height, - (int) tab->item_count - tab->item_top); + int to_show = + MIN (app_fitting_items (), (int) tab->item_count - tab->item_top); for (int row = 0; row < to_show; row++) { int item_index = tab->item_top + row; @@ -1560,12 +1566,12 @@ app_process_action (enum action action) break; case ACTION_GOTO_PAGE_PREVIOUS: - app_scroll ((int) g.header_height - LINES); - app_move_selection ((int) g.header_height - LINES); + app_scroll (-app_fitting_items ()); + app_move_selection (-app_fitting_items ()); break; case ACTION_GOTO_PAGE_NEXT: - app_scroll (LINES - (int) g.header_height); - app_move_selection (LINES - (int) g.header_height); + app_scroll (app_fitting_items ()); + app_move_selection (app_fitting_items ()); break; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.3-70-g09d2