Ensure toolbar controls have the correct width on frame creation

Otherwise they could be slightly too small and then look odd.
This commit is contained in:
Ian McInerney 2021-03-27 21:49:38 +00:00
parent d0d6352a25
commit 475ac3697f
18 changed files with 213 additions and 43 deletions

View File

@ -332,6 +332,20 @@ void ACTION_TOOLBAR::doSelectAction( ACTION_GROUP* aGroup, const TOOL_ACTION& aA
}
void ACTION_TOOLBAR::UpdateControlWidth( int aID )
{
wxAuiToolBarItem* item = FindTool( aID );
wxASSERT_MSG( item, wxString::Format( "No toolbar item found for ID %d", aID ) );
// The control on the toolbar is stored inside the window field of the item
wxControl* control = dynamic_cast<wxControl*>( item->GetWindow() );
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() );
}
void ACTION_TOOLBAR::ClearToolbar()
{
// Clear all the maps keeping track of our items on the toolbar

View File

@ -157,6 +157,14 @@ DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME( KIWAY* aKiway, wxWindow* aPa
updateView();
Show( true );
// Register a call to update the toolbar sizes. It can't be done immediately because
// it seems to require some sizes calculated that aren't yet (at least on GTK).
CallAfter( [&]()
{
// Ensure the controls on the toolbars all are correctly sized
UpdateToolbarControlSizes();
} );
}
@ -311,12 +319,29 @@ void DISPLAY_FOOTPRINTS_FRAME::ReCreateHToolbar()
UpdateZoomSelectBox();
m_mainToolBar->AddControl( m_zoomSelectBox );
m_mainToolBar->UpdateControlWidth( ID_ON_GRID_SELECT );
m_mainToolBar->UpdateControlWidth( ID_ON_ZOOM_SELECT );
// after adding the buttons to the toolbar, must call Realize() to reflect
// the changes
m_mainToolBar->Realize();
}
void DISPLAY_FOOTPRINTS_FRAME::UpdateToolbarControlSizes()
{
if( m_mainToolBar )
{
// 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();
}
}
void DISPLAY_FOOTPRINTS_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
{
auto cfg = dynamic_cast<CVPCB_SETTINGS*>( aCfg );

View File

@ -51,6 +51,7 @@ public:
void ReCreateHToolbar() override;
void ReCreateVToolbar() override;
void ReCreateOptToolbar() override;
void UpdateToolbarControlSizes() override;
/**
* Refresh the full display for this frame:

View File

@ -193,6 +193,14 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent )
// Ensure the window is on top
Raise();
// Register a call to update the toolbar sizes. It can't be done immediately because
// it seems to require some sizes calculated that aren't yet (at least on GTK).
CallAfter( [&]()
{
// Ensure the controls on the toolbars all are correctly sized
UpdateToolbarControlSizes();
} );
}

View File

@ -91,6 +91,7 @@ public:
void ReCreateMenuBar() override;
void UpdateStatusBar() override;
void UpdateToolbarControlSizes() override;
/**
* @return 0 for fast mode (not fully compatible with negative objects)

View File

@ -38,6 +38,7 @@ enum gerbview_ids
ID_MAIN_MENUBAR = ID_END_LIST,
ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE,
ID_TOOLBARH_GERBER_DATA_TEXT_BOX,
ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE,
ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE,

View File

@ -82,11 +82,14 @@ void GERBVIEW_FRAME::ReCreateHToolbar()
m_mainToolBar->AddControl( m_SelLayerBox );
if( !m_TextInfo )
m_TextInfo = new wxTextCtrl( m_mainToolBar, wxID_ANY, wxEmptyString, wxDefaultPosition,
m_TextInfo = new wxTextCtrl( m_mainToolBar, ID_TOOLBARH_GERBER_DATA_TEXT_BOX, wxEmptyString, wxDefaultPosition,
wxDefaultSize, wxTE_READONLY );
m_mainToolBar->AddControl( m_TextInfo );
m_mainToolBar->UpdateControlWidth( ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER );
m_mainToolBar->UpdateControlWidth( ID_TOOLBARH_GERBER_DATA_TEXT_BOX );
// after adding the buttons to the toolbar, must call Realize() to reflect the changes
m_mainToolBar->KiRealize();
}
@ -189,26 +192,13 @@ void GERBVIEW_FRAME::ReCreateAuxiliaryToolbar()
UpdateGridSelectBox();
UpdateZoomSelectBox();
// combobox sizes can have changed: apply new best sizes
auto item = m_auxiliaryToolBar->FindTool( ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE );
wxASSERT( item );
item->SetMinSize( m_SelComponentBox->GetBestSize() );
item = m_auxiliaryToolBar->FindTool( ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE );
wxASSERT( item );
item->SetMinSize( m_SelNetnameBox->GetBestSize() );
item = m_auxiliaryToolBar->FindTool( ID_GBR_AUX_TOOLBAR_PCB_APERATTRIBUTES_CHOICE );
wxASSERT( item );
item->SetMinSize( m_SelAperAttributesBox->GetBestSize() );
item = m_auxiliaryToolBar->FindTool( ID_ON_GRID_SELECT );
wxASSERT( item );
item->SetMinSize( m_gridSelectBox->GetBestSize() );
item = m_auxiliaryToolBar->FindTool( ID_ON_ZOOM_SELECT );
wxASSERT( item );
item->SetMinSize( m_zoomSelectBox->GetBestSize() );
// Go through and ensure the comboboxes are the correct size, since the strings in the
// box could have changed widths.
m_auxiliaryToolBar->UpdateControlWidth( ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE );
m_auxiliaryToolBar->UpdateControlWidth( ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE );
m_auxiliaryToolBar->UpdateControlWidth( ID_GBR_AUX_TOOLBAR_PCB_APERATTRIBUTES_CHOICE );
m_auxiliaryToolBar->UpdateControlWidth( ID_ON_GRID_SELECT );
m_auxiliaryToolBar->UpdateControlWidth( ID_ON_ZOOM_SELECT );
// after adding the buttons to the toolbar, must call Realize()
m_auxiliaryToolBar->KiRealize();
@ -265,6 +255,33 @@ void GERBVIEW_FRAME::ReCreateOptToolbar()
}
void GERBVIEW_FRAME::UpdateToolbarControlSizes()
{
if( m_mainToolBar )
{
// 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 )
{
// Update the item widths
m_auxiliaryToolBar->UpdateControlWidth( ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE );
m_auxiliaryToolBar->UpdateControlWidth( ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE );
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();
}
}
#define NO_SELECTION_STRING _("<No selection>")
void GERBVIEW_FRAME::updateDCodeSelectBox()

View File

@ -207,6 +207,11 @@ public:
virtual void ReCreateOptToolbar() = 0;
virtual void ReCreateAuxiliaryToolbar() { }
/**
* Update the sizes of any controls in the toolbars of the frame.
*/
virtual void UpdateToolbarControlSizes() { }
/*
* These 4 functions provide a basic way to show/hide grid and /get/set grid color.
*

View File

@ -253,6 +253,13 @@ public:
*/
void SelectAction( ACTION_GROUP* aGroup, const TOOL_ACTION& aAction );
/**
* Update the toolbar item width of a control using its best size.
*
* @param aID is the ID of the toolbar item to update the width for
*/
void UpdateControlWidth( int aID );
/**
* Clear the toolbar and remove all associated menus.
*/

View File

@ -205,6 +205,14 @@ PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
// Ensure the window is on top
Raise();
// Register a call to update the toolbar sizes. It can't be done immediately because
// it seems to require some sizes calculated that aren't yet (at least on GTK).
CallAfter( [&]()
{
// Ensure the controls on the toolbars all are correctly sized
UpdateToolbarControlSizes();
} );
}

