Browse Source
Introduce a new number badge UI element for DRC and ERC reporting
Introduce a new number badge UI element for DRC and ERC reporting
This new badge allows for proper UI scaling and will not cut off the number being displayed. Fixes https://gitlab.com/kicad/code/kicad/-/issues/5734 Fixes https://gitlab.com/kicad/code/kicad/-/issues/60116.0.7
17 changed files with 378 additions and 187 deletions
-
1common/CMakeLists.txt
-
12common/dialogs/wx_html_report_panel.cpp
-
12common/dialogs/wx_html_report_panel_base.cpp
-
28common/dialogs/wx_html_report_panel_base.fbp
-
6common/dialogs/wx_html_report_panel_base.h
-
164common/widgets/number_badge.cpp
-
91common/widgets/ui_common.cpp
-
10eeschema/dialogs/dialog_erc.cpp
-
16eeschema/dialogs/dialog_erc_base.cpp
-
42eeschema/dialogs/dialog_erc_base.fbp
-
8eeschema/dialogs/dialog_erc_base.h
-
95include/widgets/number_badge.h
-
7include/widgets/ui_common.h
-
11pcbnew/dialogs/dialog_drc.cpp
-
20pcbnew/dialogs/dialog_drc_base.cpp
-
34pcbnew/dialogs/dialog_drc_base.fbp
-
8pcbnew/dialogs/dialog_drc_base.h
@ -0,0 +1,164 @@ |
|||
/*
|
|||
* This program source code file is part of KICAD, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2020 Kicad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|||
* or you may search the http://www.gnu.org website for the version 2 license,
|
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#include <gal/color4d.h>
|
|||
#include <widgets/number_badge.h>
|
|||
|
|||
|
|||
NUMBER_BADGE::NUMBER_BADGE( wxWindow* aParent, wxWindowID aId, const wxPoint& aPos, |
|||
const wxSize& aSize, int aStyles ) : |
|||
wxPanel( aParent, aId, aPos, aSize, aStyles ), |
|||
m_textSize( 10 ), |
|||
m_maxNumber( 1000 ), |
|||
m_currentNumber( 0 ), |
|||
m_showBadge( false ) |
|||
{ |
|||
computeSize(); |
|||
Bind( wxEVT_PAINT, &NUMBER_BADGE::onPaint, this ); |
|||
} |
|||
|
|||
|
|||
void NUMBER_BADGE::UpdateNumber( int aNumber, SEVERITY aSeverity ) |
|||
{ |
|||
m_showBadge = true; |
|||
m_currentNumber = aNumber; |
|||
|
|||
// Choose the colors of the badge rectangle and font
|
|||
if( aNumber < 0 ) |
|||
{ |
|||
m_showBadge = false; |
|||
} |
|||
else if( aNumber == 0 ) |
|||
{ |
|||
if( aSeverity == RPT_SEVERITY_ERROR || aSeverity == RPT_SEVERITY_WARNING ) |
|||
{ |
|||
m_badgeColour = KIGFX::COLOR4D( GREEN ).ToColour(); |
|||
m_textColour = *wxWHITE; |
|||
} |
|||
else |
|||
{ |
|||
m_showBadge = false; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
switch( aSeverity ) |
|||
{ |
|||
case RPT_SEVERITY_ERROR: |
|||
m_badgeColour = *wxRED; |
|||
m_textColour = *wxWHITE; |
|||
break; |
|||
|
|||
case RPT_SEVERITY_WARNING: |
|||
m_badgeColour = *wxYELLOW; |
|||
m_textColour = *wxBLACK; |
|||
break; |
|||
|
|||
case RPT_SEVERITY_ACTION: |
|||
m_badgeColour = KIGFX::COLOR4D( GREEN ).ToColour(); |
|||
m_textColour = *wxWHITE; |
|||
break; |
|||
|
|||
case RPT_SEVERITY_EXCLUSION: |
|||
case RPT_SEVERITY_INFO: |
|||
default: |
|||
m_badgeColour = *wxLIGHT_GREY; |
|||
m_textColour = *wxBLACK; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
// Force the badge UI to refresh so the new number and color is displayed
|
|||
Refresh(); |
|||
} |
|||
|
|||
|
|||
void NUMBER_BADGE::SetMaximumNumber( int aMax ) |
|||
{ |
|||
m_maxNumber = aMax; |
|||
computeSize(); |
|||
} |
|||
|
|||
|
|||
void NUMBER_BADGE::SetTextSize( int aSize ) |
|||
{ |
|||
m_textSize = aSize; |
|||
computeSize(); |
|||
} |
|||
|
|||
|
|||
void NUMBER_BADGE::computeSize() |
|||
{ |
|||
wxClientDC dc( this ); |
|||
|
|||
wxString test = wxString::Format( wxT( "%d" ), m_maxNumber ); |
|||
int len = test.length(); |
|||
|
|||
// Determine the size using the string "-999+" where the - on the front is for spacing from
|
|||
// the start of the rectangle so the number isn't close to the curved edge.
|
|||
test = "-"; |
|||
test.Pad( len, '9' ); |
|||
test += "+"; |
|||
|
|||
dc.SetFont( wxFont( m_textSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD ) ); |
|||
|
|||
SetMinSize( dc.GetTextExtent( test ) ); |
|||
} |
|||
|
|||
|
|||
void NUMBER_BADGE::onPaint( wxPaintEvent& aEvt ) |
|||
{ |
|||
// The drawing rectangle
|
|||
wxSize clientSize = GetSize(); |
|||
wxPaintDC dc( this ); |
|||
wxString text; |
|||
wxBrush brush; |
|||
|
|||
// Give the badge a transparent background to show the panel underneath
|
|||
dc.SetBackground( *wxTRANSPARENT_BRUSH ); |
|||
dc.Clear(); |
|||
|
|||
// We always draw a transparent background, but only draw the badge when it is needed
|
|||
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.
|
|||
wxRect rect( wxPoint( 0, 0 ), clientSize - wxSize( 1, 1 ) ); |
|||
|
|||
brush.SetStyle( wxBRUSHSTYLE_SOLID ); |
|||
brush.SetColour( m_badgeColour ); |
|||
dc.SetBrush( brush ); |
|||
dc.SetPen( wxPen( m_badgeColour, 0 ) ); |
|||
dc.DrawRoundedRectangle( rect, rect.height / 2 ); |
|||
|
|||
// Cap the number displayed and add the "+" to the end if required
|
|||
if( m_currentNumber > m_maxNumber ) |
|||
text = wxString::Format( wxT( "%d+" ), m_maxNumber ); |
|||
else |
|||
text = wxString::Format( wxT( "%d" ), m_currentNumber ); |
|||
|
|||
dc.SetFont( wxFont( m_textSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD ) ); |
|||
dc.SetTextForeground( m_textColour ); |
|||
dc.DrawLabel( text, wxRect( wxPoint( 0, 0 ), clientSize ), wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL ); |
|||
} |
@ -0,0 +1,95 @@ |
|||
/* |
|||
* This program source code file is part of KICAD, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2020 Kicad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|||
* or you may search the http://www.gnu.org website for the version 2 license, |
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#ifndef NUMBER_BADGE_H_ |
|||
#define NUMBER_BADGE_H_ |
|||
|
|||
#include <widgets/ui_common.h> |
|||
#include <wx/wx.h> |
|||
|
|||
/** |
|||
* A simple UI element that puts a number on top of a colored rounded rectangle with a fill |
|||
* color that shows the severity of the reports the number is counting (e.g. green, yellow, red). |
|||
* This badge will also automatically truncate the displayed number to the set maximum and display |
|||
* "+" at the end to represent it is truncated. |
|||
*/ |
|||
class NUMBER_BADGE : public wxPanel |
|||
{ |
|||
public: |
|||
/** |
|||
* Create a number badge with 10pt font and a maximum number of 1000. |
|||
*/ |
|||
NUMBER_BADGE( wxWindow* aParent, wxWindowID aId, const wxPoint& aPos, |
|||
const wxSize& aSize, int aStyles ); |
|||
|
|||
/** |
|||
* Update the number displayed on the badge. |
|||
* |
|||
* Severity to badge color mapping: |
|||
* - RPT_SEVERITY_ERROR = red badge |
|||
* - RPT_SEVERITY_WARNING = yellow badge |
|||
* - RPT_SEVERITY_ACTION = green badge |
|||
* - RPT_SEVERITY_EXCLUSION = light grey badge |
|||
* - RPT_SEVERITY_INFO = light grey badge |
|||
* |
|||
* @param aNumber is the new number to display. |
|||
* @param aSeverity is the new severity of the badge. |
|||
*/ |
|||
void UpdateNumber( int aNumber, SEVERITY aSeverity ); |
|||
|
|||
/** |
|||
* Set the maximum number to be shown on the badge. Any numbers greater than this |
|||
* will be displayed as the maximum number followed by "+". |
|||
* |
|||
* @param aMax is the maximum number |
|||
*/ |
|||
void SetMaximumNumber( int aMax ); |
|||
|
|||
/** |
|||
* Set the text size to use on the badge. |
|||
* |
|||
* @param aSize is the text size (in pt) to use on the badge |
|||
*/ |
|||
void SetTextSize( int aSize ); |
|||
|
|||
protected: |
|||
/** |
|||
* Helper function to compute the size of the badge |
|||
*/ |
|||
void computeSize(); |
|||
|
|||
/** |
|||
* Handler that actually paints the badge and the text. |
|||
*/ |
|||
void onPaint( wxPaintEvent& aEvt ); |
|||
|
|||
int m_textSize; // The text size to use |
|||
int m_maxNumber; // The maximum number allowed to be shown on the badge |
|||
|
|||
int m_currentNumber; // The current number to display |
|||
bool m_showBadge; // If true, displays the actual badge otherwise it is invisible |
|||
wxColour m_badgeColour; // The color of the badge |
|||
wxColour m_textColour; // The color of the text on the badge |
|||
}; |
|||
|
|||
#endif |
Write
Preview
Loading…
Cancel
Save
Reference in new issue