]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix wxMSW wxSlider best size calculation and label layout.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 9 Jul 2011 23:36:26 +0000 (23:36 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 9 Jul 2011 23:36:26 +0000 (23:36 +0000)
The best size calculation was wrong as the min/max labels height was
unnecessarily added to the slier total height even if though these labels are
positioned alongside the slider itself in horizontal layout case.

The slider also managed to position its value label completely outside the
space allocated to it (and the bug in DoGetBestSize() might have been an
attempt to work around this), don't do this any more. This also fixes the
wrongly centered vertical position of the min/max labels.

Closes #13291.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68207 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/slider.cpp

index 47035cff96b9f7aac68c5f00469b9ece21c02b3f..ae7b2b38a90fd7dfb33930e27ee9d36565cab950 100644 (file)
@@ -493,8 +493,21 @@ void wxSlider::DoMoveWindow(int x, int y, int width, int height)
             ((width  - (m_minLabelWidth + m_maxLabelWidth)) / 2) -
             (m_maxLabelWidth / 2);
 
+        int ySlider = y;
+
         if ( HasFlag(wxSL_BOTTOM) )
         {
+            if ( HasFlag(wxSL_VALUE_LABEL) )
+            {
+                DoMoveSibling((HWND)(*m_labels)[SliderLabel_Value],
+                    xLabelValue,
+                    y,
+                    maxLabelWidth, labelHeight);
+
+                ySlider += labelHeight;
+                yLabelMinMax += labelHeight;
+            }
+
             if ( HasFlag(wxSL_MIN_MAX_LABELS) )
             {
                 holdLeftX = x;
@@ -515,16 +528,17 @@ void wxSlider::DoMoveWindow(int x, int y, int width, int height)
                     yLabelMinMax,
                     holdRightWidth, labelHeight);
             }
+        }
+        else // wxSL_TOP
+        {
             if ( HasFlag(wxSL_VALUE_LABEL) )
             {
                 DoMoveSibling((HWND)(*m_labels)[SliderLabel_Value],
                     xLabelValue,
-                    y - labelHeight,
+                    y + THUMB + tickOffset,
                     maxLabelWidth, labelHeight);
             }
-        }
-        else // wxSL_TOP
-        {
+
             if ( HasFlag(wxSL_MIN_MAX_LABELS) )
             {
                 holdLeftX = x;
@@ -545,11 +559,6 @@ void wxSlider::DoMoveWindow(int x, int y, int width, int height)
                     yLabelMinMax,
                     holdRightWidth, labelHeight);
             }
-            if ( HasFlag(wxSL_VALUE_LABEL) )
-                DoMoveSibling((HWND)(*m_labels)[SliderLabel_Value],
-                    xLabelValue,
-                    y + THUMB + tickOffset,
-                    maxLabelWidth, labelHeight);
         }
 
         // position the slider itself along the top/bottom edge
@@ -557,7 +566,7 @@ void wxSlider::DoMoveWindow(int x, int y, int width, int height)
             labelOffset = labelHeight;
         wxSliderBase::DoMoveWindow(
             x + m_minLabelWidth + VGAP,
-            y,
+            ySlider,
             width  - (m_minLabelWidth + m_maxLabelWidth  + (VGAP*2)),
             THUMB + tickOffset);
     }
@@ -597,12 +606,17 @@ wxSize wxSlider::DoGetBestSize() const
 
         if ( m_labels )
         {
-            // labels add extra height
             int labelSize = GetLabelsSize();
-            if ( HasFlag(wxSL_MIN_MAX_LABELS) )
+
+            // Min/max labels are compensated by the ticks so we don't need
+            // extra space for them if we're also showing ticks.
+            if ( HasFlag(wxSL_MIN_MAX_LABELS) && !HasFlag(wxSL_TICKS) )
                 size.y += labelSize;
+
+            // The value label is always on top of the control and so does need
+            // extra space in any case.
             if ( HasFlag(wxSL_VALUE_LABEL) )
-                size.y += static_cast<int>(labelSize*2.75);
+                size.y += labelSize;
         }
     }