lmi-commits
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]