Add wxGridCellChoiceRenderer to optimize column size calculation

Previously columns using a set of predetermined values used plain
wxGridCellStringRenderer, which didn't allow to determine their best
size efficiently, as wxGrid had to iterate over all the rows of the
table, even if they only took a couple of possible values.

Add wxGridCellChoiceRenderer (refactoring wxGridCellEnumRenderer to
extract the common code from it in the process) which implements
GetMaxBestSize() by just finding the best size of all of these values,
which is much faster for large grids.

This does result in a change in behaviour, as the column now adapts to
its "theoretical" best size and not just the size of the values actually
shown in it, but this seems to be a worthwhile trade-off and could even
be seen as an advantage, as editing a cell won't make its value overflow
the auto-sized column width any more, as it is wide enough to show any
of the column values.
This commit is contained in:
Vadim Zeitlin
2020-06-13 16:10:14 +02:00
parent 71d42a8290
commit 96de24d1bb
3 changed files with 63 additions and 44 deletions

View File

@@ -11017,7 +11017,7 @@ int wxGridTypeRegistry::FindDataType(const wxString& typeName)
if ( typeName == wxGRID_VALUE_CHOICE )
{
RegisterDataType(wxGRID_VALUE_CHOICE,
new wxGridCellStringRenderer,
new wxGridCellChoiceRenderer,
new wxGridCellChoiceEditor);
}
else