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();
39 wxASSERT_MSG( colIndex < colCount,
"Autosized column does not exist in grid" );
41 wxASSERT_MSG(
m_flexibleCol < colCount,
"Flexible column index does not exist in grid" );
43 m_grid.Bind( wxEVT_UPDATE_UI,
44 [
this]( wxUpdateUIEvent& aEvent )
50 [
this]( wxSizeEvent& aEvent )
57 m_grid.Bind( wxEVT_GRID_CELL_CHANGED,
58 [
this]( wxGridEvent& aEvent )
70 m_grid.GetClientRect().GetWidth() - wxSystemSettings::GetMetric( wxSYS_VSCROLL_X );
72 std::optional<int> flexibleMinWidth;
75 m_grid.AutoSizeColumn( colIndex );
76 const int colSize =
m_grid.GetColSize( colIndex );
77 m_grid.SetColSize( colIndex, std::max( minWidth, colSize ) );
81 flexibleMinWidth = minWidth;
86 int nonFlexibleWidth = 0;
88 for(
int i = 0; i <
m_grid.GetNumberCols(); ++i )
92 nonFlexibleWidth +=
m_grid.GetColSize( i );
97 std::max( flexibleMinWidth.value_or( 0 ), width - nonFlexibleWidth ) );
107 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()