Ensure the layer dropdowns are correctly sized

On GTK, the layer dropdown was sized based on an empty list,
so for non-default fonts it would be undersized and cutoff
the font.
This commit is contained in:
Ian McInerney 2021-04-02 21:33:31 +01:00
parent bb95761642
commit 1931677316
4 changed files with 36 additions and 51 deletions

View File

@ -1,15 +1,9 @@
/**
* @file gbr_layer_box_selector.cpp
* @brief a derived class of LAYER_BOX_SELECTOR to handle the layer box selector
* in GerbView
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2016 Jean-Pierre Charras <jp.charras at wanadoo.fr>
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2016 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 1992-2021 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -54,11 +48,21 @@ void GBR_LAYER_BOX_SELECTOR::Resync()
Append( getLayerName( layerid ), bmp, (void*)(intptr_t) layerid );
}
// Ensure the width of the widget is enough to show the text and the icon
SetMinSize( wxSize( -1, -1 ) );
int minwidth = GetBestSize().x + BM_SIZE + 10;
SetMinSize( wxSize( minwidth, -1 ) );
// Ensure the size of the widget is enough to show the text and the icon
// We have to have a selected item when doing this, because otherwise GTK
// will just choose a random size that might not fit the actual data
// (such as in cases where the font size is very large). So we select
// the first item, get the size of the control and make that the minimum size,
// then remove the selection (which was the initial state).
SetSelection( 0 );
SetMinSize( wxSize( -1, -1 ) );
wxSize bestSize = GetBestSize();
bestSize.x = GetBestSize().x + BM_SIZE + 10;
SetMinSize( bestSize );
SetSelection( wxNOT_FOUND );
Thaw();
}

View File

@ -1,15 +1,9 @@
/**
* @file class_pcb_layer_box_selector.cpp
* @brief a derived class of LAYER_BOX_SELECTOR to handle the layer box selector
* in Pcbnew
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2015 Jean-Pierre Charras <jean-pierre.charras@ujf-grenoble.fr>
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -36,9 +30,7 @@
#include <pcb_layer_box_selector.h>
#include <tools/pcb_actions.h>
#include <wx/dcclient.h>
// translate aLayer to its hotkey
// translate aLayer to its action
static TOOL_ACTION* layer2action( PCB_LAYER_ID aLayer )
{
switch( aLayer )
@ -85,23 +77,17 @@ static TOOL_ACTION* layer2action( PCB_LAYER_ID aLayer )
// Reload the Layers
void PCB_LAYER_BOX_SELECTOR::Resync()
{
Freeze();
Clear();
// Tray to fix a minimum width fot the BitmapComboBox
int minwidth = 80;
wxClientDC dc( GetParent() ); // The DC for "this" is not always initialized
const int BM_SIZE = 14;
LSET show = LSET::AllLayersMask() & ~m_layerMaskDisable;
LSET activated = getEnabledLayers() & ~m_layerMaskDisable;
wxString layerstatus;
for( LSEQ seq = show.UIOrder(); seq; ++seq )
for( PCB_LAYER_ID layerid : show.UIOrder() )
{
PCB_LAYER_ID layerid = *seq;
if( !m_showNotEnabledBrdlayers && !activated[layerid] )
continue;
else if( !activated[layerid] )
@ -123,24 +109,27 @@ void PCB_LAYER_BOX_SELECTOR::Resync()
}
Append( layername, bmp, (void*)(intptr_t) layerid );
int w, h;
dc.GetTextExtent ( layername, &w, &h );
minwidth = std::max( minwidth, w );
}
if( !m_undefinedLayerName.IsEmpty() )
{
Append( m_undefinedLayerName, wxNullBitmap, (void*)(intptr_t)UNDEFINED_LAYER );
int w, h;
dc.GetTextExtent ( m_undefinedLayerName, &w, &h );
minwidth = std::max( minwidth, w );
}
// Ensure the size of the widget is enough to show the text and the icon
// We have to have a selected item when doing this, because otherwise GTK
// will just choose a random size that might not fit the actual data
// (such as in cases where the font size is very large). So we select
// the first item, get the size of the control and make that the minimum size,
// then remove the selection (which was the initial state).
SetSelection( 0 );
// Approximate bitmap size and margins
minwidth += BM_SIZE + 32 + ConvertDialogToPixels( wxSize( 8, 0 ) ).x;
SetMinSize( wxSize( minwidth, -1 ) );
SetMinSize( wxSize( -1, -1 ) );
wxSize bestSize = GetBestSize();
bestSize.x = GetBestSize().x + BM_SIZE + 10;
SetMinSize( bestSize );
SetSelection( wxNOT_FOUND );
Thaw();
}

View File

@ -239,11 +239,7 @@ void FOOTPRINT_EDIT_FRAME::ReCreateLayerBox( bool aForceResizeToolbar )
m_selLayerBox->Resync();
if( aForceResizeToolbar )
{
// the layer box can have its size changed
// Update the aui manager, to take in account the new size
m_auimgr.Update();
}
UpdateToolbarControlSizes();
}

View File

@ -716,11 +716,7 @@ void PCB_EDIT_FRAME::ReCreateLayerBox( bool aForceResizeToolbar )
m_SelLayerBox->Resync();
if( aForceResizeToolbar )
{
// the layer box can have its size changed
// Update the aui manager, to take in account the new size
m_auimgr.Update();
}
UpdateToolbarControlSizes();
}