Reviewed GuiDropdownBox()

This commit is contained in:
Ray San
2018-03-16 12:55:38 +01:00
parent c1fbefddc3
commit 79455f698a

View File

@ -887,7 +887,7 @@ RAYGUIDEF void GuiStatusBar(Rectangle bounds, const char *text, int offsetX)
} break; } break;
case DISABLED: case DISABLED:
{ {
DrawRectangleRec(bounds, GuiLinesColor()); DrawRectangleRec(bounds, GetColor(style[DEFAULT_BORDER_COLOR_DISABLED]));
DrawRectangleRec((Rectangle){ bounds.x + STATUSBAR_THICK, bounds.y + STATUSBAR_THICK, bounds.width - STATUSBAR_THICK*2, bounds.height - STATUSBAR_THICK*2 }, GetColor(style[DEFAULT_BASE_COLOR_DISABLED])); DrawRectangleRec((Rectangle){ bounds.x + STATUSBAR_THICK, bounds.y + STATUSBAR_THICK, bounds.width - STATUSBAR_THICK*2, bounds.height - STATUSBAR_THICK*2 }, GetColor(style[DEFAULT_BASE_COLOR_DISABLED]));
DrawText(text, bounds.x + offsetX, bounds.y + bounds.height/2 - textHeight/2, style[DEFAULT_TEXT_SIZE], GetColor(style[DEFAULT_TEXT_COLOR_DISABLED])); DrawText(text, bounds.x + offsetX, bounds.y + bounds.height/2 - textHeight/2, style[DEFAULT_TEXT_SIZE], GetColor(style[DEFAULT_TEXT_COLOR_DISABLED]));
} break; } break;
@ -1424,7 +1424,8 @@ RAYGUIDEF int GuiComboBox(Rectangle bounds, const char **text, int count, int ac
// Dropdown Box control, returns selected item // Dropdown Box control, returns selected item
RAYGUIDEF int GuiDropdownBox(Rectangle bounds, const char **text, int count, int active) RAYGUIDEF int GuiDropdownBox(Rectangle bounds, const char **text, int count, int active)
{ {
#define DROPDOWNBOX_PADDING 1 #define DROPDOWNBOX_PADDING 1
#define DROPDOWNBOX_ARROW_RIGHT_PADDING 16
GuiControlState state = guiState; GuiControlState state = guiState;
bool dropActive = false; bool dropActive = false;
@ -1435,6 +1436,8 @@ RAYGUIDEF int GuiDropdownBox(Rectangle bounds, const char **text, int count, int
if (bounds.width < textWidth) bounds.width = textWidth; if (bounds.width < textWidth) bounds.width = textWidth;
if (bounds.height < textHeight) bounds.height = textHeight; if (bounds.height < textHeight) bounds.height = textHeight;
int boundsHeight0 = bounds.height;
// Update control // Update control
//-------------------------------------------------------------------- //--------------------------------------------------------------------
if (state != DISABLED) if (state != DISABLED)
@ -1469,10 +1472,22 @@ RAYGUIDEF int GuiDropdownBox(Rectangle bounds, const char **text, int count, int
switch (state) switch (state)
{ {
case NORMAL: case NORMAL:
{
if (dropActive) GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height/(count + 1) }, text[active], true);
else GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height }, text[active], true);
DrawTriangle((Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING, bounds.y + boundsHeight0/2 - 2 },
(Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING + 5, bounds.y + boundsHeight0/2 - 2 + 5 },
(Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING + 10, bounds.y + boundsHeight0/2 - 2 }, GetColor(style[DEFAULT_TEXT_COLOR_NORMAL]));
} break;
case FOCUSED: case FOCUSED:
{ {
if (dropActive) GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height/(count + 1) }, text[active], true); if (dropActive) GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height/(count + 1) }, text[active], true);
else GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height }, text[active], true); else GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height }, text[active], true);
DrawTriangle((Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING, bounds.y + boundsHeight0/2 - 2 },
(Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING + 5, bounds.y + boundsHeight0/2 - 2 + 5 },
(Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING + 10, bounds.y + boundsHeight0/2 - 2 }, GetColor(style[DEFAULT_TEXT_COLOR_FOCUSED]));
} break; } break;
case PRESSED: case PRESSED:
{ {
@ -1485,10 +1500,17 @@ RAYGUIDEF int GuiDropdownBox(Rectangle bounds, const char **text, int count, int
GuiListElement((Rectangle){ bounds.x, bounds.y + bounds.height/(count + 1)*(i+1) + DROPDOWNBOX_PADDING, bounds.width, bounds.height/(count + 1) - DROPDOWNBOX_PADDING }, text[i], false); GuiListElement((Rectangle){ bounds.x, bounds.y + bounds.height/(count + 1)*(i+1) + DROPDOWNBOX_PADDING, bounds.width, bounds.height/(count + 1) - DROPDOWNBOX_PADDING }, text[i], false);
} }
DrawTriangle((Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING, bounds.y + boundsHeight0/2 - 2 },
(Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING + 5, bounds.y + boundsHeight0/2 - 2 + 5 },
(Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING + 10, bounds.y + boundsHeight0/2 - 2 }, GetColor(style[DEFAULT_TEXT_COLOR_PRESSED]));
} break; } break;
case DISABLED: case DISABLED:
{ {
GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height }, text[active], false); GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height }, text[active], false);
DrawTriangle((Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING, bounds.y + boundsHeight0/2 - 2 },
(Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING + 5, bounds.y + boundsHeight0/2 - 2 + 5 },
(Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING + 10, bounds.y + boundsHeight0/2 - 2 }, GetColor(style[DEFAULT_TEXT_COLOR_DISABLED]));
} break; } break;
default: break; default: break;
} }