← Back to team overview

kicad-developers team mailing list archive

[PATCH] Restore settings dialog icon scale stepped slider increments

 

Hi everyone,

While looking at the new common settings dialog, I noticed that the Icon
Scale STEPPED_SLIDER does not step in the increments that it used to.

Here is a small patch which restores the 25% stepping behavior. The
rounding logic has also been modified so that we round the the nearest
multiple instead of just down. The rounding modification allows the slider
to be single clicked up and down (only down worked before for single
clicks).

BTW, the new common settings dialog looks awesome!

-John
diff --git a/common/dialogs/panel_common_settings.cpp b/common/dialogs/panel_common_settings.cpp
--- a/common/dialogs/panel_common_settings.cpp
+++ b/common/dialogs/panel_common_settings.cpp
@@ -117,6 +117,10 @@
 void PANEL_COMMON_SETTINGS::OnScaleSlider( wxScrollEvent& aEvent )
 {
     m_scaleAuto->SetValue( false );
+
+    // Without this aEvent.Skip() call, the STEPPED_SLIDER OnScroll()
+    // event is not called and m_scaleAuto does not step.
+    aEvent.Skip( true );
 }
 
 
diff --git a/common/widgets/stepped_slider.cpp b/common/widgets/stepped_slider.cpp
--- a/common/widgets/stepped_slider.cpp
+++ b/common/widgets/stepped_slider.cpp
@@ -70,8 +70,16 @@
 void STEPPED_SLIDER::OnScroll( wxScrollEvent& aEvent )
 {
     const int value = GetValue();
-    const int rounded = value - value % m_step;
 
-    SetValue( rounded );
+    // Round up or down to nearest m_step multiple
+    if ( value % m_step > m_step / 2 )
+    {
+        SetValue( value + m_step - ( value % m_step ) );
+    }
+    else
+    {
+        SetValue( value - ( value % m_step ) );
+    }
+
     aEvent.Skip();
 }

Follow ups