From 18745cb6203605a6e5673781aec5ee85167dbcb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 2 Jun 2006 18:22:02 +0000 Subject: [PATCH] BSlider didn't like if minimum and maximum limit were the same. Now the slider is drawn correctly in that case, and the thumb stays at the start of the slider (minimal position). This fixes bug #193. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17705 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/Slider.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/kits/interface/Slider.cpp b/src/kits/interface/Slider.cpp index 83556c49d9..debc112962 100644 --- a/src/kits/interface/Slider.cpp +++ b/src/kits/interface/Slider.cpp @@ -574,7 +574,11 @@ BSlider::SetValue(int32 value) if (value != Value()) { BPoint loc; - float pos = (float)(value - fMinValue) / (float)(fMaxValue - fMinValue) * + float range = (float)(fMaxValue - fMinValue); + if (range == 0) + range = 1; + + float pos = (float)(value - fMinValue) / range * _MaxPosition() - _MinPosition(); if (fOrientation == B_HORIZONTAL) { @@ -662,7 +666,11 @@ BSlider::SetPosition(float position) float BSlider::Position() const { - return ((float)(Value() - fMinValue) / (float)(fMaxValue - fMinValue)); + float range = (float)(fMaxValue - fMinValue); + if (range == 0.0f) + range = 1.0f; + + return (float)(Value() - fMinValue) / range; }