[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master f0673e0 5/6: Fix the problem analyzed in the
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master f0673e0 5/6: Fix the problem analyzed in the penultimate commit |
Date: |
Wed, 22 Aug 2018 19:18:24 -0400 (EDT) |
branch: master
commit f0673e01ecba7908cd93833c502e8b8df3073ef0
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Fix the problem analyzed in the penultimate commit
The code being worked on contained a block comment that suggested a
design regret, so the time is ripe to "refactor mercilessly". This
commit includes a proposed simplification for one function, which is
for the moment asserted to do the same thing as the original; after
testing, the original will be removed, in the next commit.
---
wx_table_generator.cpp | 28 +++++++++++++++++++++-------
wx_table_generator.hpp | 1 +
2 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/wx_table_generator.cpp b/wx_table_generator.cpp
index c5232d2..61aa9fc 100644
--- a/wx_table_generator.cpp
+++ b/wx_table_generator.cpp
@@ -207,12 +207,7 @@ void wx_table_generator::output_super_header
return;
}
- // We don't have a function for getting the rectangle of a span of columns,
- // but we can reuse the existing cell_rect() if we just increase its width
- // by the width of all the extra (i.e. not counting the starting one)
- // columns in this span.
- auto rect = cell_rect(begin_column, pos_y);
- rect.width += cell_pos_x(end_column) - cell_pos_x(begin_column + 1);
+ auto rect = cell_rect(begin_column, end_column, pos_y);
for(auto const& i : lines)
{
@@ -519,12 +514,31 @@ int wx_table_generator::cell_pos_x(int column) const
wxRect wx_table_generator::cell_rect(int column, int y) const
{
LMI_ASSERT(column < lmi::ssize(all_columns()));
- return wxRect
+ wxRect rect0
(cell_pos_x(column)
,y
,all_columns().at(column).col_width()
,row_height_
);
+ LMI_ASSERT(cell_rect(column, 1 + column, y) == rect0);
+ return cell_rect(column, 1 + column, y);
+}
+
+/// Rectangle corresponding to a horizontal range of cells.
+
+wxRect wx_table_generator::cell_rect(int begin_column, int end_column, int y)
const
+{
+ LMI_ASSERT(begin_column <= end_column);
+ LMI_ASSERT(end_column <= lmi::ssize(all_columns()));
+
+ int const x1 = cell_pos_x(begin_column);
+ int x2 = x1;
+ for(int i = begin_column; i < end_column; ++i)
+ {
+ x2 += all_columns().at(i).col_width();
+ }
+
+ return wxRect(x1, y, x2 - x1, row_height_);
}
/// Font used for headers.
diff --git a/wx_table_generator.hpp b/wx_table_generator.hpp
index a43a47e..2e98ba2 100644
--- a/wx_table_generator.hpp
+++ b/wx_table_generator.hpp
@@ -145,6 +145,7 @@ class wx_table_generator
wxRect text_rect(int column, int y) const;
wxRect cell_rect(int column, int y) const;
+ wxRect cell_rect(int begin_column, int end_column, int y) const;
wxFont header_font() const;
- [lmi-commits] [lmi] master updated (d5a3be5 -> 4da8dbb), Greg Chicares, 2018/08/22
- [lmi-commits] [lmi] master 6330347 2/6: Assert an apparent requirement, Greg Chicares, 2018/08/22
- [lmi-commits] [lmi] master 1612829 3/6: Investigate failure of the assertion just added, Greg Chicares, 2018/08/22
- [lmi-commits] [lmi] master 4e69646 4/6: Work around the problem analyzed in the preceding commit, Greg Chicares, 2018/08/22
- [lmi-commits] [lmi] master 4da8dbb 6/6: Remove parallel implementation and its associated assertion, Greg Chicares, 2018/08/22
- [lmi-commits] [lmi] master 3f962fd 1/6: Make minimum margin a set_column_widths() argument, Greg Chicares, 2018/08/22
- [lmi-commits] [lmi] master f0673e0 5/6: Fix the problem analyzed in the penultimate commit,
Greg Chicares <=