You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.3 KiB

  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2020 Kicad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #ifndef NUMBER_BADGE_H_
  24. #define NUMBER_BADGE_H_
  25. #include <widgets/ui_common.h>
  26. #include <wx/dcclient.h>
  27. #include <wx/panel.h>
  28. /**
  29. * A simple UI element that puts a number on top of a colored rounded rectangle with a fill
  30. * color that shows the severity of the reports the number is counting (e.g. green, yellow, red).
  31. * This badge will also automatically truncate the displayed number to the set maximum and display
  32. * "+" at the end to represent it is truncated.
  33. */
  34. class NUMBER_BADGE : public wxPanel
  35. {
  36. public:
  37. /**
  38. * Create a number badge with 10pt font and a maximum number of 1000.
  39. */
  40. NUMBER_BADGE( wxWindow* aParent, wxWindowID aId, const wxPoint& aPos,
  41. const wxSize& aSize, int aStyles );
  42. /**
  43. * Update the number displayed on the badge.
  44. *
  45. * Severity to badge color mapping:
  46. * - RPT_SEVERITY_ERROR = red badge
  47. * - RPT_SEVERITY_WARNING = yellow badge
  48. * - RPT_SEVERITY_ACTION = green badge
  49. * - RPT_SEVERITY_EXCLUSION = light grey badge
  50. * - RPT_SEVERITY_INFO = light grey badge
  51. *
  52. * @param aNumber is the new number to display.
  53. * @param aSeverity is the new severity of the badge.
  54. */
  55. void UpdateNumber( int aNumber, SEVERITY aSeverity );
  56. /**
  57. * Set the maximum number to be shown on the badge. Any numbers greater than this
  58. * will be displayed as the maximum number followed by "+".
  59. *
  60. * @param aMax is the maximum number
  61. */
  62. void SetMaximumNumber( int aMax );
  63. /**
  64. * Set the text size to use on the badge.
  65. *
  66. * @param aSize is the text size (in pt) to use on the badge
  67. */
  68. void SetTextSize( int aSize );
  69. protected:
  70. /**
  71. * Helper function to compute the size of the badge
  72. */
  73. void computeSize();
  74. /**
  75. * Handler that actually paints the badge and the text.
  76. */
  77. void onPaint( wxPaintEvent& aEvt );
  78. int m_textSize; // The text size to use
  79. int m_maxNumber; // The maximum number allowed to be shown on the badge
  80. int m_currentNumber; // The current number to display
  81. bool m_showBadge; // If true, displays the actual badge otherwise it is invisible
  82. wxColour m_badgeColour; // The color of the badge
  83. wxColour m_textColour; // The color of the text on the badge
  84. };
  85. #endif