From 59cf0c7607a772082e08e3e59397541340ab8a6b Mon Sep 17 00:00:00 2001 From: Jeffery Myers Date: Mon, 7 Nov 2022 10:22:28 -0800 Subject: [PATCH] Use floor for mouse to cell mapping, it is more readable and would work for theoretical negative cell positions. (#241) --- src/raygui.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/raygui.h b/src/raygui.h index a118dbe..402cb66 100644 --- a/src/raygui.h +++ b/src/raygui.h @@ -3283,9 +3283,9 @@ Vector2 GuiGrid(Rectangle bounds, const char *text, float spacing, int subdivs) { if (CheckCollisionPointRec(mousePoint, bounds)) { - // NOTE: Cell values must be rounded to int - currentCell.x = (float)((int)((mousePoint.x - bounds.x)/spacing)); - currentCell.y = (float)((int)((mousePoint.y - bounds.y)/spacing)); + // NOTE: Cell values must be the upper left of the cell the mouse is in + currentCell.x = floorf((mousePoint.x - bounds.x)/spacing)); + currentCell.y = floorf((mousePoint.y - bounds.y)/spacing)); } } //--------------------------------------------------------------------