← Back to team overview

kicad-developers team mailing list archive

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

 

Hi Seth!

Something like this (see attachment)?
Not sure that I done it right, but it works fine.

вт, 25 сент. 2018 г. в 22:24, <seth@xxxxxxxxxxxxx>:

> Hi Baranovskiy-
>
> On 2018-09-25 07:17, Baranovskiy Konstantin wrote:
> > 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" )
>
> This is overall a good patch.  Can you replace the three defines here
> with C++-style constexpr functions?
>
> -Seth
>
From 99206017b4c1522147c3ca884071eacdd808b876 Mon Sep 17 00:00:00 2001
From: Baranovskiy Konstantin <baranovskiykonstantin@xxxxxxxxx>
Date: Tue, 25 Sep 2018 12:31:17 +0300
Subject: [PATCH 2/4] 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   | 48 +++++++++++++++----
 1 file changed, 38 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..6db4efaac 100644
--- a/pcbnew/dialogs/dialog_select_net_from_list.cpp
+++ b/pcbnew/dialogs/dialog_select_net_from_list.cpp
@@ -65,6 +65,9 @@ private:
     void onListSize( wxSizeEvent& event ) override;
 
     void buildNetsList();
+    constexpr wxString getListColumnHeaderNet() { return _( "Net" ); };
+    constexpr wxString getListColumnHeaderName() { return _( "Name" ); };
+    constexpr wxString getListColumnHeaderCount() { return _( "Pad Count" ); };
     void adjustListColumns( int aWidth );
 
     wxString        m_selection;
@@ -93,9 +96,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( getListColumnHeaderNet(),   wxDATAVIEW_CELL_INERT, 0, wxALIGN_LEFT, 0 );
+    m_netsList->AppendTextColumn( getListColumnHeaderName(),  wxDATAVIEW_CELL_INERT, 0, wxALIGN_LEFT, 0 );
+    m_netsList->AppendTextColumn( getListColumnHeaderCount(), 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 +223,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( getListColumnHeaderNet(), &w0, &h );
+        dc.GetTextExtent( getListColumnHeaderCount(), &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