Fold best size and ellipsis handling in AutoResizeIfNecessary()

Refactor wxStaticText code to use AutoResizeIfNecessary() for all the
updates done after the label extent changes (whether it's due to the
change of the label itself or the font used for rendering it).

There should be no changes in behaviour after this commit except for a
small bug fix in wxGenericStaticText when setting label with markup:
this didn't invalidate the best size before, but does now.
This commit is contained in:
Vadim Zeitlin
2018-01-16 16:22:51 +01:00
parent 52e71680ea
commit 6651999719
5 changed files with 21 additions and 40 deletions

View File

@@ -205,13 +205,20 @@ void wxStaticTextBase::Wrap(int width)
void wxStaticTextBase::AutoResizeIfNecessary()
{
// adjust the size of the window to fit to the label unless autoresizing is
// disabled
if ( !HasFlag(wxST_NO_AUTORESIZE) )
{
DoSetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord,
wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
}
// This method is only called if either the label or the font changed, i.e.
// if the label extent changed, so the best size is not the same neither
// any more.
InvalidateBestSize();
if ( IsEllipsized() ) // if ellipsize is ON, then we don't want to get resized!
return;
// This flag is specifically used to prevent the control from resizing even
// when its label changes.
if ( HasFlag(wxST_NO_AUTORESIZE) )
return;
SetSize(GetBestSize());
}
// ----------------------------------------------------------------------------