[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master ce0f83e 8/9: Clip variable-width columns in w
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master ce0f83e 8/9: Clip variable-width columns in wx_table_generator |
Date: |
Fri, 9 Feb 2018 17:39:17 -0500 (EST) |
branch: master
commit ce0f83ee225b3f0330578e2237d05ff7c4ddb198
Author: Vadim Zeitlin <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Clip variable-width columns in wx_table_generator
This prevents the, potentially arbitrarily long, contents of such
columns from overflowing into the next (and possibly even subsequent)
column(s), making the output completely unreadable.
There is currently no indication that the truncation has occurred, we
might want to show it in some way in the future, e.g. by appending "…"
(U+2026) to the column contents in this case.
---
wx_table_generator.cpp | 23 ++++++++++++++++++++++-
wx_table_generator.hpp | 11 +++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/wx_table_generator.cpp b/wx_table_generator.cpp
index e4e7b6e..78c73cb 100644
--- a/wx_table_generator.cpp
+++ b/wx_table_generator.cpp
@@ -306,7 +306,28 @@ void wx_table_generator::do_output_values
}
}
- dc_.DrawText(s, x_text, y_text);
+ // Tiny helper to avoid duplicating the same DrawText() call in
+ // both branches of the "if" statement below. It might not be that
+ // useful now, but could become so if this simple DrawText() gets
+ // more complicated in the future.
+ auto const do_output = [=]() { dc_.DrawText(s, x_text, y_text); };
+
+ if(ci.needs_clipping())
+ {
+ wxDCClipper clip
+ (dc_
+ ,wxRect
+ {wxPoint{x, y_top}
+ ,wxSize{width - column_margin_, row_height_}
+ }
+ );
+
+ do_output();
+ }
+ else
+ {
+ do_output();
+ }
}
x += width;
if(draw_separators_)
diff --git a/wx_table_generator.hpp b/wx_table_generator.hpp
index aa31a52..1bbe471 100644
--- a/wx_table_generator.hpp
+++ b/wx_table_generator.hpp
@@ -186,6 +186,17 @@ class wx_table_generator
return !is_variable_width_;
}
+ // Return true if the contents of this column needs to be clipped when
+ // outputting it.
+ bool needs_clipping() const
+ {
+ // Variable width columns can have practically unlimited length and
+ // hence overflow into the next column or even beyond and must be
+ // clipped to prevent this from happening. Fixed width columns are
+ // not supposed to overflow anyhow, so clipping them is
unnecessary.
+ return is_variable_width_;
+ }
+
std::string const header_;
// Note that this field is modified directly by wx_table_generator code
- [lmi-commits] [lmi] master updated (246f754 -> 76bcb28), Greg Chicares, 2018/02/09
- [lmi-commits] [lmi] master 2c2145d 3/9: Fix closing brace indentation in wx_table_generator.cpp, Greg Chicares, 2018/02/09
- [lmi-commits] [lmi] master 4b75c18 5/9: Add a comment explaining why column_info::width_ is not const, Greg Chicares, 2018/02/09
- [lmi-commits] [lmi] master 11da7b5 1/9: Extract get_needed_pages_count() from PDF generation code, Greg Chicares, 2018/02/09
- [lmi-commits] [lmi] master 58c87b5 7/9: Make column_info::is_variable_width_ field private, Greg Chicares, 2018/02/09
- [lmi-commits] [lmi] master 76bcb28 9/9: Avoid passing an enum by const value, Greg Chicares, 2018/02/09
- [lmi-commits] [lmi] master ce0f83e 8/9: Clip variable-width columns in wx_table_generator,
Greg Chicares <=
- [lmi-commits] [lmi] master 8c1e124 2/9: Add simple unit test for get_needed_pages_count(), Greg Chicares, 2018/02/09
- [lmi-commits] [lmi] master 79144a7 4/9: Make unchangeable wx_table_generator::column_info fields const, Greg Chicares, 2018/02/09
- [lmi-commits] [lmi] master 2b0c1fd 6/9: Replace column_info::is_centered_ with is_centered(), Greg Chicares, 2018/02/09