31#include <wx/combobox.h>
32#include <wx/settings.h>
33#include <wx/spinctrl.h>
37 wxGenericStaticBitmap( aField->GetParent(), wxID_ANY,
KiBitmapBundle( aIcon ) ),
44 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
67 std::vector<std::pair<wxString, size_t>> lines;
69 for(
const wxString&
message : aMessages )
71 auto it = std::find_if( lines.begin(), lines.end(),
72 [&](
const std::pair<wxString, size_t>& aLine )
74 return aLine.first == message;
77 if( it != lines.end() )
80 lines.emplace_back(
message, 1 );
85 for(
size_t ii = 0; ii < lines.size() && ii <
MAX_LINES; ++ii )
90 text += lines[ii].first;
92 if( lines[ii].second > 1 )
93 text += wxString::Format(
_(
" (%zu times)" ), lines[ii].second );
97 text += wxString::Format(
_(
"\n... and %zu more" ), lines.size() -
MAX_LINES );
100 Show( !
text.IsEmpty() );
108 wxArrayString messages;
110 if( !aMessage.IsEmpty() )
111 messages.Add( aMessage );
120 SetToolTip( wxS(
" " ) );
131 const wxSize fieldSize =
m_field->GetSize();
136 if(
dynamic_cast<wxComboBox*
>(
m_field ) ||
dynamic_cast<wxChoice*
>(
m_field )
137 ||
dynamic_cast<wxComboCtrl*
>(
m_field ) ||
dynamic_cast<wxSpinCtrl*
>(
m_field ) )
140 buttonWidth = wxSystemSettings::GetMetric( wxSYS_VSCROLL_X,
m_field );
142 buttonWidth = fieldSize.y;
146 const wxSize iconSize = GetSize();
147 const int gap =
m_field->FromDIP( 3 );
149 const int slotOffset =
m_slot * ( iconSize.x + gap );
153 + wxPoint( fieldSize.x - buttonWidth - iconSize.x - gap - slotOffset, ( fieldSize.y - iconSize.y ) / 2 ) );
174 if( aEvent.GetEventObject() ==
m_field )
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
BITMAPS
A list of all bitmap identifiers.
FIELD_WARNING_ICON(wxWindow *aField, BITMAPS aIcon=BITMAPS::small_warning, int aSlot=0)
static constexpr size_t MAX_LINES
The most warnings listed in the tooltip, with a count of the rest.
wxWindow * m_field
Null once the field has been destroyed.
~FIELD_WARNING_ICON() override
void ShowAsBadge()
Shows the icon with no tooltip of its own, for one that opens something on click or hover.
void onFieldChanged(wxEvent &aEvent)
void Reposition()
Moves the icon back over the field after the field has moved or changed size.
void SetWarnings(const wxArrayString &aMessages)
Lists aMessages in the tooltip, once each with a count when repeated, and shows the icon,...
void SetWarning(const wxString &aMessage)
Shows aMessage as the tooltip, or hides the icon when it is empty.
void onFieldDestroyed(wxWindowDestroyEvent &aEvent)
Some functions to handle hotkeys in KiCad.