Scale all sizers and spacers on a DPI change
Do not only scale the first sizer of a window, but scale all its child sizers and spacers recursively. Closes https://github.com/wxWidgets/wxWidgets/pull/1804 See #18649.
This commit is contained in:
committed by
Vadim Zeitlin
parent
f1714b3d69
commit
4072c0634b
@@ -4851,27 +4851,17 @@ static void ScaleCoordIfSet(int& coord, float scaleFactor)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
// Called from MSWUpdateonDPIChange() to recursively update the window
|
||||||
wxWindowMSW::MSWUpdateOnDPIChange(const wxSize& oldDPI, const wxSize& newDPI)
|
// sizer and any child sizers and spacers.
|
||||||
|
static void UpdateSizerOnDPIChange(wxSizer* sizer, float scaleFactor)
|
||||||
{
|
{
|
||||||
// update min and max size if necessary
|
if ( !sizer )
|
||||||
const float scaleFactor = (float)newDPI.y / oldDPI.y;
|
|
||||||
|
|
||||||
ScaleCoordIfSet(m_minHeight, scaleFactor);
|
|
||||||
ScaleCoordIfSet(m_minWidth, scaleFactor);
|
|
||||||
ScaleCoordIfSet(m_maxHeight, scaleFactor);
|
|
||||||
ScaleCoordIfSet(m_maxWidth, scaleFactor);
|
|
||||||
|
|
||||||
InvalidateBestSize();
|
|
||||||
|
|
||||||
// update font if necessary
|
|
||||||
MSWUpdateFontOnDPIChange(newDPI);
|
|
||||||
|
|
||||||
// update sizers
|
|
||||||
if ( GetSizer() )
|
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for ( wxSizerItemList::compatibility_iterator
|
for ( wxSizerItemList::compatibility_iterator
|
||||||
node = GetSizer()->GetChildren().GetFirst();
|
node = sizer->GetChildren().GetFirst();
|
||||||
node;
|
node;
|
||||||
node = node->GetNext() )
|
node = node->GetNext() )
|
||||||
{
|
{
|
||||||
@@ -4893,10 +4883,32 @@ wxWindowMSW::MSWUpdateOnDPIChange(const wxSize& oldDPI, const wxSize& newDPI)
|
|||||||
ScaleCoordIfSet(size.x, scaleFactor);
|
ScaleCoordIfSet(size.x, scaleFactor);
|
||||||
ScaleCoordIfSet(size.y, scaleFactor);
|
ScaleCoordIfSet(size.y, scaleFactor);
|
||||||
sizerItem->SetDimension(wxDefaultPosition, size);
|
sizerItem->SetDimension(wxDefaultPosition, size);
|
||||||
|
|
||||||
|
// Update any child sizers if this is a sizer
|
||||||
|
UpdateSizerOnDPIChange(sizerItem->GetSizer(), scaleFactor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wxWindowMSW::MSWUpdateOnDPIChange(const wxSize& oldDPI, const wxSize& newDPI)
|
||||||
|
{
|
||||||
|
// update min and max size if necessary
|
||||||
|
const float scaleFactor = (float)newDPI.y / oldDPI.y;
|
||||||
|
|
||||||
|
ScaleCoordIfSet(m_minHeight, scaleFactor);
|
||||||
|
ScaleCoordIfSet(m_minWidth, scaleFactor);
|
||||||
|
ScaleCoordIfSet(m_maxHeight, scaleFactor);
|
||||||
|
ScaleCoordIfSet(m_maxWidth, scaleFactor);
|
||||||
|
|
||||||
|
InvalidateBestSize();
|
||||||
|
|
||||||
|
// update font if necessary
|
||||||
|
MSWUpdateFontOnDPIChange(newDPI);
|
||||||
|
|
||||||
|
// update sizers
|
||||||
|
UpdateSizerOnDPIChange(GetSizer(), scaleFactor);
|
||||||
|
|
||||||
// update children
|
// update children
|
||||||
for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
|
for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
|
||||||
node;
|
node;
|
||||||
|
Reference in New Issue
Block a user