From dcfd7a4b5e9c3ccdb0a1ccd1270b214c0ed8ae8d Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sat, 11 May 2013 00:07:17 +0200 Subject: [PATCH] WINGs: Changed the minimum internal knob size of WScroller The original code allowed to have 0.0, but this can generate division by zero in WScrollView. As a value of 0.0 is not realistic anyway, use a minimum constant instead. --- WINGs/wscroller.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/WINGs/wscroller.c b/WINGs/wscroller.c index 671bb229..e6d2cd3c 100644 --- a/WINGs/wscroller.c +++ b/WINGs/wscroller.c @@ -154,6 +154,15 @@ void WMSetScrollerAction(WMScroller * sPtr, WMAction * action, void *clientData) void WMSetScrollerParameters(WMScroller * sPtr, float floatValue, float knobProportion) { + /* + * This value represents 1 pixel on a 4k wide screen, it makes + * a good minimum; this ensure a non-null value to avoid + * potential division-by-0. + * Please note that there is another size check when drawing + * the knob to make sure it will remain selectable. + */ + static const float min_knob_proportion = 1.0 / 4096.0; + CHECK_CLASS(sPtr, WC_Scroller); assert(!isnan(floatValue)); @@ -165,9 +174,9 @@ void WMSetScrollerParameters(WMScroller * sPtr, float floatValue, float knobProp else sPtr->floatValue = floatValue; - if (knobProportion <= 0.0) { + if (knobProportion <= min_knob_proportion) { - sPtr->knobProportion = 0.0; + sPtr->knobProportion = min_knob_proportion; sPtr->flags.documentFullyVisible = 0; } else if (knobProportion >= 1.0) { -- 2.11.4.GIT