From 6732f35a52b0e36b31a11fe61cded44813ea0577 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 20 Nov 2023 18:13:07 +0000 Subject: [PATCH] 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 --- common/widgets/bitmap_button.cpp | 16 +++++++++------- common/widgets/kistatusbar.cpp | 11 +++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/common/widgets/bitmap_button.cpp b/common/widgets/bitmap_button.cpp index dc3168b9c0..65275a4b27 100644 --- a/common/widgets/bitmap_button.cpp +++ b/common/widgets/bitmap_button.cpp @@ -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 ) ); } } diff --git a/common/widgets/kistatusbar.cpp b/common/widgets/kistatusbar.cpp index c1cd05eed1..ad3a63d1a6 100644 --- a/common/widgets/kistatusbar.cpp +++ b/common/widgets/kistatusbar.cpp @@ -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 );