View File

@ -116,7 +116,8 @@ public:
void setupTools();
// Virtual basic functions:
void ReCreateHToolbar() override;
void ReCreateHToolbar() override;
void UpdateToolbarControlSizes() override;
void SetPageSettings(const PAGE_INFO&) override;
const PAGE_INFO& GetPageSettings () const override;

View File

@ -117,6 +117,11 @@ void PL_EDITOR_FRAME::ReCreateHToolbar()
m_pageSelectBox->SetSelection( 0 );
// Go through and ensure the comboboxes are the correct size, since the strings in the
// box could have changed widths.
m_mainToolBar->UpdateControlWidth( ID_SELECT_COORDINATE_ORIGIN );
m_mainToolBar->UpdateControlWidth( ID_SELECT_PAGE_NUMBER );
// after adding the buttons to the toolbar, must call Realize() to reflect the changes
m_mainToolBar->KiRealize();
}
@ -172,3 +177,17 @@ void PL_EDITOR_FRAME::ReCreateOptToolbar()
m_optionsToolBar->KiRealize();
}
void PL_EDITOR_FRAME::UpdateToolbarControlSizes()
{
if( m_mainToolBar )
{
// 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();
}
}

View File

@ -291,6 +291,15 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent,
// Ensure the window is on top
Raise();
Show( true );
// Register a call to update the toolbar sizes. It can't be done immediately because
// it seems to require some sizes calculated that aren't yet (at least on GTK).
CallAfter( [&]()
{
// Ensure the controls on the toolbars all are correctly sized
UpdateToolbarControlSizes();
} );
}

View File

