← Back to team overview

kicad-developers team mailing list archive

[PATCH 2/4 (master)] Pcbnew: fix column width in Nets dialog.

 

Nets dialog (Inspect->List Nets) contains list control
that has very small width for first and last columns.
Changed algorithm for calculating optimal values for
column width.
---
 .../dialogs/dialog_select_net_from_list.cpp   | 49 +++++++++++++++----
 1 file changed, 39 insertions(+), 10 deletions(-)

diff --git a/pcbnew/dialogs/dialog_select_net_from_list.cpp b/pcbnew/dialogs/dialog_select_net_from_list.cpp
index 39a403b65..960c5afbd 100644
--- a/pcbnew/dialogs/dialog_select_net_from_list.cpp
+++ b/pcbnew/dialogs/dialog_select_net_from_list.cpp
@@ -42,6 +42,10 @@
 #include <pcb_painter.h>
 #include <connectivity_data.h>
 
+#define COLUMN_HEADER_NET   _( "Net" )
+#define COLUMN_HEADER_NAME  _( "Name" )
+#define COLUMN_HEADER_COUNT _( "Pad Count" )
+
 class DIALOG_SELECT_NET_FROM_LIST: public DIALOG_SELECT_NET_FROM_LIST_BASE
 {
 private:
@@ -93,9 +97,9 @@ DIALOG_SELECT_NET_FROM_LIST::DIALOG_SELECT_NET_FROM_LIST( PCB_EDIT_FRAME* aParen
     m_brd = aParent->GetBoard();
     m_wasSelected = false;
 
-    m_netsList->AppendTextColumn( _( "Net" ),       wxDATAVIEW_CELL_INERT, 0, wxALIGN_LEFT, 0 );
-    m_netsList->AppendTextColumn( _( "Name" ),      wxDATAVIEW_CELL_INERT, 0, wxALIGN_LEFT, 0 );
-    m_netsList->AppendTextColumn( _( "Pad Count" ), wxDATAVIEW_CELL_INERT, 0, wxALIGN_CENTER, 0 );
+    m_netsList->AppendTextColumn( COLUMN_HEADER_NET,   wxDATAVIEW_CELL_INERT, 0, wxALIGN_LEFT, 0 );
+    m_netsList->AppendTextColumn( COLUMN_HEADER_NAME,  wxDATAVIEW_CELL_INERT, 0, wxALIGN_LEFT, 0 );
+    m_netsList->AppendTextColumn( COLUMN_HEADER_COUNT, wxDATAVIEW_CELL_INERT, 0, wxALIGN_CENTER, 0 );
 
     // The fact that we're a list should keep the control from reserving space for the
     // expander buttons... but it doesn't.  Fix by forcing the indent to 0.
@@ -220,19 +224,44 @@ void DIALOG_SELECT_NET_FROM_LIST::onSelChanged( wxDataViewEvent&  )
 
 void DIALOG_SELECT_NET_FROM_LIST::adjustListColumns( int aWidth )
 {
+    int w0, w1, w2;
+
     if( aWidth == wxCOL_WIDTH_AUTOSIZE )
     {
-        m_netsList->GetColumn( 0 )->SetWidth( wxCOL_WIDTH_AUTOSIZE );
-        m_netsList->GetColumn( 0 )->SetWidth( m_netsList->GetColumn( 0 )->GetWidth() + 12 );
-        m_netsList->GetColumn( 2 )->SetWidth( wxCOL_WIDTH_AUTOSIZE );
-        m_netsList->GetColumn( 2 )->SetWidth( m_netsList->GetColumn( 2 )->GetWidth() + 12 );
+        /**
+         * Calculating optimal width of the first (Net) and
+         * the last (Pad Count) columns. That width must be
+         * enough to fit column header label and be not less
+         * than width of four chars (0000).
+         */
+
+        wxClientDC dc( GetParent() );
+        int h, minw;
+
         aWidth = m_netsList->GetRect().GetWidth();
+
+        dc.GetTextExtent( COLUMN_HEADER_NET, &w0, &h );
+        dc.GetTextExtent( COLUMN_HEADER_COUNT, &w2, &h );
+        dc.GetTextExtent( "0000", &minw, &h );
+
+        // Considering left and right margins.
+        // For wxRanderGeneric it is 5px.
+        w0 = std::max( w0+10, minw);
+        w2 = std::max( w2+10, minw);
+
+        m_netsList->GetColumn( 0 )->SetWidth( w0 );
+        m_netsList->GetColumn( 2 )->SetWidth( w2 );
+    }
+    else
+    {
+        w0 = m_netsList->GetColumn( 0 )->GetWidth();
+        w2 = m_netsList->GetColumn( 2 )->GetWidth();
     }
 
-    aWidth -= m_netsList->GetColumn( 0 )->GetWidth();
-    aWidth -= m_netsList->GetColumn( 2 )->GetWidth();
+    // At resizing of the list the width of middle column (Name) changes only.
+    w1 = aWidth - w0 - w2;
 
-    m_netsList->GetColumn( 1 )->SetWidth( aWidth - 8 );
+    m_netsList->GetColumn( 1 )->SetWidth( w1 );
 }
 
 
-- 
2.19.0



Follow ups

References