From c12d4e1dace7d7c01692a0ffa93c8660cb04f8de Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 9 Jul 2011 23:36:26 +0000 Subject: [PATCH] Fix wxMSW wxSlider best size calculation and label layout. 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 | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/msw/slider.cpp b/src/msw/slider.cpp index 47035cff96..ae7b2b38a9 100644 --- a/src/msw/slider.cpp +++ b/src/msw/slider.cpp @@ -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(labelSize*2.75); + size.y += labelSize; } } -- 2.49.0