Adjust DRC badge spacing on OSX.

Also added dynamic badge sizing based on number of digits.
This commit is contained in:
Jeff Young 2020-10-20 16:49:52 +01:00
parent 12b106aba4
commit f772e49d25
2 changed files with 35 additions and 9 deletions

View File

@ -107,6 +107,26 @@ void NUMBER_BADGE::SetTextSize( int aSize )
}
// OSX has prevalent badges in the application bar at the bottom of the screen so we try to
// match those. Other platforms may also need tweaks to spacing, fontweight, etc.
#ifdef __WXMAC__
#define BADGE_FONTWEIGHT wxFONTWEIGHT_NORMAL
#define PLATFORM_FUDGE_X 0.8
#define PLATFORM_FUDGE_Y 1.6
#endif
#ifdef __WXGTK__
#define BADGE_FONTWEIGHT wxFONTWEIGHT_BOLD
#define PLATFORM_FUDGE_X 1.0
#define PLATFORM_FUDGE_Y 1.0
#endif
#ifdef __WXMSW__
#define BADGE_FONTWEIGHT wxFONTWEIGHT_BOLD
#define PLATFORM_FUDGE_X 1.0
#define PLATFORM_FUDGE_Y 1.0
#endif
void NUMBER_BADGE::computeSize()
{
wxClientDC dc( this );
@ -120,9 +140,14 @@ void NUMBER_BADGE::computeSize()
test.Pad( len, '9' );
test += "+";
dc.SetFont( wxFont( m_textSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD ) );
dc.SetFont( wxFont( m_textSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, BADGE_FONTWEIGHT ) );
wxSize size = dc.GetTextExtent( test );
SetMinSize( dc.GetTextExtent( test ) );
size.y *= PLATFORM_FUDGE_Y;
size.x = std::max<int>( size.x * PLATFORM_FUDGE_X, size.y );
SetMinSize( size );
SetSize( size );
}
@ -142,8 +167,8 @@ void NUMBER_BADGE::onPaint( wxPaintEvent& aEvt )
if( !m_showBadge )
return;
// The rectangle the color is drawn in needs to be shrunk by 1px on each axis because for some reason it seems
// to be padded out by 1px and is cutoff otherwise.
// The rectangle the color is drawn in needs to be shrunk by 1px on each axis because for some
// reason it seems to be padded out by 1px and is cutoff otherwise.
wxRect rect( wxPoint( 0, 0 ), clientSize - wxSize( 1, 1 ) );
brush.SetStyle( wxBRUSHSTYLE_SOLID );
@ -158,7 +183,7 @@ void NUMBER_BADGE::onPaint( wxPaintEvent& aEvt )
else
text = wxString::Format( wxT( "%d" ), m_currentNumber );
dc.SetFont( wxFont( m_textSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD ) );
dc.SetFont( wxFont( m_textSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, BADGE_FONTWEIGHT ) );
dc.SetTextForeground( m_textColour );
dc.DrawLabel( text, wxRect( wxPoint( 0, 0 ), clientSize ), wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL );
}

View File

@ -85,10 +85,6 @@ DIALOG_DRC::DIALOG_DRC( PCB_EDIT_FRAME* aEditorFrame, wxWindow* aParent ) :
m_sdbSizerOK->SetDefault();
m_errorsBadge->SetMaximumNumber( 999 );
m_warningsBadge->SetMaximumNumber( 999 );
m_exclusionsBadge->SetMaximumNumber( 999 );
initValues();
syncCheckboxes();
@ -864,7 +860,12 @@ void DIALOG_DRC::updateDisplayedCounts()
numWarnings = -1;
}
m_errorsBadge->SetMaximumNumber( numErrors );
m_errorsBadge->UpdateNumber( numErrors, RPT_SEVERITY_ERROR );
m_warningsBadge->SetMaximumNumber( numWarnings );
m_warningsBadge->UpdateNumber( numWarnings, RPT_SEVERITY_WARNING );
m_exclusionsBadge->SetMaximumNumber( numExcluded );
m_exclusionsBadge->UpdateNumber( numExcluded, RPT_SEVERITY_EXCLUSION );
}