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/6011
This commit is contained in:
Ian McInerney 2020-10-20 02:32:49 +01:00
parent 0d5b5bf8c3
commit 7c9acc605d
17 changed files with 378 additions and 187 deletions

View File

@ -223,6 +223,7 @@ set( COMMON_WIDGET_SRCS
widgets/layer_box_selector.cpp
widgets/lib_tree.cpp
widgets/mathplot.cpp
widgets/number_badge.cpp
widgets/paged_dialog.cpp
widgets/progress_reporter.cpp
widgets/split_button.cpp

View File

@ -135,10 +135,10 @@ void WX_HTML_REPORT_PANEL::scrollToBottom()
void WX_HTML_REPORT_PANEL::updateBadges()
{
int count = Count(RPT_SEVERITY_ERROR );
m_errorsBadge->SetBitmap( MakeBadge( RPT_SEVERITY_ERROR, count, m_errorsBadge, 2 ) );
m_errorsBadge->UpdateNumber( count, RPT_SEVERITY_ERROR );
count = Count(RPT_SEVERITY_WARNING );
m_warningsBadge->SetBitmap( MakeBadge( RPT_SEVERITY_WARNING, count, m_warningsBadge, 2 ) );
m_warningsBadge->UpdateNumber( count, RPT_SEVERITY_WARNING );
}

View File

@ -42,18 +42,14 @@ WX_HTML_REPORT_PANEL_BASE::WX_HTML_REPORT_PANEL_BASE( wxWindow* parent, wxWindow
m_checkBoxShowErrors = new wxCheckBox( m_box->GetStaticBox(), wxID_ANY, _("Errors"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerBottom->Add( m_checkBoxShowErrors, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
m_errorsBadge = new wxStaticBitmap( m_box->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
m_errorsBadge->SetMinSize( wxSize( 20,20 ) );
bSizerBottom->Add( m_errorsBadge, 0, wxBOTTOM|wxRIGHT|wxTOP|wxALIGN_CENTER_VERTICAL, 4 );
m_errorsBadge = new NUMBER_BADGE( m_box->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
bSizerBottom->Add( m_errorsBadge, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxTOP, 4 );
m_checkBoxShowWarnings = new wxCheckBox( m_box->GetStaticBox(), wxID_ANY, _("Warnings"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerBottom->Add( m_checkBoxShowWarnings, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
m_warningsBadge = new wxStaticBitmap( m_box->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
m_warningsBadge->SetMinSize( wxSize( 20,20 ) );
bSizerBottom->Add( m_warningsBadge, 0, wxBOTTOM|wxRIGHT|wxTOP|wxALIGN_CENTER_VERTICAL, 4 );
m_warningsBadge = new NUMBER_BADGE( m_box->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
bSizerBottom->Add( m_warningsBadge, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxTOP, 4 );
m_checkBoxShowActions = new wxCheckBox( m_box->GetStaticBox(), wxID_ANY, _("Actions"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerBottom->Add( m_checkBoxShowActions, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );

View File

@ -344,9 +344,9 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">4</property>
<property name="flag">wxBOTTOM|wxRIGHT|wxTOP|wxALIGN_CENTER_VERTICAL</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxTOP</property>
<property name="proportion">0</property>
<object class="wxStaticBitmap" expanded="1">
<object class="CustomControl" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -357,13 +357,15 @@
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="class">NUMBER_BADGE</property>
<property name="close_button">1</property>
<property name="construction"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="declaration"></property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
@ -375,12 +377,13 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="include">#include &lt;widgets/number_badge.h&gt;</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">20,20</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_errorsBadge</property>
<property name="pane_border">1</property>
@ -390,9 +393,10 @@
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="settings"></property>
<property name="show">1</property>
<property name="size"></property>
<property name="subclass">; forward_declare</property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
@ -467,9 +471,9 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">4</property>
<property name="flag">wxBOTTOM|wxRIGHT|wxTOP|wxALIGN_CENTER_VERTICAL</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxTOP</property>
<property name="proportion">0</property>
<object class="wxStaticBitmap" expanded="1">
<object class="CustomControl" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -480,13 +484,15 @@
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="class">NUMBER_BADGE</property>
<property name="close_button">1</property>
<property name="construction"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="declaration"></property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
@ -498,12 +504,13 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="include">#include &lt;widgets/number_badge.h&gt;</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">20,20</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_warningsBadge</property>
<property name="pane_border">1</property>
@ -513,9 +520,10 @@
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="settings"></property>
<property name="show">1</property>
<property name="size"></property>
<property name="subclass">; forward_declare</property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>

View File

@ -18,10 +18,10 @@
#include <wx/string.h>
#include <wx/stattext.h>
#include <wx/checkbox.h>
#include <widgets/number_badge.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/statbmp.h>
#include <wx/button.h>
#include <wx/sizer.h>
#include <wx/statbox.h>
@ -44,9 +44,9 @@ class WX_HTML_REPORT_PANEL_BASE : public wxPanel
wxStaticText* m_staticTextShow;
wxCheckBox* m_checkBoxShowAll;
wxCheckBox* m_checkBoxShowErrors;
wxStaticBitmap* m_errorsBadge;
NUMBER_BADGE* m_errorsBadge;
wxCheckBox* m_checkBoxShowWarnings;
wxStaticBitmap* m_warningsBadge;
NUMBER_BADGE* m_warningsBadge;
wxCheckBox* m_checkBoxShowActions;
wxCheckBox* m_checkBoxShowInfos;
wxButton* m_btnSaveReportToFile;

View File

@ -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 );
}

View File

@ -30,97 +30,6 @@ int KIUI::GetStdMargin()
}
#define BADGE_SIZE 24
#define BADGE_FONT_SIZE 10
wxBitmap MakeBadge( SEVERITY aStyle, int aCount, wxWindow* aWindow, int aDepth )
{
wxSize size( BADGE_SIZE, BADGE_SIZE );
wxBitmap bitmap( size );
wxBrush brush;
wxMemoryDC badgeDC;
wxColour badgeColour;
wxColour textColour;
wxColour backColour;
int fontSize = BADGE_FONT_SIZE;
if( aCount > 99 )
fontSize--;
badgeDC.SelectObject( bitmap );
brush.SetStyle( wxBRUSHSTYLE_SOLID );
backColour = aWindow->GetParent()->GetBackgroundColour();
// Each level inside staticBoxes is darkened by 215
for( int i = 1; i < aDepth; ++i )
backColour = backColour.MakeDisabled( 215 );
brush.SetColour( backColour );
badgeDC.SetBackground( brush );
badgeDC.Clear();
if( aCount < 0 )
{
return bitmap;
}
else if( aCount == 0 )
{
if( aStyle == RPT_SEVERITY_ERROR || aStyle == RPT_SEVERITY_WARNING )
{
badgeColour = KIGFX::COLOR4D( GREEN ).ToColour();
textColour = *wxWHITE;
}
else
{
return bitmap;
}
}
else
{
switch( aStyle )
{
case RPT_SEVERITY_ERROR:
badgeColour = *wxRED;
textColour = *wxWHITE;
break;
case RPT_SEVERITY_WARNING:
badgeColour = *wxYELLOW;
textColour = *wxBLACK;
break;
case RPT_SEVERITY_ACTION:
badgeColour = KIGFX::COLOR4D( GREEN ).ToColour();
textColour = *wxWHITE;
break;
case RPT_SEVERITY_EXCLUSION:
case RPT_SEVERITY_INFO:
default:
badgeColour = *wxLIGHT_GREY;
textColour = *wxBLACK;
break;
}
}
brush.SetStyle( wxBRUSHSTYLE_SOLID );
brush.SetColour( badgeColour );
badgeDC.SetBrush( brush );
badgeDC.SetPen( wxPen( badgeColour, 0 ) );
badgeDC.DrawCircle( size.x / 2 - 1, size.y / 2, ( std::max( size.x, size.y ) / 2 ) - 1 );
wxFont font( fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD );
badgeDC.SetFont( font );
wxString text = wxString::Format( wxT( "%d" ), aCount );
wxSize textExtent = badgeDC.GetTextExtent( text );
badgeDC.SetTextForeground( textColour );
badgeDC.DrawText( text, size.x / 2 - textExtent.x / 2 - 1, size.y / 2 - textExtent.y / 2 );
return bitmap;
}
SEVERITY SeverityFromString( const wxString& aSeverity )
{
if( aSeverity == wxT( "warning" ) )

View File

@ -81,6 +81,10 @@ DIALOG_ERC::DIALOG_ERC( SCH_EDIT_FRAME* parent ) :
m_sdbSizer1OK->SetDefault();
m_errorsBadge->SetMaximumNumber( 999 );
m_warningsBadge->SetMaximumNumber( 999 );
m_exclusionsBadge->SetMaximumNumber( 999 );
if( m_parent->CheckAnnotate( NULL_REPORTER::GetInstance(), false ) )
{
wxHyperlinkCtrl* button = new wxHyperlinkCtrl( m_infoBar, wxID_ANY,
@ -167,9 +171,9 @@ void DIALOG_ERC::updateDisplayedCounts()
numWarnings = -1;
}
m_errorsBadge->SetBitmap( MakeBadge( RPT_SEVERITY_ERROR, numErrors, m_errorsBadge ) );
m_warningsBadge->SetBitmap( MakeBadge( RPT_SEVERITY_WARNING, numWarnings, m_warningsBadge ) );
m_exclusionsBadge->SetBitmap( MakeBadge( RPT_SEVERITY_EXCLUSION, numExcluded, m_exclusionsBadge ) );
m_errorsBadge->UpdateNumber( numErrors, RPT_SEVERITY_ERROR );
m_warningsBadge->UpdateNumber( numWarnings, RPT_SEVERITY_WARNING );
m_exclusionsBadge->UpdateNumber( numExcluded, RPT_SEVERITY_EXCLUSION );
}

View File

@ -74,24 +74,20 @@ DIALOG_ERC_BASE::DIALOG_ERC_BASE( wxWindow* parent, wxWindowID id, const wxStrin
m_showErrors = new wxCheckBox( this, wxID_ANY, _("Errors"), wxDefaultPosition, wxDefaultSize, 0 );
bSeveritySizer->Add( m_showErrors, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
m_errorsBadge = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
m_errorsBadge->SetMinSize( wxSize( 20,20 ) );
bSeveritySizer->Add( m_errorsBadge, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 25 );
m_errorsBadge = new NUMBER_BADGE( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
bSeveritySizer->Add( m_errorsBadge, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 25 );
m_showWarnings = new wxCheckBox( this, wxID_ANY, _("Warnings"), wxDefaultPosition, wxDefaultSize, 0 );
bSeveritySizer->Add( m_showWarnings, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
m_warningsBadge = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
m_warningsBadge->SetMinSize( wxSize( 20,20 ) );
bSeveritySizer->Add( m_warningsBadge, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 25 );
m_warningsBadge = new NUMBER_BADGE( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
bSeveritySizer->Add( m_warningsBadge, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 25 );
m_showExclusions = new wxCheckBox( this, wxID_ANY, _("Exclusions"), wxDefaultPosition, wxDefaultSize, 0 );
bSeveritySizer->Add( m_showExclusions, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
m_exclusionsBadge = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
bSeveritySizer->Add( m_exclusionsBadge, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 25 );
m_exclusionsBadge = new NUMBER_BADGE( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
bSeveritySizer->Add( m_exclusionsBadge, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 25 );
bSeveritySizer->Add( 0, 0, 1, wxEXPAND, 5 );

View File

@ -406,7 +406,7 @@
<property name="border">5</property>
<property name="flag">wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxBoxSizer" expanded="0">
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSeveritySizer</property>
<property name="orient">wxHORIZONTAL</property>
@ -612,11 +612,11 @@
<event name="OnCheckBox">OnSeverity</event>
</object>
</object>
<object class="sizeritem" expanded="0">
<object class="sizeritem" expanded="1">
<property name="border">25</property>
<property name="flag">wxRIGHT|wxALIGN_CENTER_VERTICAL</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxStaticBitmap" expanded="0">
<object class="CustomControl" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -627,13 +627,15 @@
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="class">NUMBER_BADGE</property>
<property name="close_button">1</property>
<property name="construction"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="declaration"></property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
@ -645,12 +647,13 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="include">#include &lt;widgets/number_badge.h&gt;</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">20,20</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_errorsBadge</property>
<property name="pane_border">1</property>
@ -660,6 +663,7 @@
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="settings"></property>
<property name="show">1</property>
<property name="size"></property>
<property name="subclass">; ; forward_declare</property>
@ -735,11 +739,11 @@
<event name="OnCheckBox">OnSeverity</event>
</object>
</object>
<object class="sizeritem" expanded="0">
<object class="sizeritem" expanded="1">
<property name="border">25</property>
<property name="flag">wxRIGHT|wxALIGN_CENTER_VERTICAL</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxStaticBitmap" expanded="0">
<object class="CustomControl" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -750,13 +754,15 @@
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="class">NUMBER_BADGE</property>
<property name="close_button">1</property>
<property name="construction"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="declaration"></property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
@ -768,12 +774,13 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="include">#include &lt;widgets/number_badge.h&gt;</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">20,20</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_warningsBadge</property>
<property name="pane_border">1</property>
@ -783,6 +790,7 @@
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="settings"></property>
<property name="show">1</property>
<property name="size"></property>
<property name="subclass">; ; forward_declare</property>
@ -858,11 +866,11 @@
<event name="OnCheckBox">OnSeverity</event>
</object>
</object>
<object class="sizeritem" expanded="0">
<object class="sizeritem" expanded="1">
<property name="border">25</property>
<property name="flag">wxRIGHT|wxALIGN_CENTER_VERTICAL</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxStaticBitmap" expanded="0">
<object class="CustomControl" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -873,13 +881,15 @@
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="class">NUMBER_BADGE</property>
<property name="close_button">1</property>
<property name="construction"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="declaration"></property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
@ -891,6 +901,7 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="include">#include &lt;widgets/number_badge.h&gt;</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
@ -906,6 +917,7 @@
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="settings"></property>
<property name="show">1</property>
<property name="size"></property>
<property name="subclass">; ; forward_declare</property>

View File

@ -30,7 +30,7 @@ class WX_INFOBAR;
#include <wx/notebook.h>
#include <wx/stattext.h>
#include <wx/checkbox.h>
#include <wx/statbmp.h>
#include <widgets/number_badge.h>
#include <wx/button.h>
#include <wx/statline.h>
#include <wx/dialog.h>
@ -56,11 +56,11 @@ class DIALOG_ERC_BASE : public DIALOG_SHIM
wxStaticText* m_showLabel;
wxCheckBox* m_showAll;
wxCheckBox* m_showErrors;
wxStaticBitmap* m_errorsBadge;
NUMBER_BADGE* m_errorsBadge;
wxCheckBox* m_showWarnings;
wxStaticBitmap* m_warningsBadge;
NUMBER_BADGE* m_warningsBadge;
wxCheckBox* m_showExclusions;
wxStaticBitmap* m_exclusionsBadge;
NUMBER_BADGE* m_exclusionsBadge;
wxButton* m_saveReport;
wxStaticLine* m_staticline1;
wxBoxSizer* m_buttonsSizer;

View File

@ -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

View File

@ -28,8 +28,6 @@
#include <wx/string.h>
class wxWindow;
namespace KIUI
{
@ -53,13 +51,8 @@ enum SEVERITY {
RPT_SEVERITY_IGNORE = 0x20
};
wxBitmap MakeBadge( SEVERITY aStyle, int aCount, wxWindow* aWindow, int aDepth = 1 );
SEVERITY SeverityFromString( const wxString& aSeverity );
wxString SeverityToString( const SEVERITY& aSeverity );
#endif // UI_COMMON_H

View File

@ -36,6 +36,7 @@
#include <class_marker_pcb.h>
#include <wx/wupdlock.h>
#include <widgets/appearance_controls.h>
#include <widgets/number_badge.h>
#include <widgets/ui_common.h>
#include <widgets/progress_reporter.h>
#include <dialogs/wx_html_report_box.h>
@ -84,6 +85,10 @@ 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();
@ -859,7 +864,7 @@ void DIALOG_DRC::updateDisplayedCounts()
numWarnings = -1;
}
m_errorsBadge->SetBitmap( MakeBadge( RPT_SEVERITY_ERROR, numErrors, m_errorsBadge ) );
m_warningsBadge->SetBitmap( MakeBadge( RPT_SEVERITY_WARNING, numWarnings, m_warningsBadge ) );
m_exclusionsBadge->SetBitmap( MakeBadge( RPT_SEVERITY_EXCLUSION, numExcluded, m_exclusionsBadge ) );
m_errorsBadge->UpdateNumber( numErrors, RPT_SEVERITY_ERROR );
m_warningsBadge->UpdateNumber( numWarnings, RPT_SEVERITY_WARNING );
m_exclusionsBadge->UpdateNumber( numExcluded, RPT_SEVERITY_EXCLUSION );
}

View File

@ -63,7 +63,7 @@ DIALOG_DRC_BASE::DIALOG_DRC_BASE( wxWindow* parent, wxWindowID id, const wxStrin
bSizer10 = new wxBoxSizer( wxVERTICAL );
m_messages = new WX_HTML_REPORT_BOX( m_panelMessages, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO );
bSizer10->Add( m_messages, 1, wxEXPAND | wxTOP | wxRIGHT | wxLEFT, 5 );
bSizer10->Add( m_messages, 1, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 );
wxBoxSizer* bGaugeMargins;
bGaugeMargins = new wxBoxSizer( wxVERTICAL );
@ -162,24 +162,20 @@ DIALOG_DRC_BASE::DIALOG_DRC_BASE( wxWindow* parent, wxWindowID id, const wxStrin
m_showErrors = new wxCheckBox( this, wxID_ANY, _("Errors"), wxDefaultPosition, wxDefaultSize, 0 );
bSeveritySizer->Add( m_showErrors, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
m_errorsBadge = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
m_errorsBadge->SetMinSize( wxSize( 20,20 ) );
bSeveritySizer->Add( m_errorsBadge, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 25 );
m_errorsBadge = new NUMBER_BADGE( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
bSeveritySizer->Add( m_errorsBadge, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 25 );
m_showWarnings = new wxCheckBox( this, wxID_ANY, _("Warnings"), wxDefaultPosition, wxDefaultSize, 0 );
bSeveritySizer->Add( m_showWarnings, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
m_warningsBadge = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
m_warningsBadge->SetMinSize( wxSize( 20,20 ) );
bSeveritySizer->Add( m_warningsBadge, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 25 );
m_warningsBadge = new NUMBER_BADGE( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
bSeveritySizer->Add( m_warningsBadge, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 25 );
m_showExclusions = new wxCheckBox( this, wxID_ANY, _("Exclusions"), wxDefaultPosition, wxDefaultSize, 0 );
bSeveritySizer->Add( m_showExclusions, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
m_exclusionsBadge = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
bSeveritySizer->Add( m_exclusionsBadge, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 25 );
m_exclusionsBadge = new NUMBER_BADGE( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
bSeveritySizer->Add( m_exclusionsBadge, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 25 );
bSeveritySizer->Add( 5, 0, 1, wxEXPAND, 5 );

View File

@ -1344,9 +1344,9 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">25</property>
<property name="flag">wxRIGHT|wxALIGN_CENTER_VERTICAL</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxStaticBitmap" expanded="1">
<object class="CustomControl" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -1357,13 +1357,15 @@
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="class">NUMBER_BADGE</property>
<property name="close_button">1</property>
<property name="construction"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="declaration"></property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
@ -1375,12 +1377,13 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="include">#include &lt;widgets/number_badge.h&gt;</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">20,20</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_errorsBadge</property>
<property name="pane_border">1</property>
@ -1390,6 +1393,7 @@
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="settings"></property>
<property name="show">1</property>
<property name="size"></property>
<property name="subclass">; ; forward_declare</property>
@ -1467,9 +1471,9 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">25</property>
<property name="flag">wxRIGHT|wxALIGN_CENTER_VERTICAL</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxStaticBitmap" expanded="1">
<object class="CustomControl" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -1480,13 +1484,15 @@
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="class">NUMBER_BADGE</property>
<property name="close_button">1</property>
<property name="construction"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="declaration"></property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
@ -1498,12 +1504,13 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="include">#include &lt;widgets/number_badge.h&gt;</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">20,20</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_warningsBadge</property>
<property name="pane_border">1</property>
@ -1513,6 +1520,7 @@
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="settings"></property>
<property name="show">1</property>
<property name="size"></property>
<property name="subclass">; ; forward_declare</property>
@ -1590,9 +1598,9 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">25</property>
<property name="flag">wxRIGHT|wxALIGN_CENTER_VERTICAL</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxStaticBitmap" expanded="1">
<object class="CustomControl" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -1603,13 +1611,15 @@
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="class">NUMBER_BADGE</property>
<property name="close_button">1</property>
<property name="construction"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="declaration"></property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
@ -1621,6 +1631,7 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="include">#include &lt;widgets/number_badge.h&gt;</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
@ -1636,6 +1647,7 @@
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="settings"></property>
<property name="show">1</property>
<property name="size"></property>
<property name="subclass">; ; forward_declare</property>

View File

@ -30,7 +30,7 @@ class WX_HTML_REPORT_BOX;
#include <wx/dataview.h>
#include <wx/simplebook.h>
#include <wx/stattext.h>
#include <wx/statbmp.h>
#include <widgets/number_badge.h>
#include <wx/button.h>
#include <wx/statline.h>
#include <wx/dialog.h>
@ -68,11 +68,11 @@ class DIALOG_DRC_BASE : public DIALOG_SHIM
wxStaticText* m_showLabel;
wxCheckBox* m_showAll;
wxCheckBox* m_showErrors;
wxStaticBitmap* m_errorsBadge;
NUMBER_BADGE* m_errorsBadge;
wxCheckBox* m_showWarnings;
wxStaticBitmap* m_warningsBadge;
NUMBER_BADGE* m_warningsBadge;
wxCheckBox* m_showExclusions;
wxStaticBitmap* m_exclusionsBadge;
NUMBER_BADGE* m_exclusionsBadge;
wxButton* m_saveReport;
wxStaticLine* m_staticline1;
wxBoxSizer* m_sizerButtons;