diff --git a/common/widgets/wx_grid.cpp b/common/widgets/wx_grid.cpp index 6c5211c9e3..8f35492094 100644 --- a/common/widgets/wx_grid.cpp +++ b/common/widgets/wx_grid.cpp @@ -243,27 +243,9 @@ int WX_GRID::GetVisibleWidth( int aCol, bool aHeader, bool aContents, bool aKeep // we don't write a continuous line of text at the column header if( aHeader ) { + EnsureColLabelsVisible(); // The 1.1 scale factor is due to the fact headers use a bold font, bigger than the normal font size = std::max( size, int( GetTextExtent( GetColLabelValue( aCol ) + "M" ).x * 1.1 ) ); - - // Headers can be multiline. Fix the Column Label Height to show the full header - // However GetTextExtent does not work on multiline strings, - // and do not return the full text height (only the height of one line) - int nl_count = 0; - - for( unsigned ii = 0; ii < GetColLabelValue( aCol ).size(); ii++ ) - if( GetColLabelValue( aCol )[ii] == '\n' ) - nl_count++; - - if( nl_count ) - { - // calculate a reasonable text height and its margin - int heigth = int( GetTextExtent( "Mj" ).y * 1.1 ) + 3; - - // Col Label height must be able to show nl_count+1 lines - if( GetColLabelSize() < heigth * (nl_count+1) ) - SetColLabelSize( GetColLabelSize() + heigth*nl_count ); - } } for( int row = 0; aContents && row < GetNumberRows(); row++ ) @@ -278,3 +260,34 @@ int WX_GRID::GetVisibleWidth( int aCol, bool aHeader, bool aContents, bool aKeep return size; } + + +void WX_GRID::EnsureColLabelsVisible() +{ + int row_height = GetColLabelSize(); + // The 1.1 scale factor is due to the fact row labels use a bold font, bigger than the normal font + // TODO: use a better way to evaluate the text size, for bold font + // Headers can be multiline. Fix the Column Label Height to show the full header + // However GetTextExtent does not work on multiline strings, + // and do not return the full text height (only the height of one line) + for( int col = 0; col < GetNumberCols(); col++ ) + { + int nl_count = 0; + + for( unsigned ii = 0; ii < GetColLabelValue( col ).size(); ii++ ) + if( GetColLabelValue( col )[ii] == '\n' ) + nl_count++; + + if( nl_count ) + { + // calculate a reasonable text height and its margin + int heigth = int( GetTextExtent( "Mj" ).y * 1.1 ) + 3; + + // Col Label height must be able to show nl_count+1 lines + if( row_height < heigth * (nl_count+1) ) + row_height += heigth*nl_count; + } + } + + SetColLabelSize( row_height ); +} diff --git a/common/widgets/wx_grid.h b/common/widgets/wx_grid.h index 292381abf6..96fe2b5beb 100644 --- a/common/widgets/wx_grid.h +++ b/common/widgets/wx_grid.h @@ -85,6 +85,12 @@ public: */ int GetVisibleWidth( int aCol, bool aHeader = true, bool aContents = false, bool aKeep = true ); + /** + * Ensure the height of the row displaying the column labels is enough, even + * if labels are multiline texts + */ + void EnsureColLabelsVisible(); + protected: void DrawColLabel( wxDC& dc, int col ) override; diff --git a/pcbnew/dialogs/panel_setup_netclasses.cpp b/pcbnew/dialogs/panel_setup_netclasses.cpp index 8b214a50e1..19a91f78af 100644 --- a/pcbnew/dialogs/panel_setup_netclasses.cpp +++ b/pcbnew/dialogs/panel_setup_netclasses.cpp @@ -79,6 +79,9 @@ PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( PAGED_DIALOG* aParent, PCB_EDIT_ m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] ); } + // Be sure the column labels are readable + m_netclassGrid->EnsureColLabelsVisible(); + // Membership combobox editors require a bit more room, so increase the row size of // all our grids for consistency m_netclassGrid->SetDefaultRowSize( m_netclassGrid->GetDefaultRowSize() + 4 );