28#include <wx/settings.h>
32 unsigned aFlexibleCol ) :
33 m_grid( aGrid ), m_autosizedCols(
std::
move( aAutosizedCols ) ),
34 m_flexibleCol( aFlexibleCol )
36 const int colCount =
m_grid.GetNumberCols();
40 wxASSERT_MSG( colIndex < colCount,
"Autosized column does not exist in grid" );
43 wxASSERT_MSG(
m_flexibleCol < colCount,
"Flexible column index does not exist in grid" );
45 m_grid.Bind( wxEVT_UPDATE_UI,
46 [
this]( wxUpdateUIEvent& aEvent )
52 [
this]( wxSizeEvent& aEvent )
59 m_grid.Bind( wxEVT_GRID_CELL_CHANGED,
60 [
this]( wxGridEvent& aEvent )
73 m_grid.GetClientRect().GetWidth() - wxSystemSettings::GetMetric( wxSYS_VSCROLL_X );
75 std::optional<int> flexibleMinWidth;
79 m_grid.AutoSizeColumn( colIndex );
80 const int colSize =
m_grid.GetColSize( colIndex );
81 m_grid.SetColSize( colIndex, std::max( minWidth, colSize ) );
85 flexibleMinWidth = minWidth;
90 int nonFlexibleWidth = 0;
92 for(
int i = 0; i <
m_grid.GetNumberCols(); ++i )
96 nonFlexibleWidth +=
m_grid.GetColSize( i );
101 std::max( flexibleMinWidth.value_or( 0 ), width - nonFlexibleWidth ) );
112 const int width = aEvent.GetSize().GetX();
WX_GRID_AUTOSIZER(wxGrid &aGrid, COL_MIN_WIDTHS aAutosizedCols, unsigned aFlexibleCol)
std::map< int, int > COL_MIN_WIDTHS
Map of column indices to minimum widths.
COL_MIN_WIDTHS m_autosizedCols
void onSizeEvent(wxSizeEvent &aEvent)
void recomputeGridWidths()