Don't refresh wxStaticText if its label didn't really change

Optimize calling SetLabel() with the same label as the current one, this
seems to happen quite often in practice and results in flicker, so check
for it explicitly.
This commit is contained in:
Vadim Zeitlin
2017-07-16 02:29:49 +02:00
parent 4e2684c155
commit dfd03f5fee
6 changed files with 28 additions and 0 deletions

View File

@@ -99,6 +99,18 @@ public:
*/
bool IsEllipsized() const;
/**
Change the label shown in the control.
Notice that since wxWidgets 3.1.1 this function is guaranteed not to do
anything if the label didn't really change, so there is no benefit to
checking if the new label is different from the current one in the
application code.
@see wxControl::SetLabel()
*/
virtual void SetLabel(const wxString& label);
/**
This functions wraps the controls label so that each of its lines becomes at
most @a width pixels wide if possible (the lines are broken at words

View File

@@ -144,6 +144,9 @@ void wxStaticText::GTKDoSetLabel(GTKLabelSetter setter, const wxString& label)
void wxStaticText::SetLabel(const wxString& label)
{
if ( label == m_labelOrig )
return;
m_labelOrig = label;
GTKDoSetLabel(&wxStaticText::GTKSetLabelForLabel, label);

View File

@@ -71,6 +71,9 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id,
void wxStaticText::SetLabel(const wxString& label)
{
if ( label == m_labelOrig )
return;
m_labelOrig = label; // save original label
// Motif does not support ellipsized labels natively

View File

@@ -150,6 +150,10 @@ void wxStaticText::DoSetSize(int x, int y, int w, int h, int sizeFlags)
void wxStaticText::SetLabel(const wxString& label)
{
// If the label doesn't really change, avoid flicker by not doing anything.
if ( label == m_labelOrig )
return;
#ifdef SS_ENDELLIPSIS
long styleReal = ::GetWindowLong(GetHwnd(), GWL_STYLE);
if ( HasFlag(wxST_ELLIPSIZE_END) )

View File

@@ -58,6 +58,9 @@ bool wxStaticText::Create( wxWindow *parent,
void wxStaticText::SetLabel(const wxString& label)
{
if ( label == m_labelOrig )
return;
m_labelOrig = label;
// middle/end ellipsization is handled by the OS:

View File

@@ -70,6 +70,9 @@ void wxStaticText::DoDraw(wxControlRenderer *renderer)
void wxStaticText::SetLabel(const wxString& str)
{
if ( label == m_labelOrig )
return;
// save original label
m_labelOrig = str;