From 1db5e2bc964442c58ec6b676a8a34045c2a27f08 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Fri, 2 Apr 2021 19:12:21 +0100 Subject: [PATCH] Don't force an entire refresh of toolbars to update sizes Forcing an entire refresh of the toolbars is wasteful, so instead just update the sizers directly. --- common/tool/action_toolbar.cpp | 23 ++++++++++++++++++++++- cvpcb/display_footprints_frame.cpp | 3 --- gerbview/toolbars_gerber.cpp | 6 ------ pagelayout_editor/toolbars_pl_editor.cpp | 3 --- pcbnew/footprint_edit_frame.cpp | 1 - pcbnew/toolbars_footprint_editor.cpp | 3 --- pcbnew/toolbars_pcb_editor.cpp | 6 ------ 7 files changed, 22 insertions(+), 23 deletions(-) diff --git a/common/tool/action_toolbar.cpp b/common/tool/action_toolbar.cpp index ac6a095f95..e296d83b67 100644 --- a/common/tool/action_toolbar.cpp +++ b/common/tool/action_toolbar.cpp @@ -40,6 +40,7 @@ #include #include #include +#include ACTION_GROUP::ACTION_GROUP( std::string aName, const std::vector& aActions ) @@ -342,7 +343,27 @@ void ACTION_TOOLBAR::UpdateControlWidth( int aID ) wxASSERT_MSG( control, wxString::Format( "No control located in toolbar item with ID %d", aID ) ); // Update the size the item has stored using the best size of the control - item->SetMinSize( control->GetBestSize() ); + wxSize bestSize = control->GetBestSize(); + item->SetMinSize( bestSize ); + + // Update the sizer item sizes + // This is a bit convoluted because there are actually 2 sizers that need to be updated: + // 1. The main sizer that is used for the entire toolbar (this sizer item can be found in the + // toolbar item) + if( wxSizerItem* szrItem = item->GetSizerItem() ) + szrItem->SetMinSize( bestSize ); + + // 2. The controls have a second sizer that allows for padding above/below the control with stretch + // space, so we also need to update the sizer item for the control in that sizer with the new size. + // We let wx do the search for us, since SetItemMinSize is recursive and will locate the control + // on that sizer. + if( m_sizer ) + { + m_sizer->SetItemMinSize( control, bestSize ); + + // Now actually update the toolbar with the new sizes + m_sizer->Layout(); + } } diff --git a/cvpcb/display_footprints_frame.cpp b/cvpcb/display_footprints_frame.cpp index f1bd4eb08d..b10adbdcc4 100644 --- a/cvpcb/display_footprints_frame.cpp +++ b/cvpcb/display_footprints_frame.cpp @@ -335,9 +335,6 @@ void DISPLAY_FOOTPRINTS_FRAME::UpdateToolbarControlSizes() // Update the item widths m_mainToolBar->UpdateControlWidth( ID_ON_GRID_SELECT ); m_mainToolBar->UpdateControlWidth( ID_ON_ZOOM_SELECT ); - - // Update the toolbar with the new widths - m_mainToolBar->KiRealize(); } } diff --git a/gerbview/toolbars_gerber.cpp b/gerbview/toolbars_gerber.cpp index cd61b9d437..f75a1f4c2f 100644 --- a/gerbview/toolbars_gerber.cpp +++ b/gerbview/toolbars_gerber.cpp @@ -262,9 +262,6 @@ void GERBVIEW_FRAME::UpdateToolbarControlSizes() // Update the item widths m_mainToolBar->UpdateControlWidth( ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER ); m_mainToolBar->UpdateControlWidth( ID_TOOLBARH_GERBER_DATA_TEXT_BOX ); - - // Update the toolbar with the new widths - m_mainToolBar->KiRealize(); } if( m_auxiliaryToolBar ) @@ -275,9 +272,6 @@ void GERBVIEW_FRAME::UpdateToolbarControlSizes() m_auxiliaryToolBar->UpdateControlWidth( ID_GBR_AUX_TOOLBAR_PCB_APERATTRIBUTES_CHOICE ); m_auxiliaryToolBar->UpdateControlWidth( ID_ON_GRID_SELECT ); m_auxiliaryToolBar->UpdateControlWidth( ID_ON_ZOOM_SELECT ); - - // Update the toolbar with the new widths - m_auxiliaryToolBar->KiRealize(); } } diff --git a/pagelayout_editor/toolbars_pl_editor.cpp b/pagelayout_editor/toolbars_pl_editor.cpp index 53baeff7f8..54cf6c4cd6 100644 --- a/pagelayout_editor/toolbars_pl_editor.cpp +++ b/pagelayout_editor/toolbars_pl_editor.cpp @@ -186,8 +186,5 @@ void PL_EDITOR_FRAME::UpdateToolbarControlSizes() // Update the item widths m_mainToolBar->UpdateControlWidth( ID_SELECT_COORDINATE_ORIGIN ); m_mainToolBar->UpdateControlWidth( ID_SELECT_PAGE_NUMBER ); - - // Update the toolbar with the new widths - m_mainToolBar->KiRealize(); } } diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index 59c8af1329..e4d0186252 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -299,7 +299,6 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, // Ensure the controls on the toolbars all are correctly sized UpdateToolbarControlSizes(); } ); - } diff --git a/pcbnew/toolbars_footprint_editor.cpp b/pcbnew/toolbars_footprint_editor.cpp index 6b3ad009b4..1944663679 100644 --- a/pcbnew/toolbars_footprint_editor.cpp +++ b/pcbnew/toolbars_footprint_editor.cpp @@ -226,9 +226,6 @@ void FOOTPRINT_EDIT_FRAME::UpdateToolbarControlSizes() m_mainToolBar->UpdateControlWidth( ID_TOOLBARH_PCB_SELECT_LAYER ); m_mainToolBar->UpdateControlWidth( ID_ON_ZOOM_SELECT ); m_mainToolBar->UpdateControlWidth( ID_ON_GRID_SELECT ); - - // Update the toolbar with the new widths - m_mainToolBar->KiRealize(); } } diff --git a/pcbnew/toolbars_pcb_editor.cpp b/pcbnew/toolbars_pcb_editor.cpp index 976ec9089d..61a1dce958 100644 --- a/pcbnew/toolbars_pcb_editor.cpp +++ b/pcbnew/toolbars_pcb_editor.cpp @@ -561,9 +561,6 @@ void PCB_EDIT_FRAME::UpdateToolbarControlSizes() { // Update the item widths m_mainToolBar->UpdateControlWidth( ID_TOOLBARH_PCB_SELECT_LAYER ); - - // Update the toolbar with the new widths - m_mainToolBar->KiRealize(); } if( m_auxiliaryToolBar ) @@ -573,9 +570,6 @@ void PCB_EDIT_FRAME::UpdateToolbarControlSizes() m_auxiliaryToolBar->UpdateControlWidth( ID_AUX_TOOLBAR_PCB_VIA_SIZE ); m_auxiliaryToolBar->UpdateControlWidth( ID_ON_ZOOM_SELECT ); m_auxiliaryToolBar->UpdateControlWidth( ID_ON_GRID_SELECT ); - - // Update the toolbar with the new widths - m_auxiliaryToolBar->KiRealize(); } }