diff --git a/common/widgets/two_column_tree_list.cpp b/common/widgets/two_column_tree_list.cpp index 77f74bc376..f29ff7085e 100644 --- a/common/widgets/two_column_tree_list.cpp +++ b/common/widgets/two_column_tree_list.cpp @@ -89,7 +89,7 @@ void TWO_COLUMN_TREE_LIST::OnSize( wxSizeEvent& aEvent ) if( width > clamped_column_width ) clamped_column_width = width; - width = WidthFor( GetItemText( item, m_rubber_band_column ) ); + width = MemoWidthFor( GetItemText( item, m_rubber_band_column ) ); if( width > rubber_max_width ) rubber_max_width = width; } @@ -119,3 +119,24 @@ void TWO_COLUMN_TREE_LIST::OnSize( wxSizeEvent& aEvent ) } } + +int TWO_COLUMN_TREE_LIST::MemoWidthFor( const wxString& aStr ) +{ + int width; + auto found = m_width_cache.find( aStr ); + + if( found == m_width_cache.end() ) + { + width = WidthFor( aStr ); + m_width_cache[aStr] = width; + } + else + { + width = found->second; + } + + return width; +} + + +std::map TWO_COLUMN_TREE_LIST::m_width_cache; diff --git a/eeschema/component_tree_search_container.cpp b/eeschema/component_tree_search_container.cpp index 1619bc28b0..1318eb12c3 100644 --- a/eeschema/component_tree_search_container.cpp +++ b/eeschema/component_tree_search_container.cpp @@ -142,7 +142,7 @@ void COMPONENT_TREE_SEARCH_CONTAINER::SetTree( TWO_COLUMN_TREE_LIST* aTree ) if( m_tree ) { - m_tree->AppendColumn( _( "Part" ), wxCOL_WIDTH_AUTOSIZE, wxALIGN_LEFT, wxCOL_RESIZABLE ); + m_tree->AppendColumn( _( "Part" ), 100, wxALIGN_LEFT, wxCOL_RESIZABLE ); m_tree->AppendColumn( _( "Description" ), 100, wxALIGN_LEFT, wxCOL_RESIZABLE ); m_tree->SetRubberBandColumn( 1 ); } diff --git a/include/widgets/two_column_tree_list.h b/include/widgets/two_column_tree_list.h index f04a42de0d..0309c7d27d 100644 --- a/include/widgets/two_column_tree_list.h +++ b/include/widgets/two_column_tree_list.h @@ -27,6 +27,7 @@ */ #include +#include #ifndef __two_column_tree_list__ #define __two_column_tree_list__ @@ -79,8 +80,17 @@ class TWO_COLUMN_TREE_LIST : public wxTreeListCtrl void OnSize( wxSizeEvent& aEvent ); protected: + + /** + * Memoized version of wx WidthFor(), which returns the width in pixels + * required to display a string. This function is REALLY SLOW on macOS. + */ + int MemoWidthFor( const wxString& aStr ); + int m_rubber_band_column; int m_clamped_min_width; + + static std::map m_width_cache; }; #endif // __two_column_tree_list__