Optimize TWO_COLUMN_TREE_LIST column sizing
This was particularly slow for very long lists on macOS.
This commit is contained in:
parent
9effcb80e7
commit
23d4da9e49
|
@ -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<wxString, int> TWO_COLUMN_TREE_LIST::m_width_cache;
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
*/
|
||||
|
||||
#include <wx/treelist.h>
|
||||
#include <map>
|
||||
|
||||
#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<wxString, int> m_width_cache;
|
||||
};
|
||||
|
||||
#endif // __two_column_tree_list__
|
||||
|
|
Loading…
Reference in New Issue