From c98db2bc6f7dec12f455f48b5b178ebeb80e9a8c Mon Sep 17 00:00:00 2001 From: Leonard Ritter Date: Tue, 8 Jul 2014 15:43:44 +0200 Subject: [PATCH] moved scrollhandle calculation to tool function --- blendish.h | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/blendish.h b/blendish.h index e9f7523..a4ab3f6 100644 --- a/blendish.h +++ b/blendish.h @@ -343,6 +343,13 @@ void bndInnerColors(NVGcolor *shade_top, NVGcolor *shade_down, // widgets state. NVGcolor bndTextColor(const BNDwidgetTheme *theme, BNDwidgetState state); +// computes the bounds of the scrollbar handle from the scrollbar size +// and the handles offset and size. +// offset is in the range 0..1 and defines the position of the scroll handle +// size is in the range 0..1 and defines the size of the scroll handle +void bndScrollHandleRect(float *x, float *y, float *w, float *h, + float offset, float size); + // Add a rounded box path at position (x,y) with size (w,h) and a separate // radius for each corner listed in clockwise order, so that cr0 = top left, // cr1 = top right, cr2 = bottom right, cr3 = bottom left; @@ -813,17 +820,7 @@ void bndScrollBar(NVGcontext *ctx, bnd_theme.scrollBarTheme.itemColor, (state == BND_ACTIVE)?BND_SCROLLBAR_ACTIVE_SHADE:0); - size = bnd_clamp(size,0,1); - offset = bnd_clamp(offset,0,1); - if (h>w) { - float hs = fmaxf(size*h, w+1); - y = y + (h-hs)*offset; - h = hs; - } else { - float ws = fmaxf(size*w, h-1); - x = x + (w-ws)*offset; - w = ws; - } + bndScrollHandleRect(&x,&y,&w,&h,offset,size); bndInnerBox(ctx,x,y,w,h, BND_SCROLLBAR_RADIUS,BND_SCROLLBAR_RADIUS, @@ -1130,6 +1127,21 @@ void bndUpDownArrow(NVGcontext *ctx, float x, float y, float s, NVGcolor color) nvgFill(ctx); } +void bndScrollHandleRect(float *x, float *y, float *w, float *h, + float offset, float size) { + size = bnd_clamp(size,0,1); + offset = bnd_clamp(offset,0,1); + if ((*h) > (*w)) { + float hs = fmaxf(size*(*h), (*w)+1); + *y = (*y) + ((*h)-hs)*offset; + *h = hs; + } else { + float ws = fmaxf(size*(*w), (*h)-1); + *x = (*x) + ((*w)-ws)*offset; + *w = ws; + } +} + //////////////////////////////////////////////////////////////////////////////// #ifdef BND_INLINE