summaryrefslogtreecommitdiff
path: root/wx+/no_flicker.h
blob: ea9efb4d61333e904e9da4049035ac26000f93d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// **************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: http://www.gnu.org/licenses/gpl.html       *
// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved        *
// **************************************************************************

#ifndef NO_FLICKER_HEADER_893421590321532
#define NO_FLICKER_HEADER_893421590321532

#include <wx/textctrl.h>
#include <wx/stattext.h>

namespace zen
{
inline
void setText(wxTextCtrl& control, const wxString& newText, bool* additionalLayoutChange = nullptr)
{
    if (additionalLayoutChange && !*additionalLayoutChange) //never revert from true to false!
        *additionalLayoutChange = control.GetValue().length() != newText.length(); //avoid screen flicker: update layout only when necessary

    if (control.GetValue() != newText)
        control.ChangeValue(newText);
}

inline
void setText(wxStaticText& control, const wxString& newText, bool* additionalLayoutChange = nullptr)
{
    if (additionalLayoutChange && !*additionalLayoutChange)
        *additionalLayoutChange = control.GetLabel().length() != newText.length(); //avoid screen flicker: update layout only when necessary

    if (control.GetLabel() != newText)
        control.SetLabel(newText);
}
}

#endif //NO_FLICKER_HEADER_893421590321532
bgstack15