From 70c6eef9d18e69be13b7b17d951096c10f0412fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez?= Date: Tue, 23 Oct 2018 17:44:44 +0200 Subject: [PATCH] GuiCheckBoxEx and GuiLabelButton review --- examples/controls_review/controls_review.c | 6 +++++- src/raygui.h | 14 ++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/examples/controls_review/controls_review.c b/examples/controls_review/controls_review.c index 78590b7..0aefab8 100644 --- a/examples/controls_review/controls_review.c +++ b/examples/controls_review/controls_review.c @@ -52,6 +52,8 @@ int main() bool dropDown000EditMode = false; bool dropDown001EditMode = false; + + bool forceSquaredChecked = false; //---------------------------------------------------------------------------------- Font font = LoadFontEx("fonts/NorthernLights.ttf", 30, 0, 0); @@ -89,8 +91,10 @@ int main() //GuiScrollPanel((Rectangle){ 325, 225, 225, 125 }, "SAMPLE TEXT"); if (GuiDropdownBox((Rectangle){ 25, 75, 125, 30 }, DropdownBox000TextList, 3, &DropdownBox001Active, dropDown001EditMode)) dropDown001EditMode = !dropDown001EditMode; - + //forceSquaredChecked = GuiCheckBoxEx((Rectangle){ 25, 65, 15, 15 }, forceSquaredChecked, "Force Square"); + GuiDisable(); if (GuiDropdownBox((Rectangle){ 25, 25, 125, 30 }, DropdownBox000TextList, 3, &DropdownBox000Active, dropDown000EditMode)) dropDown000EditMode = !dropDown000EditMode; + GuiEnable(); GuiLock(); GuiState(0); if (GuiButton((Rectangle){ 25, 400, 125, 30 }, "SAMPLE TEXT")) Button005(); diff --git a/src/raygui.h b/src/raygui.h index 8e0d519..1e94b82 100644 --- a/src/raygui.h +++ b/src/raygui.h @@ -1197,7 +1197,7 @@ RAYGUIDEF bool GuiButton(Rectangle bounds, const char *text) RAYGUIDEF bool GuiLabelButton(Rectangle bounds, const char *text) { GuiControlState state = guiState; - bool clicked = false; + bool pressed = false; int textWidth = GuiTextWidth(text); int textHeight = style[DEFAULT_TEXT_SIZE]; @@ -1211,12 +1211,13 @@ RAYGUIDEF bool GuiLabelButton(Rectangle bounds, const char *text) { Vector2 mousePoint = GetMousePosition(); - // Check label state + // Check checkbox state if (CheckCollisionPointRec(mousePoint, bounds)) { if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = PRESSED; - else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) clicked = true; else state = FOCUSED; + + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) pressed = true; } } //-------------------------------------------------------------------- @@ -1233,7 +1234,7 @@ RAYGUIDEF bool GuiLabelButton(Rectangle bounds, const char *text) } //-------------------------------------------------------------------- - return clicked; + return pressed; } // Image button control, returns true when clicked @@ -1495,8 +1496,9 @@ RAYGUIDEF bool GuiCheckBoxEx(Rectangle bounds, bool checked, const char *text) if (CheckCollisionPointRec(mousePoint, bounds)) { if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = PRESSED; - else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) checked = !checked; else state = FOCUSED; + + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) checked = !checked; } } //-------------------------------------------------------------------- @@ -1755,7 +1757,7 @@ RAYGUIDEF bool GuiDropdownBox(Rectangle bounds, const char **text, int count, in { DrawRectangle(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(style[DEFAULT_BASE_COLOR_DISABLED]), guiAlpha)); DrawRectangleLinesEx(bounds, DROPDOWNBOX_BORDER_WIDTH, Fade(GetColor(style[LISTVIEW_BORDER_COLOR_DISABLED]), guiAlpha)); - GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height }, text[activeAux], false, true); + GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height }, text[activeAux], false, false); DrawTriangle((Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING, bounds.y + bounds.height/2 - 2 }, (Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING + 5, bounds.y + bounds.height/2 - 2 + 5 },