From 7f40cac4b0c4fecb0df8a70da1a7118588b685eb Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 17 Feb 2022 22:05:44 +0000 Subject: [PATCH] Fix collapsing name column in Net Inspector. (cherry picked from commit 4966e2ebc2b9f71efc8bd6f80d14629c8510b02f) --- pcbnew/dialogs/dialog_net_inspector.cpp | 71 +++++++++----------- pcbnew/dialogs/dialog_net_inspector_base.cpp | 2 +- pcbnew/dialogs/dialog_net_inspector_base.fbp | 2 +- 3 files changed, 35 insertions(+), 40 deletions(-) diff --git a/pcbnew/dialogs/dialog_net_inspector.cpp b/pcbnew/dialogs/dialog_net_inspector.cpp index 00c1e7f6ff..d3fb33748e 100644 --- a/pcbnew/dialogs/dialog_net_inspector.cpp +++ b/pcbnew/dialogs/dialog_net_inspector.cpp @@ -46,6 +46,7 @@ #include #include +#include "wx/wupdlock.h" struct DIALOG_NET_INSPECTOR::COLUMN_DESC { @@ -1701,42 +1702,36 @@ void DIALOG_NET_INSPECTOR::onSortingChanged( wxDataViewEvent& aEvent ) void DIALOG_NET_INSPECTOR::adjustListColumns() { - /** - * 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). - */ + wxWindowUpdateLocker locker( m_netsList ); - wxClientDC dc( GetParent() ); + int w0 = GetTextExtent( COLUMN_NET.display_name ).x; + int w1 = GetTextExtent( COLUMN_NAME.display_name ).x; + int w2 = GetTextExtent( COLUMN_PAD_COUNT.display_name ).x; + int w3 = GetTextExtent( COLUMN_VIA_COUNT.display_name ).x; + int w4 = GetTextExtent( COLUMN_VIA_LENGTH.display_name ).x; + int w5 = GetTextExtent( COLUMN_BOARD_LENGTH.display_name ).x; + int w6 = GetTextExtent( COLUMN_CHIP_LENGTH.display_name ).x; + int w7 = GetTextExtent( COLUMN_TOTAL_LENGTH.display_name ).x; - int h, minw, minw_col0, minw_col1; - int w0, w1, w2, w3, w4, w5, w6, w7; - - dc.GetTextExtent( COLUMN_NET.display_name, &w0, &h ); - dc.GetTextExtent( wxT( "MMMMMMMMMMMMMMMM" ), &minw_col1, &h ); - dc.GetTextExtent( COLUMN_PAD_COUNT.display_name, &w2, &h ); - dc.GetTextExtent( COLUMN_VIA_COUNT.display_name, &w3, &h ); - dc.GetTextExtent( COLUMN_VIA_LENGTH.display_name, &w4, &h ); - dc.GetTextExtent( COLUMN_BOARD_LENGTH.display_name, &w5, &h ); - dc.GetTextExtent( COLUMN_CHIP_LENGTH.display_name, &w6, &h ); - dc.GetTextExtent( COLUMN_TOTAL_LENGTH.display_name, &w7, &h ); - dc.GetTextExtent( wxT( "00000,000 mm" ), &minw, &h ); - dc.GetTextExtent( wxT( "00000" ), &minw_col0, &h ); + int minValueWidth = GetTextExtent( wxT( "00000,000 mm" ) ).x; + int minNumberWidth = GetTextExtent( wxT( "000" ) ).x; + int minNameWidth = GetTextExtent( wxT( "MMMMMM" ) ).x; // Considering left and right margins. // For wxRenderGeneric it is 5px. // Also account for the sorting arrow in the column header. // Column 0 also needs space for any potential expander icons. + const int margins = 15; const int extra_width = 30; - w0 = std::max( w0, minw_col0 ) + extra_width; - minw_col1 = minw_col1 + extra_width; - w2 = w2 + extra_width; - w3 = w3 + extra_width; - w4 = std::max( w4 + extra_width, minw ); - w5 = std::max( w5 + extra_width, minw ); - w6 = std::max( w6 + extra_width, minw ); - w7 = std::max( w7 + extra_width, minw ); + w0 = std::max( w0, minNumberWidth ) + extra_width; + w1 = std::max( w1, minNameWidth ) + margins; + w2 = std::max( w2, minNumberWidth ) + margins; + w3 = std::max( w3, minNumberWidth ) + margins; + w4 = std::max( w4, minValueWidth ) + margins; + w5 = std::max( w5, minValueWidth ) + margins; + w6 = std::max( w6, minValueWidth ) + margins; + w7 = std::max( w7, minValueWidth ) + margins; // the columns might have been reordered. we work on the column model numbers though. std::vector column_order( m_data_model->columnCount() ); @@ -1746,21 +1741,21 @@ void DIALOG_NET_INSPECTOR::adjustListColumns() assert( column_order.size() == 8 ); - m_netsList->GetColumn( column_order[0] )->SetWidth( w0 ); - m_netsList->GetColumn( column_order[1] )->SetMinWidth( minw_col1 ); - m_netsList->GetColumn( column_order[2] )->SetWidth( w2 ); - m_netsList->GetColumn( column_order[3] )->SetWidth( w3 ); - m_netsList->GetColumn( column_order[4] )->SetWidth( w4 ); - m_netsList->GetColumn( column_order[5] )->SetWidth( w5 ); - m_netsList->GetColumn( column_order[6] )->SetWidth( w6 ); - m_netsList->GetColumn( column_order[7] )->SetWidth( w7 ); + m_netsList->GetColumn( column_order[0] )->SetMinWidth( w0 ); + m_netsList->GetColumn( column_order[1] )->SetMinWidth( w1 ); + m_netsList->GetColumn( column_order[2] )->SetMinWidth( w2 ); + m_netsList->GetColumn( column_order[3] )->SetMinWidth( w3 ); + m_netsList->GetColumn( column_order[4] )->SetMinWidth( w4 ); + m_netsList->GetColumn( column_order[5] )->SetMinWidth( w5 ); + m_netsList->GetColumn( column_order[6] )->SetMinWidth( w6 ); + m_netsList->GetColumn( column_order[7] )->SetMinWidth( w7 ); // At resizing of the list the width of middle column (Net Names) changes only. int width = m_netsList->GetClientSize().x - 24; - w1 = width - w0 - w2 - w3 - w4 - w5 - w6 - w7; + int remaining = width - w0 - w2 - w3 - w4 - w5 - w6 - w7; - if( w1 > minw_col1 ) - m_netsList->GetColumn( column_order[1] )->SetWidth( w1 ); + if( remaining > w1 ) + m_netsList->GetColumn( column_order[1] )->SetWidth( remaining ); m_netsList->Refresh(); } diff --git a/pcbnew/dialogs/dialog_net_inspector_base.cpp b/pcbnew/dialogs/dialog_net_inspector_base.cpp index 6812fdb807..8a62e250c1 100644 --- a/pcbnew/dialogs/dialog_net_inspector_base.cpp +++ b/pcbnew/dialogs/dialog_net_inspector_base.cpp @@ -72,7 +72,7 @@ DIALOG_NET_INSPECTOR_BASE::DIALOG_NET_INSPECTOR_BASE( wxWindow* parent, wxWindow bSizerMain->Add( bMidSizer, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); m_netsList = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxDV_HORIZ_RULES|wxDV_MULTIPLE|wxDV_VERT_RULES ); - m_netsList->SetMinSize( wxSize( 500,300 ) ); + m_netsList->SetMinSize( wxSize( 640,300 ) ); bSizerMain->Add( m_netsList, 1, wxEXPAND|wxLEFT|wxRIGHT, 10 ); diff --git a/pcbnew/dialogs/dialog_net_inspector_base.fbp b/pcbnew/dialogs/dialog_net_inspector_base.fbp index ea042f0a4d..c4ac6262dc 100644 --- a/pcbnew/dialogs/dialog_net_inspector_base.fbp +++ b/pcbnew/dialogs/dialog_net_inspector_base.fbp @@ -520,7 +520,7 @@ 0 wxID_ANY - 500,300 + 640,300 m_netsList protected