Skip to content

Commit

Permalink
REVIEWED: GuiGrid() to support STATE_DISABLED
Browse files Browse the repository at this point in the history
  • Loading branch information
raysan5 committed Oct 3, 2023
1 parent cfb9191 commit 85a5c10
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions src/raygui.h
Original file line number Diff line number Diff line change
Expand Up @@ -3894,12 +3894,14 @@ int GuiGrid(Rectangle bounds, const char *text, float spacing, int subdivs, Vect
GuiState state = guiState;

Vector2 mousePoint = GetMousePosition();
Vector2 currentMouseCell = { 0 };
Vector2 currentMouseCell = { -1, -1 };

float spaceWidth = spacing/(float)subdivs;
int linesV = (int)(bounds.width/spaceWidth) + 1;
int linesH = (int)(bounds.height/spaceWidth) + 1;

int color = GuiGetStyle(DEFAULT, LINE_COLOR);

// Update control
//--------------------------------------------------------------------
if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
Expand All @@ -3915,28 +3917,23 @@ int GuiGrid(Rectangle bounds, const char *text, float spacing, int subdivs, Vect

// Draw control
//--------------------------------------------------------------------
switch (state)
if (state == STATE_DISABLED) color = GuiGetStyle(DEFAULT, BORDER_COLOR_DISABLED);

if (subdivs > 0)
{
case STATE_NORMAL:
// Draw vertical grid lines
for (int i = 0; i < linesV; i++)
{
if (subdivs > 0)
{
// Draw vertical grid lines
for (int i = 0; i < linesV; i++)
{
Rectangle lineV = { bounds.x + spacing*i/subdivs, bounds.y, 1, bounds.height };
GuiDrawRectangle(lineV, 0, BLANK, ((i%subdivs) == 0)? GuiFade(GetColor(GuiGetStyle(DEFAULT, LINE_COLOR)), RAYGUI_GRID_ALPHA*4) : GuiFade(GetColor(GuiGetStyle(DEFAULT, LINE_COLOR)), RAYGUI_GRID_ALPHA));
}
Rectangle lineV = { bounds.x + spacing*i/subdivs, bounds.y, 1, bounds.height };
GuiDrawRectangle(lineV, 0, BLANK, ((i%subdivs) == 0)? GuiFade(GetColor(color), RAYGUI_GRID_ALPHA*4) : GuiFade(GetColor(color), RAYGUI_GRID_ALPHA));
}

// Draw horizontal grid lines
for (int i = 0; i < linesH; i++)
{
Rectangle lineH = { bounds.x, bounds.y + spacing*i/subdivs, bounds.width, 1 };
GuiDrawRectangle(lineH, 0, BLANK, ((i%subdivs) == 0)? GuiFade(GetColor(GuiGetStyle(DEFAULT, LINE_COLOR)), RAYGUI_GRID_ALPHA*4) : GuiFade(GetColor(GuiGetStyle(DEFAULT, LINE_COLOR)), RAYGUI_GRID_ALPHA));
}
}
} break;
default: break;
// Draw horizontal grid lines
for (int i = 0; i < linesH; i++)
{
Rectangle lineH = { bounds.x, bounds.y + spacing*i/subdivs, bounds.width, 1 };
GuiDrawRectangle(lineH, 0, BLANK, ((i%subdivs) == 0)? GuiFade(GetColor(color), RAYGUI_GRID_ALPHA*4) : GuiFade(GetColor(color), RAYGUI_GRID_ALPHA));
}
}

if (mouseCell != NULL) *mouseCell = currentMouseCell;
Expand Down

0 comments on commit 85a5c10

Please sign in to comment.