[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master baa8825 5/6: Calculate the exact number of li
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master baa8825 5/6: Calculate the exact number of lines on the last page |
Date: |
Fri, 7 Sep 2018 19:33:54 -0400 (EDT) |
branch: master
commit baa8825be4fe31b29616f9eeb932438e056825ec
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Calculate the exact number of lines on the last page
---
report_table.cpp | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/report_table.cpp b/report_table.cpp
index 9ef9522..b201d0b 100644
--- a/report_table.cpp
+++ b/report_table.cpp
@@ -205,6 +205,7 @@ paginator::paginator(int total_rows, int rows_per_group,
int max_lines_per_page)
// If there are zero rows of data, then one empty page is wanted.
if(0 == total_rows_)
{
+ lines_on_last_page_ = 0;
page_count_ = 1;
return;
}
@@ -212,6 +213,13 @@ paginator::paginator(int total_rows, int rows_per_group,
int max_lines_per_page)
page_count_ = outward_quotient(total_rows_, rows_per_page_);
int const rows_on_last_page = total_rows_ - (page_count_ - 1) *
rows_per_page_;
+ int const full_groups_on_last_page = rows_on_last_page / rows_per_group_;
+ int const extra_rows_on_last_page = rows_on_last_page % rows_per_group_;
+ lines_on_last_page_ =
+ lines_per_group_ * full_groups_on_last_page
+ + extra_rows_on_last_page
+ - (0 == extra_rows_on_last_page)
+ ;
// Avoid widowing a partial group on the last page, by moving it
// to the preceding page (which becomes the last) if there's room.
@@ -222,6 +230,8 @@ paginator::paginator(int total_rows, int rows_per_group,
int max_lines_per_page)
if(rows_on_last_page <= free_lines)
{
--page_count_;
+ // "+ 1": separator before antiwidowed partial group.
+ lines_on_last_page_ = lines_on_full_page_ + 1 + rows_on_last_page;
}
}
}
- [lmi-commits] [lmi] master updated (7376c94 -> f27b89f), Greg Chicares, 2018/09/07
- [lmi-commits] [lmi] master 033d6b6 2/6: Avoid 'auto' where it is not helpful, Greg Chicares, 2018/09/07
- [lmi-commits] [lmi] master 2207a63 3/6: Refactor: move one line, for a reason soon to be revealed, Greg Chicares, 2018/09/07
- [lmi-commits] [lmi] master ef971ec 1/6: Move test_main function to end where it belongs, Greg Chicares, 2018/09/07
- [lmi-commits] [lmi] master baa8825 5/6: Calculate the exact number of lines on the last page,
Greg Chicares <=
- [lmi-commits] [lmi] master a873fa4 4/6: Introduce additional paginator data members, Greg Chicares, 2018/09/07
- [lmi-commits] [lmi] master f27b89f 6/6: Demonstrate pagination with the simplest possible control structure, Greg Chicares, 2018/09/07