Fix bad positioning for padded bitmap badges.

Also fixes an off-by-one error (because generally speaking it's
better to avoid writing off the end of an array).

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15784
This commit is contained in:
Jeff Young 2023-11-20 18:13:07 +00:00
parent 196e05bc51
commit 6732f35a52
2 changed files with 14 additions and 13 deletions

View File

@ -338,21 +338,23 @@ void BITMAP_BUTTON::OnPaint( wxPaintEvent& aEvent )
{
dc.SetFont( m_badgeFont );
wxSize box_size = dc.GetTextExtent( m_badgeText );
wxSize text_padding( 3, 1 );
if( m_padding )
text_padding *= 2;
wxSize box_size = dc.GetTextExtent( m_badgeText ) + text_padding;
wxSize box_offset = box_size;
wxSize text_offset = box_offset;
if( m_padding != 0 )
{
box_offset += wxSize( m_padding - 2, m_padding );
text_offset -= wxSize( 3, 1 );
}
box_offset += wxSize( m_padding / 3, m_padding / 3 );
dc.SetPen( wxPen( m_badgeColor ) );
dc.SetBrush( wxBrush( m_badgeColor ) );
dc.DrawRoundedRectangle( rect.GetRightBottom() - box_offset, box_size, -0.25 );
dc.SetTextForeground( m_badgeTextColor );
dc.DrawText( m_badgeText, rect.GetRightBottom() - text_offset );
dc.DrawText( m_badgeText, rect.GetRightBottom() - box_offset + ( text_padding / 2 ) );
}
}

View File

@ -56,6 +56,7 @@ KISTATUSBAR::KISTATUSBAR( int aNumberFields, wxWindow* parent, wxWindowID id ) :
SetFieldsCount( aNumberFields + ExtraFields );
int* widths = new int[aNumberFields + ExtraFields];
for( int i = 0; i < aNumberFields; i++ )
widths[i] = -1;
@ -65,7 +66,7 @@ KISTATUSBAR::KISTATUSBAR( int aNumberFields, wxWindow* parent, wxWindowID id ) :
widths[aNumberFields + FIELD_OFFSET_NOTIFICATION_BUTTON] = 20; // notifications button
#ifdef __WXOSX__
// offset from the right edge
widths[aNumberFields + ExtraFields] = 15;
widths[aNumberFields + ExtraFields - 1] = 10;
#endif
SetStatusWidths( aNumberFields + ExtraFields, widths );
@ -79,15 +80,13 @@ KISTATUSBAR::KISTATUSBAR( int aNumberFields, wxWindow* parent, wxWindowID id ) :
SetStatusStyles( aNumberFields + ExtraFields, styles );
delete[] styles;
m_backgroundTxt =
new wxStaticText( this, wxID_ANY, wxT( "" ), wxDefaultPosition, wxDefaultSize );
m_backgroundTxt = new wxStaticText( this, wxID_ANY, wxT( "" ) );
m_backgroundProgressBar = new wxGauge( this, wxID_ANY, 100, wxDefaultPosition, wxDefaultSize,
wxGA_HORIZONTAL | wxGA_SMOOTH );
m_backgroundStopButton =
new wxButton( this, wxID_ANY, "X", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
m_backgroundStopButton = new wxButton( this, wxID_ANY, "X", wxDefaultPosition, wxDefaultSize,
wxBU_EXACTFIT );
m_notificationsButton = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition,
wxDefaultSize, wxBU_EXACTFIT );