Browse Source

Use floor for mouse to cell mapping, it is more readable and would work for theoretical negative cell positions. (#241)

Jeffery Myers 2 years ago
parent
commit
59cf0c7607
1 changed files with 3 additions and 3 deletions
  1. 3 3
      src/raygui.h

+ 3 - 3
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));
         }
     }
     //--------------------------------------------------------------------