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() void ACTION_TOOLBAR::ClearToolbar()
{ {
// Clear all the maps keeping track of our items on the toolbar // 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(); updateView();
Show( true ); 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(); UpdateZoomSelectBox();
m_mainToolBar->AddControl( m_zoomSelectBox ); 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 // after adding the buttons to the toolbar, must call Realize() to reflect
// the changes // the changes
m_mainToolBar->Realize(); 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 ) void DISPLAY_FOOTPRINTS_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
{ {
auto cfg = dynamic_cast<CVPCB_SETTINGS*>( aCfg ); auto cfg = dynamic_cast<CVPCB_SETTINGS*>( aCfg );

View File

@ -51,6 +51,7 @@ public:
void ReCreateHToolbar() override; void ReCreateHToolbar() override;
void ReCreateVToolbar() override; void ReCreateVToolbar() override;
void ReCreateOptToolbar() override; void ReCreateOptToolbar() override;
void UpdateToolbarControlSizes() override;
/** /**
* Refresh the full display for this frame: * 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 // Ensure the window is on top
Raise(); 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 ReCreateMenuBar() override;
void UpdateStatusBar() override; void UpdateStatusBar() override;
void UpdateToolbarControlSizes() override;
/** /**
* @return 0 for fast mode (not fully compatible with negative objects) * @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_MAIN_MENUBAR = ID_END_LIST,
ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE, ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE,
ID_TOOLBARH_GERBER_DATA_TEXT_BOX,
ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE, ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE,
ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE, ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE,

View File

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

View File

@ -207,6 +207,11 @@ public:
virtual void ReCreateOptToolbar() = 0; virtual void ReCreateOptToolbar() = 0;
virtual void ReCreateAuxiliaryToolbar() { } 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. * 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 ); 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. * 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 // Ensure the window is on top
Raise(); 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(); void setupTools();
// Virtual basic functions: // Virtual basic functions:
void ReCreateHToolbar() override; void ReCreateHToolbar() override;
void UpdateToolbarControlSizes() override;
void SetPageSettings(const PAGE_INFO&) override; void SetPageSettings(const PAGE_INFO&) override;
const PAGE_INFO& GetPageSettings () const override; const PAGE_INFO& GetPageSettings () const override;

View File

@ -117,6 +117,11 @@ void PL_EDITOR_FRAME::ReCreateHToolbar()
m_pageSelectBox->SetSelection( 0 ); 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 // after adding the buttons to the toolbar, must call Realize() to reflect the changes
m_mainToolBar->KiRealize(); m_mainToolBar->KiRealize();
} }
@ -172,3 +177,17 @@ void PL_EDITOR_FRAME::ReCreateOptToolbar()
m_optionsToolBar->KiRealize(); 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 // Ensure the window is on top
Raise(); Raise();
Show( true ); 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 ReCreateVToolbar() override;
void ReCreateOptToolbar() override; void ReCreateOptToolbar() override;
void UpdateToolbarControlSizes() override;
/** /**
* @brief (Re)Create the menubar for the Footprint Editor frame * @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 #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 ReCreateVToolbar() override;
void ReCreateOptToolbar() override; void ReCreateOptToolbar() override;
void ReCreateMenuBar() override; void ReCreateMenuBar() override;
void UpdateToolbarControlSizes() override;
/** /**
* Recreate the layer box by clearing the old list and building a new one from the new * 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 ); ReCreateLayerBox( false );
m_mainToolBar->AddControl( m_selLayerBox ); 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 // after adding the buttons to the toolbar, must call Realize() to reflect the changes
m_mainToolBar->KiRealize(); 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 ) void FOOTPRINT_EDIT_FRAME::ReCreateLayerBox( bool aForceResizeToolbar )
{ {
if( m_selLayerBox == NULL || m_mainToolBar == NULL ) 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->Add( ACTIONS::showFootprintBrowser );
m_mainToolBar->AddScaledSeparator( this ); m_mainToolBar->AddScaledSeparator( this );
if( !Kiface().IsSingle() ) if( !Kiface().IsSingle() )
{
m_mainToolBar->Add( ACTIONS::updatePcbFromSchematic ); m_mainToolBar->Add( ACTIONS::updatePcbFromSchematic );
}
else else
{
m_mainToolBar->Add( PCB_ACTIONS::importNetlist ); m_mainToolBar->Add( PCB_ACTIONS::importNetlist );
}
m_mainToolBar->Add( PCB_ACTIONS::runDRC ); m_mainToolBar->Add( PCB_ACTIONS::runDRC );
@ -310,6 +307,10 @@ void PCB_EDIT_FRAME::ReCreateHToolbar()
} }
#endif #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 // after adding the buttons to the toolbar, must call Realize() to reflect the changes
m_mainToolBar->KiRealize(); m_mainToolBar->KiRealize();
} }
@ -485,24 +486,14 @@ void PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar()
if( m_auxiliaryToolBar ) if( m_auxiliaryToolBar )
{ {
UpdateTrackWidthSelectBox( m_SelTrackWidthBox ); m_auxiliaryToolBar->ClearToolbar();
UpdateViaSizeSelectBox( m_SelViaSizeBox ); }
UpdateGridSelectBox(); else
{
// combobox sizes can have changed: apply new best sizes m_auxiliaryToolBar = new ACTION_TOOLBAR( this, ID_AUX_TOOLBAR, wxDefaultPosition, wxDefaultSize,
wxAuiToolBarItem* item = m_auxiliaryToolBar->FindTool( ID_AUX_TOOLBAR_PCB_TRACK_WIDTH ); KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
item->SetMinSize( m_SelTrackWidthBox->GetBestSize() ); m_auxiliaryToolBar->SetAuiManager( &m_auimgr );
item = m_auxiliaryToolBar->FindTool( ID_AUX_TOOLBAR_PCB_VIA_SIZE );
item->SetMinSize( m_SelViaSizeBox->GetBestSize() );
m_auxiliaryToolBar->KiRealize();
m_auimgr.Update();
return;
} }
m_auxiliaryToolBar = new ACTION_TOOLBAR( this, ID_AUX_TOOLBAR,
wxDefaultPosition, wxDefaultSize,
KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
/* Set up toolbar items */ /* Set up toolbar items */
@ -552,11 +543,43 @@ void PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar()
UpdateZoomSelectBox(); UpdateZoomSelectBox();
m_auxiliaryToolBar->AddControl( m_zoomSelectBox ); 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() // after adding the buttons to the toolbar, must call Realize()
m_auxiliaryToolBar->KiRealize(); 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 ) static wxString ComboBoxUnits( EDA_UNITS aUnits, double aValue, bool aIncludeLabel = true )
{ {
wxString text; wxString text;