Fix margin between wxBitmapComboBox images and text in high DPI
Don't use FromDIP() with m_usedImgSize which is expressed in logical, and not DPI-independent, pixels already and also update the image size when the DPI changes. Closes #22436.
This commit is contained in:
committed by
Vadim Zeitlin
parent
76797ab9e1
commit
80a736250e
@@ -56,7 +56,7 @@ void wxBitmapComboBoxBase::Init()
|
|||||||
m_fontHeight = 0;
|
m_fontHeight = 0;
|
||||||
m_imgAreaWidth = 0;
|
m_imgAreaWidth = 0;
|
||||||
m_indent = 0;
|
m_indent = 0;
|
||||||
m_usedImgSize = wxSize(-1, -1);
|
m_usedImgSize = wxDefaultSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxBitmapComboBoxBase::UpdateInternals()
|
void wxBitmapComboBoxBase::UpdateInternals()
|
||||||
@@ -66,6 +66,9 @@ void wxBitmapComboBoxBase::UpdateInternals()
|
|||||||
|
|
||||||
while ( m_bitmapbundles.size() < GetItemContainer()->GetCount() )
|
while ( m_bitmapbundles.size() < GetItemContainer()->GetCount() )
|
||||||
m_bitmapbundles.push_back( wxBitmapBundle() );
|
m_bitmapbundles.push_back( wxBitmapBundle() );
|
||||||
|
|
||||||
|
if ( m_usedImgSize.x != -1 && m_bitmapbundles.size() > 0 )
|
||||||
|
m_usedImgSize = m_bitmapbundles[0].GetPreferredLogicalSizeFor(GetControl());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -94,8 +97,7 @@ void wxBitmapComboBoxBase::BCBDoClear()
|
|||||||
{
|
{
|
||||||
m_bitmapbundles.clear();
|
m_bitmapbundles.clear();
|
||||||
|
|
||||||
m_usedImgSize.x = -1;
|
m_usedImgSize = wxDefaultSize;
|
||||||
m_usedImgSize.y = -1;
|
|
||||||
|
|
||||||
DetermineIndent();
|
DetermineIndent();
|
||||||
}
|
}
|
||||||
@@ -117,14 +119,11 @@ bool wxBitmapComboBoxBase::OnAddBitmap(const wxBitmapBundle& bitmap)
|
|||||||
if ( bitmap.IsOk() )
|
if ( bitmap.IsOk() )
|
||||||
{
|
{
|
||||||
wxSize bmpDefaultSize = bitmap.GetPreferredLogicalSizeFor(GetControl());
|
wxSize bmpDefaultSize = bitmap.GetPreferredLogicalSizeFor(GetControl());
|
||||||
int width = bmpDefaultSize.GetWidth();
|
|
||||||
int height = bmpDefaultSize.GetHeight();
|
|
||||||
|
|
||||||
if ( m_usedImgSize.x < 0 )
|
if ( m_usedImgSize.x < 0 )
|
||||||
{
|
{
|
||||||
// If size not yet determined, get it from this image.
|
// If size not yet determined, get it from this image.
|
||||||
m_usedImgSize.x = width;
|
m_usedImgSize = bmpDefaultSize;
|
||||||
m_usedImgSize.y = height;
|
|
||||||
|
|
||||||
// Adjust control size to vertically fit the bitmap
|
// Adjust control size to vertically fit the bitmap
|
||||||
wxWindow* ctrl = GetControl();
|
wxWindow* ctrl = GetControl();
|
||||||
@@ -137,7 +136,7 @@ bool wxBitmapComboBoxBase::OnAddBitmap(const wxBitmapBundle& bitmap)
|
|||||||
DetermineIndent();
|
DetermineIndent();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxCHECK_MSG( width == m_usedImgSize.x && height == m_usedImgSize.y,
|
wxCHECK_MSG( bmpDefaultSize == m_usedImgSize,
|
||||||
false,
|
false,
|
||||||
"you can only add images of same size" );
|
"you can only add images of same size" );
|
||||||
|
|
||||||
@@ -155,7 +154,7 @@ int wxBitmapComboBoxBase::DetermineIndent()
|
|||||||
|
|
||||||
if ( m_usedImgSize.x > 0 )
|
if ( m_usedImgSize.x > 0 )
|
||||||
{
|
{
|
||||||
indent = GetControl()->FromDIP(m_usedImgSize.x)
|
indent = m_usedImgSize.x
|
||||||
+ GetControl()->FromDIP(IMAGE_SPACING_LEFT)
|
+ GetControl()->FromDIP(IMAGE_SPACING_LEFT)
|
||||||
+ GetControl()->FromDIP(IMAGE_SPACING_RIGHT);
|
+ GetControl()->FromDIP(IMAGE_SPACING_RIGHT);
|
||||||
m_imgAreaWidth = indent;
|
m_imgAreaWidth = indent;
|
||||||
|
|||||||
Reference in New Issue
Block a user