PROGRESS_REPORTER_BASE: call code to resize it only if the message has change.

In wxWidgets 3.15 (and perhaps older version) the call to GetTextExtent() probably
creates major issues when called too many times, at least oo msys2.
It was probably also time costly.
Calling it and resize the PROGRESS_REPORTER only when needed fixes these serious issues.
Issues happened only when the board has a lot of zones (when teardrops are added)
This commit is contained in:
jean-pierre charras 2022-08-01 13:13:54 +02:00
parent 225b03d702
commit d1ff8f4781
3 changed files with 24 additions and 6 deletions

View File

@ -34,7 +34,8 @@ PROGRESS_REPORTER_BASE::PROGRESS_REPORTER_BASE( int aNumPhases ) :
m_numPhases( aNumPhases ),
m_progress( 0 ),
m_maxProgress( 1000 ),
m_cancelled( false )
m_cancelled( false ),
m_messageChanged( false )
{
}
@ -63,6 +64,8 @@ void PROGRESS_REPORTER_BASE::AdvancePhase( const wxString& aMessage )
void PROGRESS_REPORTER_BASE::Report( const wxString& aMessage )
{
std::lock_guard<std::mutex> guard( m_mutex );
m_messageChanged = m_rptMessage != aMessage;
m_rptMessage = aMessage;
}

View File

@ -75,12 +75,21 @@ bool WX_PROGRESS_REPORTER::updateUI()
message = m_rptMessage;
}
int newWidth = GetTextExtent( m_rptMessage ).x;
if( newWidth > m_messageWidth )
// Perhaps the window size is too small if the new message to display is bigger
// than the previous message. in this case, resize the WX_PROGRESS_REPORTER window
// GetTextExtent has probably bugs in wxWidgets < 3.1.6, so calling it only when
// the message has changed is mandatory
if( m_messageChanged )
{
m_messageWidth = newWidth;
Fit();
int newWidth = GetTextExtent( m_rptMessage ).x;
if( newWidth > m_messageWidth )
{
m_messageWidth = newWidth;
Fit();
}
m_messageChanged = false;
}
bool diag = wxProgressDialog::Update( cur, message );

View File

@ -120,6 +120,12 @@ protected:
std::atomic_int m_progress;
std::atomic_int m_maxProgress;
std::atomic_bool m_cancelled;
// True if the displayed message has changed,
// so perhaps there is a need to resize the window
// Note the resize is made only if the size of the new message
// is bigger than the old message
std::atomic_bool m_messageChanged;
};