@ -107,6 +107,7 @@ public:
void ReCreateVToolbar() override;
void ReCreateOptToolbar() override;
void UpdateToolbarControlSizes() override;
/**
* @brief (Re)Create the menubar for the Footprint Editor frame

View File

@ -363,6 +363,14 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
} );
}
#endif
// Register a call to update the toolbar sizes. It can't be done immediately because
// it seems to require some sizes calculated that aren't yet (at least on GTK).
CallAfter( [&]()
{
// Ensure the controls on the toolbars all are correctly sized
UpdateToolbarControlSizes();
} );
}

View File

@ -396,6 +396,7 @@ public:
void ReCreateVToolbar() override;
void ReCreateOptToolbar() override;
void ReCreateMenuBar() override;
void UpdateToolbarControlSizes() override;
/**
* Recreate the layer box by clearing the old list and building a new one from the new

View File

@ -134,6 +134,12 @@ void FOOTPRINT_EDIT_FRAME::ReCreateHToolbar()
ReCreateLayerBox( false );
m_mainToolBar->AddControl( m_selLayerBox );
// Go through and ensure the comboboxes are the correct size, since the strings in the
// box could have changed widths.
m_mainToolBar->UpdateControlWidth( ID_TOOLBARH_PCB_SELECT_LAYER );
m_mainToolBar->UpdateControlWidth( ID_ON_ZOOM_SELECT );
m_mainToolBar->UpdateControlWidth( ID_ON_GRID_SELECT );
// after adding the buttons to the toolbar, must call Realize() to reflect the changes
m_mainToolBar->KiRealize();
}
@ -212,6 +218,21 @@ void FOOTPRINT_EDIT_FRAME::ReCreateOptToolbar()
}
void FOOTPRINT_EDIT_FRAME::UpdateToolbarControlSizes()
{
if( m_mainToolBar )
{
// Update the item widths
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();
}
}
void FOOTPRINT_EDIT_FRAME::ReCreateLayerBox( bool aForceResizeToolbar )
{
if( m_selLayerBox == NULL || m_mainToolBar == NULL )

View File

@ -269,14 +269,11 @@ void PCB_EDIT_FRAME::ReCreateHToolbar()
m_mainToolBar->Add( ACTIONS::showFootprintBrowser );
m_mainToolBar->AddScaledSeparator( this );
if( !Kiface().IsSingle() )
{
m_mainToolBar->Add( ACTIONS::updatePcbFromSchematic );
}
else
{
m_mainToolBar->Add( PCB_ACTIONS::importNetlist );
}
m_mainToolBar->Add( PCB_ACTIONS::runDRC );
@ -310,6 +307,10 @@ void PCB_EDIT_FRAME::ReCreateHToolbar()
}
#endif
// Go through and ensure the comboboxes are the correct size, since the strings in the
// box could have changed widths.
m_mainToolBar->UpdateControlWidth( ID_TOOLBARH_PCB_SELECT_LAYER );
// after adding the buttons to the toolbar, must call Realize() to reflect the changes
m_mainToolBar->KiRealize();
}
@ -485,24 +486,14 @@ void PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar()
if( m_auxiliaryToolBar )
{
UpdateTrackWidthSelectBox( m_SelTrackWidthBox );
UpdateViaSizeSelectBox( m_SelViaSizeBox );
UpdateGridSelectBox();
// combobox sizes can have changed: apply new best sizes
wxAuiToolBarItem* item = m_auxiliaryToolBar->FindTool( ID_AUX_TOOLBAR_PCB_TRACK_WIDTH );
item->SetMinSize( m_SelTrackWidthBox->GetBestSize() );
item = m_auxiliaryToolBar->FindTool( ID_AUX_TOOLBAR_PCB_VIA_SIZE );
item->SetMinSize( m_SelViaSizeBox->GetBestSize() );
m_auxiliaryToolBar->KiRealize();
m_auimgr.Update();
return;
m_auxiliaryToolBar->ClearToolbar();
}
else
{
m_auxiliaryToolBar = new ACTION_TOOLBAR( this, ID_AUX_TOOLBAR, wxDefaultPosition, wxDefaultSize,
KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
m_auxiliaryToolBar->SetAuiManager( &m_auimgr );
}
m_auxiliaryToolBar = new ACTION_TOOLBAR( this, ID_AUX_TOOLBAR,
wxDefaultPosition, wxDefaultSize,
KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
/* Set up toolbar items */
@ -552,11 +543,43 @@ void PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar()
UpdateZoomSelectBox();
m_auxiliaryToolBar->AddControl( m_zoomSelectBox );
// Go through and ensure the comboboxes are the correct size, since the strings in the
// box could have changed widths.
m_auxiliaryToolBar->UpdateControlWidth( ID_AUX_TOOLBAR_PCB_TRACK_WIDTH );
m_auxiliaryToolBar->UpdateControlWidth( ID_AUX_TOOLBAR_PCB_VIA_SIZE );
m_auxiliaryToolBar->UpdateControlWidth( ID_ON_ZOOM_SELECT );
m_auxiliaryToolBar->UpdateControlWidth( ID_ON_GRID_SELECT );
// after adding the buttons to the toolbar, must call Realize()
m_auxiliaryToolBar->KiRealize();
}
void PCB_EDIT_FRAME::UpdateToolbarControlSizes()
{
if( m_mainToolBar )
{
// 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 )
{
// Update the item widths
m_auxiliaryToolBar->UpdateControlWidth( ID_AUX_TOOLBAR_PCB_TRACK_WIDTH );
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();
}
}
static wxString ComboBoxUnits( EDA_UNITS aUnits, double aValue, bool aIncludeLabel = true )
{
wxString text;