pcbnew: Force grid sizing based on text extents

GTK does not handle enlarged text layouts automatically, so we need to
get the screen size before choosing the correct grid width for the
dialog

Fixes: lp:1788495
* https://bugs.launchpad.net/kicad/+bug/1788495
This commit is contained in:
Seth Hillbrand 2019-02-01 20:03:45 -08:00
parent d06f0de1eb
commit 76600e3436
3 changed files with 47 additions and 3 deletions

View File

@ -374,6 +374,23 @@ bool DIALOG_FOOTPRINT_BOARD_EDITOR::TransferDataToWindow()
// Show the footprint's ID.
m_staticLibraryID->SetLabel( m_footprint->GetFPID().Format() );
// Work around an issue where wxWidgets doesn't calculate the row width on its own
// TODO: Refactor this into a GRID_TRICKS routine or similar
for( int col = 0; col < m_itemsGrid->GetNumberCols(); col++ )
{
// 'M' is generally the widest character, so we buffer the column width by default to ensure
// we don't write a continuous line of text at the column header
auto size = m_itemsGrid->GetTextExtent( m_itemsGrid->GetColLabelValue( col ) + "M").x;
m_itemsGrid->SetColSize( col, std::max( m_itemsGrid->GetColumnWidth( col ), size ) );
}
int size = m_itemsGrid->GetRowLabelSize();
for( int row = 0; row < m_itemsGrid->GetNumberRows(); row++ )
size = std::max( size, m_itemsGrid->GetTextExtent( m_itemsGrid->GetRowLabelValue( row ) + "M" ).x );
m_itemsGrid->SetRowLabelSize( size );
Layout();
adjustGridColumns( m_itemsGrid->GetRect().GetWidth());

View File

@ -66,12 +66,19 @@ PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( PAGED_DIALOG* aParent, PCB_EDIT_
m_originalColWidths = new int[ m_netclassGrid->GetNumberCols() ];
for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
m_originalColWidths[ i ] = m_netclassGrid->GetColSize( i );
{
// 'M' is generally the widest character, so we buffer the column width by default to ensure
// we don't write a continuous line of text at the column header
auto size = m_netclassGrid->GetTextExtent( m_netclassGrid->GetColLabelValue( i ) + "M");
m_originalColWidths[ i ] = std::max( m_netclassGrid->GetColSize( i ), size.x );
m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
}
// 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 );
m_membershipGrid->SetDefaultRowSize( m_membershipGrid->GetDefaultRowSize() + 4 );
m_netclassGrid->SetDefaultRowSize( m_netclassGrid->GetDefaultRowSize() + 4 );
m_membershipGrid->SetDefaultRowSize( m_membershipGrid->GetDefaultRowSize() + 4 );
m_netclassGrid->PushEventHandler( new GRID_TRICKS( m_netclassGrid ) );
m_membershipGrid->PushEventHandler( new GRID_TRICKS( m_membershipGrid ) );

View File

@ -65,6 +65,26 @@ PANEL_SETUP_TEXT_AND_GRAPHICS::PANEL_SETUP_TEXT_AND_GRAPHICS( PAGED_DIALOG* aPar
m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
// Work around an issue where wxWidgets doesn't calculate the row width on its own
for( int col = 0; col < m_grid->GetNumberCols(); col++ )
{
// 'M' is generally the widest character, so we buffer the column width by default to ensure
// we don't write a continuous line of text at the column header
auto size = m_grid->GetTextExtent( m_grid->GetColLabelValue( col ) + "M").x;
for( int row = 0; row < m_grid->GetNumberRows(); row++ )
size = std::max( size, m_grid->GetTextExtent( m_grid->GetCellValue( row, col ) ).x );
m_grid->SetColSize( col, size);
}
int size = m_grid->GetRowLabelSize();
for( int row = 0; row < m_grid->GetNumberRows(); row++ )
size = std::max( size, m_grid->GetTextExtent( m_grid->GetRowLabelValue( row ) + "M" ).x );
m_grid->SetRowLabelSize( size );
// Work around a bug in wxWidgets where it fails to recalculate the grid height
// after changing the default row size
m_grid->AppendRows( 1 );