diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp index c6d72181dd..f9676d3e67 100644 --- a/common/eda_draw_frame.cpp +++ b/common/eda_draw_frame.cpp @@ -118,7 +118,6 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame m_drawBgColor = COLOR4D( BLACK ); // the background color of the draw canvas: // BLACK for Pcbnew, BLACK or WHITE for Eeschema m_colorSettings = nullptr; - m_msgFrameHeight = EDA_MSG_PANEL::GetRequiredHeight( this ); m_polarCoords = false; m_findReplaceData = std::make_unique(); m_hotkeyPopup = nullptr; @@ -175,15 +174,16 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame stsbar->SetFont( KIUI::GetStatusFont( this ) ); } + m_messagePanel = new EDA_MSG_PANEL( this, -1, wxPoint( 0, m_frameSize.y ), wxDefaultSize ); + m_messagePanel->SetBackgroundColour( COLOR4D( LIGHTGRAY ).ToColour() ); + m_msgFrameHeight = m_messagePanel->GetBestSize().y; + // Create child subwindows. GetClientSize( &m_frameSize.x, &m_frameSize.y ); m_framePos.x = m_framePos.y = 0; m_frameSize.y -= m_msgFrameHeight; - m_messagePanel = new EDA_MSG_PANEL( this, -1, wxPoint( 0, m_frameSize.y ), - wxSize( m_frameSize.x, m_msgFrameHeight ) ); - - m_messagePanel->SetBackgroundColour( COLOR4D( LIGHTGRAY ).ToColour() ); + m_messagePanel->SetSize( m_frameSize.x, m_msgFrameHeight ); Bind( wxEVT_DPI_CHANGED, [&]( wxDPIChangedEvent& ) @@ -195,11 +195,13 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame // especially important even for first launches as the constructor of the window // here usually doesn't have the correct dpi awareness yet m_frameSize.y += m_msgFrameHeight; - m_msgFrameHeight = EDA_MSG_PANEL::GetRequiredHeight( this ); + m_msgFrameHeight = m_messagePanel->GetBestSize().y; m_frameSize.y -= m_msgFrameHeight; m_messagePanel->SetPosition( wxPoint( 0, m_frameSize.y ) ); m_messagePanel->SetSize( m_frameSize.x, m_msgFrameHeight ); + + // Don't skip, otherwise the frame gets too big } ); } diff --git a/common/widgets/msgpanel.cpp b/common/widgets/msgpanel.cpp index ccfc078cf2..683cd65912 100644 --- a/common/widgets/msgpanel.cpp +++ b/common/widgets/msgpanel.cpp @@ -34,6 +34,7 @@ BEGIN_EVENT_TABLE( EDA_MSG_PANEL, wxPanel ) + EVT_DPI_CHANGED( EDA_MSG_PANEL::OnDPIChanged ) EVT_PAINT( EDA_MSG_PANEL::OnPaint ) END_EVENT_TABLE() @@ -50,7 +51,9 @@ EDA_MSG_PANEL::EDA_MSG_PANEL( wxWindow* aParent, int aId, const wxPoint& aPositi m_last_x = 0; - m_fontSize = GetTextExtent( wxT( "W" ) ); + updateFontSize(); + + InvalidateBestSize(); } @@ -59,16 +62,31 @@ EDA_MSG_PANEL::~EDA_MSG_PANEL() } -int EDA_MSG_PANEL::GetRequiredHeight( wxWindow* aWindow ) +void EDA_MSG_PANEL::updateFontSize() { - wxSize fontSizeInPixels; - wxWindowDC dc( aWindow ); + wxFont font = KIUI::GetControlFont( this ); + GetTextExtent( wxT( "W" ), &m_fontSize.x, &m_fontSize.y, 0, 0, &font ); +} - dc.SetFont( KIUI::GetControlFont( aWindow ) ); - dc.GetTextExtent( wxT( "W" ), &fontSizeInPixels.x, &fontSizeInPixels.y ); - // make space for two rows of text plus a number of pixels between them. - return 2 * fontSizeInPixels.y + 0; +wxSize EDA_MSG_PANEL::DoGetBestSize() const +{ + return wxSize( wxDefaultCoord, 2 * m_fontSize.y + 0 ); +} + + +wxSize EDA_MSG_PANEL::DoGetBestClientSize() const +{ + return wxPanel::DoGetBestClientSize(); +} + + +void EDA_MSG_PANEL::OnDPIChanged( wxDPIChangedEvent& aEvent ) +{ + updateFontSize(); + InvalidateBestSize(); + + aEvent.Skip(); } diff --git a/include/widgets/msgpanel.h b/include/widgets/msgpanel.h index 961db5002b..9a1e4f10ca 100644 --- a/include/widgets/msgpanel.h +++ b/include/widgets/msgpanel.h @@ -3,7 +3,7 @@ * * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com * Copyright (C) 2011-2012 Wayne Stambaugh - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2024 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 @@ -105,16 +105,13 @@ public: long style=wxTAB_TRAVERSAL, const wxString& name=wxPanelNameStr); ~EDA_MSG_PANEL(); - /** - * Return the required height (in pixels) of a EDA_MSG_PANEL. - * - * This takes into consideration the system gui font, wxSYS_DEFAULT_GUI_FONT. - */ - static int GetRequiredHeight( wxWindow* aWindow ); - void OnPaint( wxPaintEvent& aEvent ); + void OnDPIChanged( wxDPIChangedEvent& aEvent ); void EraseMsgBox(); + wxSize DoGetBestSize() const override; + wxSize DoGetBestClientSize() const override; + /** * Set a message at \a aXPosition to \a aUpperText and \a aLowerText in the message panel. * @@ -154,15 +151,12 @@ public: DECLARE_EVENT_TABLE() protected: + void updateFontSize(); + void showItem( wxDC& dc, const MSG_PANEL_ITEM& aItem ); void erase( wxDC* DC ); - /** - * Calculate the width and height of a text string using the system UI font. - */ - wxSize computeTextSize( const wxString& text ) const; - protected: std::vector m_Items; int m_last_x; ///< the last used x coordinate