From a609522c052dc7a791f3b6636f297218c3ec0587 Mon Sep 17 00:00:00 2001 From: Andidy <37605997+Andidy@users.noreply.github.com> Date: Sun, 7 Nov 2021 03:55:17 -0600 Subject: [PATCH] Fixed Spinner control bounds check error (#166) The bounds check occurred before the `GuiButton`s for the increment and decrement feature of the `Spinner` control which meant using the buttons when the spinner value was at the `minValue` or `maxValue` and incremented or decremented past the min or max would not be resolved until the next time the `Spinner` control was called in the code, likely on the next iteration of a program loop. This caused an array index out of bounds issue in my codebase. --- src/raygui.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/raygui.h b/src/raygui.h index 9bc0132..5d722e9 100644 --- a/src/raygui.h +++ b/src/raygui.h @@ -2079,6 +2079,14 @@ bool GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, in } } +#if defined(RAYGUI_NO_RICONS) + if (GuiButton(leftButtonBound, "<")) tempValue--; + if (GuiButton(rightButtonBound, ">")) tempValue++; +#else + if (GuiButton(leftButtonBound, GuiIconText(RICON_ARROW_LEFT_FILL, NULL))) tempValue--; + if (GuiButton(rightButtonBound, GuiIconText(RICON_ARROW_RIGHT_FILL, NULL))) tempValue++; +#endif + if (!editMode) { if (tempValue < minValue) tempValue = minValue; @@ -2098,13 +2106,7 @@ bool GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, in GuiSetStyle(BUTTON, BORDER_WIDTH, GuiGetStyle(SPINNER, BORDER_WIDTH)); GuiSetStyle(BUTTON, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_CENTER); -#if defined(RAYGUI_NO_RICONS) - if (GuiButton(leftButtonBound, "<")) tempValue--; - if (GuiButton(rightButtonBound, ">")) tempValue++; -#else - if (GuiButton(leftButtonBound, GuiIconText(RICON_ARROW_LEFT_FILL, NULL))) tempValue--; - if (GuiButton(rightButtonBound, GuiIconText(RICON_ARROW_RIGHT_FILL, NULL))) tempValue++; -#endif + GuiSetStyle(BUTTON, TEXT_ALIGNMENT, tempTextAlign); GuiSetStyle(BUTTON, BORDER_WIDTH, tempBorderWidth);