lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 31048c8 047/156: Make wx_table_generator even


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 31048c8 047/156: Make wx_table_generator even more customizable
Date: Tue, 30 Jan 2018 17:22:07 -0500 (EST)

branch: master
commit 31048c877067197c3552b4a1e0b62b25688bba4f
Author: Vadim Zeitlin <address@hidden>
Commit: Vadim Zeitlin <address@hidden>

    Make wx_table_generator even more customizable
    
    Instead of just disabling separators, add a function for using
    "condensed style" which also uses smaller row height and avoids the use
    of bold font for the headers.
    
    Finally, allow using right alignment for the table columns: this is done
    in a separate function because it isn't really related to whether the
    style is condensed or not.
---
 wx_table_generator.cpp | 44 ++++++++++++++++++++++++++++++++++++--------
 wx_table_generator.hpp | 19 ++++++++++++++++---
 2 files changed, 52 insertions(+), 11 deletions(-)

diff --git a/wx_table_generator.cpp b/wx_table_generator.cpp
index 7c8a96f..c8a80e7 100644
--- a/wx_table_generator.cpp
+++ b/wx_table_generator.cpp
@@ -64,6 +64,18 @@ wx_table_generator::wx_table_generator
     dc_.SetPen(pen);
 }
 
+void wx_table_generator::use_condensed_style()
+{
+    row_height_ = char_height_;
+    draw_separators_ = false;
+    use_bold_headers_ = false;
+}
+
+void wx_table_generator::align_right()
+{
+    align_right_ = true;
+}
+
 void wx_table_generator::add_column
     (std::string const& header
     ,std::string const& widest_text
@@ -77,7 +89,11 @@ void wx_table_generator::add_column
         }
     else
         {
-        wxDCFontChanger set_header_font(dc_, get_header_font());
+        wxDCFontChanger set_header_font(dc_);
+        if(use_bold_headers_)
+            {
+            set_header_font.Set(get_header_font());
+            }
 
         // Set width to the special value of 0 for the variable width columns.
         width = widest_text.empty() ? 0 : dc_.GetTextExtent(widest_text).x;
@@ -236,16 +252,24 @@ void wx_table_generator::do_output_values
         if(!s.empty())
             {
             int x_text = x;
-            if(ci.is_centered_)
+
+            if(align_right_)
                 {
-                // Centre the text for the columns configured to do it.
-                x_text += (width - dc_.GetTextExtent(s).x) / 2;
+                x_text += width - dc_.GetTextExtent(s).x;
                 }
             else
                 {
-                // Otherwise just offset it by ~1 em.
-                x_text += dc_.GetTextExtent("M").x;
-                }
+                if(ci.is_centered_)
+                    {
+                    // Centre the text for the columns configured to do it.
+                    x_text += (width - dc_.GetTextExtent(s).x) / 2;
+                    }
+                else
+                    {
+                    // Otherwise just offset it by ~1 em.
+                    x_text += dc_.GetTextExtent("M").x;
+                    }
+            }
 
             dc_.DrawText(s, x_text, y_text);
             }
@@ -297,7 +321,11 @@ void wx_table_generator::output_header(int* pos_y)
 {
     do_compute_column_widths_if_necessary();
 
-    wxDCFontChanger set_header_font(dc_, get_header_font());
+    wxDCFontChanger set_header_font(dc_);
+    if(use_bold_headers_)
+        {
+        set_header_font.Set(get_header_font());
+        }
 
     // Split headers in single lines and fill up the entire columns*lines 2D
     // matrix, using empty strings for the headers with less than the maximal
diff --git a/wx_table_generator.hpp b/wx_table_generator.hpp
index 88b2633..e1da312 100644
--- a/wx_table_generator.hpp
+++ b/wx_table_generator.hpp
@@ -105,8 +105,14 @@ class wx_table_generator
     // output a separator after the last column.
     void output_vert_separator(std::size_t before_column, int y);
 
-    // Disable separator lines drawn by default.
-    void disable_separators() {draw_separators_ = false;}
+    // Use condensed style: don't draw separators between rows and make them
+    // smaller.
+    void use_condensed_style();
+
+    // By default, columns are centered if they have fixed size or left-aligned
+    // otherwise. By calling this method, this alignment auto-detection is
+    // turned off and all columns are right-aligned.
+    void align_right();
 
   private:
     // Return the font used for the headers.
@@ -132,7 +138,7 @@ class wx_table_generator
 
     // These values could be recomputed, but cache them for performance.
     int const char_height_;
-    int const row_height_;
+    int row_height_;
 
     struct column_info
     {
@@ -169,6 +175,13 @@ class wx_table_generator
     // drawn by calling output_horz_separator() or output_vert_separator()
     // explicitly).
     bool draw_separators_ = true;
+
+    // If true, headers are drawn in bold.
+    bool use_bold_headers_ = true;
+
+    // If true, force right alignment for all columns instead of centering them
+    // automatically if they have fixed size.
+    bool align_right_ = false;
 };
 
 #endif // wx_table_generator_hpp



reply via email to

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