From 884051fae13c7c1f721a87abced9d7325a1c3c28 Mon Sep 17 00:00:00 2001
From: Alex Shvartzkop <dudesuchamazing@gmail.com>
Date: Thu, 23 May 2024 20:22:09 +0300
Subject: [PATCH] Update status bar widths on DPI change.

---
 common/eda_draw_frame.cpp | 86 +++++++++++++++++++++------------------
 include/eda_draw_frame.h  |  4 +-
 2 files changed, 50 insertions(+), 40 deletions(-)

diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp
index f9676d3e67..3032a05bbb 100644
--- a/common/eda_draw_frame.cpp
+++ b/common/eda_draw_frame.cpp
@@ -132,46 +132,10 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame
     {
         CreateStatusBar( 8 )->SetDoubleBuffered( true );
 
-    // set the size of the status bar subwindows:
+        GetStatusBar()->SetFont( KIUI::GetStatusFont( this ) );
 
-        wxWindow* stsbar = GetStatusBar();
-        int       spacer = KIUI::GetTextSize( wxT( "M" ), stsbar ).x * 2;
-
-        int dims[] =
-        {
-            // remainder of status bar on far left is set to a default or whatever is left over.
-            -1,
-
-            // When using GetTextSize() remember the width of character '1' is not the same
-            // as the width of '0' unless the font is fixed width, and it usually won't be.
-
-            // zoom:
-            KIUI::GetTextSize( wxT( "Z 762000" ), stsbar ).x,
-
-            // cursor coords
-            KIUI::GetTextSize( wxT( "X 1234.1234  Y 1234.1234" ), stsbar ).x,
-
-            // delta distances
-            KIUI::GetTextSize( wxT( "dx 1234.1234  dy 1234.1234  dist 1234.1234" ), stsbar ).x,
-
-            // grid size
-            KIUI::GetTextSize( wxT( "grid X 1234.1234  Y 1234.1234" ), stsbar ).x,
-
-            // units display, Inches is bigger than mm
-            KIUI::GetTextSize( _( "Inches" ), stsbar ).x,
-
-            // Size for the "Current Tool" panel; longest string from SetTool()
-            KIUI::GetTextSize( wxT( "Add layer alignment target" ), stsbar ).x,
-
-            // constraint mode
-            KIUI::GetTextSize( _( "Constrain to H, V, 45" ), stsbar ).x
-        };
-
-        for( size_t ii = 1; ii < arrayDim( dims ); ii++ )
-            dims[ii] += spacer;
-
-        SetStatusWidths( arrayDim( dims ), dims );
-        stsbar->SetFont( KIUI::GetStatusFont( this ) );
+        // set the size of the status bar subwindows:
+        updateStatusBarWidths();
     }
 
     m_messagePanel = new EDA_MSG_PANEL( this, -1, wxPoint( 0, m_frameSize.y ), wxDefaultSize );
@@ -188,6 +152,9 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame
     Bind( wxEVT_DPI_CHANGED,
           [&]( wxDPIChangedEvent& )
           {
+              if( ( GetWindowStyle() & wxFRAME_NO_TASKBAR ) == 0 )
+                  updateStatusBarWidths();
+
               wxMoveEvent dummy;
               OnMove( dummy );
 
@@ -690,6 +657,47 @@ void EDA_DRAW_FRAME::OnSize( wxSizeEvent& SizeEv )
 }
 
 
+void EDA_DRAW_FRAME::updateStatusBarWidths()
+{
+    wxWindow* stsbar = GetStatusBar();
+    int       spacer = KIUI::GetTextSize( wxT( "M" ), stsbar ).x * 2;
+
+    int dims[] = {
+        // remainder of status bar on far left is set to a default or whatever is left over.
+        -1,
+
+        // When using GetTextSize() remember the width of character '1' is not the same
+        // as the width of '0' unless the font is fixed width, and it usually won't be.
+
+        // zoom:
+        KIUI::GetTextSize( wxT( "Z 762000" ), stsbar ).x,
+
+        // cursor coords
+        KIUI::GetTextSize( wxT( "X 1234.1234  Y 1234.1234" ), stsbar ).x,
+
+        // delta distances
+        KIUI::GetTextSize( wxT( "dx 1234.1234  dy 1234.1234  dist 1234.1234" ), stsbar ).x,
+
+        // grid size
+        KIUI::GetTextSize( wxT( "grid X 1234.1234  Y 1234.1234" ), stsbar ).x,
+
+        // units display, Inches is bigger than mm
+        KIUI::GetTextSize( _( "Inches" ), stsbar ).x,
+
+        // Size for the "Current Tool" panel; longest string from SetTool()
+        KIUI::GetTextSize( wxT( "Add layer alignment target" ), stsbar ).x,
+
+        // constraint mode
+        KIUI::GetTextSize( _( "Constrain to H, V, 45" ), stsbar ).x
+    };
+
+    for( size_t ii = 1; ii < arrayDim( dims ); ii++ )
+        dims[ii] += spacer;
+
+    SetStatusWidths( arrayDim( dims ), dims );
+}
+
+
 void EDA_DRAW_FRAME::UpdateStatusBar()
 {
     SetStatusText( GetZoomLevelIndicator(), 1 );
diff --git a/include/eda_draw_frame.h b/include/eda_draw_frame.h
index e471bc5137..bf5ea73979 100644
--- a/include/eda_draw_frame.h
+++ b/include/eda_draw_frame.h
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
- * Copyright (C) 1992-2023 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
@@ -509,6 +509,8 @@ protected:
 
     void setupUnits( APP_SETTINGS_BASE* aCfg );
 
+    void updateStatusBarWidths();
+
     std::vector<wxWindow*> findDialogs();
 
     /**