From 36365199b11dd967e7147e64c85ccfda8c5064d1 Mon Sep 17 00:00:00 2001 From: Ludovic J Date: Fri, 28 Jul 2023 19:55:37 +0200 Subject: [PATCH] Fix GuiScrollBar dragging taking slider behavior (#313) --- src/raygui.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/raygui.h b/src/raygui.h index 9cba681..6d463d2 100644 --- a/src/raygui.h +++ b/src/raygui.h @@ -4878,14 +4878,16 @@ static int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue) if (guiSliderDragging) // Keep dragging outside of bounds { - if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) && + !CheckCollisionPointRec(mousePoint, arrowUpLeft) && + !CheckCollisionPointRec(mousePoint, arrowDownRight)) { if (CHECK_BOUNDS_ID(bounds, guiSliderActive)) { state = STATE_PRESSED; - if (isVertical) value += (int)(GetMouseDelta().y/(scrollbar.height - slider.height)*valueRange); - else value += (int)(GetMouseDelta().x/(scrollbar.width - slider.width)*valueRange); + if (isVertical) value = (int)(((float)(mousePoint.y - scrollbar.y - slider.height/2)*valueRange)/(scrollbar.height - slider.height) + minValue); + else value = (int)(((float)(mousePoint.x - scrollbar.x - slider.width/2)*valueRange)/(scrollbar.width - slider.width) + minValue); } } else @@ -4920,11 +4922,6 @@ static int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue) state = STATE_PRESSED; } - else if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) - { - if (isVertical) value += (int)(GetMouseDelta().y/(scrollbar.height - slider.height)*valueRange); - else value += (int)(GetMouseDelta().x/(scrollbar.width - slider.width)*valueRange); - } // Keyboard control on mouse hover scrollbar /*