Review GuiToggleButton()
This commit is contained in:
parent
6ee5718b2e
commit
18a13679fd
1 changed files with 17 additions and 4 deletions
21
src/raygui.c
21
src/raygui.c
|
@ -258,15 +258,28 @@ bool GuiToggleButton(Rectangle bounds, const char *text, bool toggle)
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
if (toggleButton.width < textWidth) toggleButton.width = textWidth + style[TOGGLE_TEXT_PADDING];
|
if (toggleButton.width < textWidth) toggleButton.width = textWidth + style[TOGGLE_TEXT_PADDING];
|
||||||
if (toggleButton.height < textHeight) toggleButton.height = textHeight + style[TOGGLE_TEXT_PADDING]/2;
|
if (toggleButton.height < textHeight) toggleButton.height = textHeight + style[TOGGLE_TEXT_PADDING]/2;
|
||||||
|
|
||||||
|
if (toggle) toggleState = TOGGLE_ACTIVE;
|
||||||
|
else toggleState = TOGGLE_UNACTIVE;
|
||||||
|
|
||||||
if (CheckCollisionPointRec(mousePoint, toggleButton))
|
if (CheckCollisionPointRec(mousePoint, toggleButton))
|
||||||
{
|
{
|
||||||
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) toggleState = TOGGLE_PRESSED;
|
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) toggleState = TOGGLE_PRESSED;
|
||||||
else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) toggleState = TOGGLE_ACTIVE;
|
else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
|
||||||
|
{
|
||||||
|
if (toggle)
|
||||||
|
{
|
||||||
|
toggle = false;
|
||||||
|
toggleState = TOGGLE_UNACTIVE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
toggle = true;
|
||||||
|
toggleState = TOGGLE_ACTIVE;
|
||||||
|
}
|
||||||
|
}
|
||||||
else toggleState = TOGGLE_HOVER;
|
else toggleState = TOGGLE_HOVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toggleState == TOGGLE_ACTIVE && !toggle) toggle = true;
|
|
||||||
if (toggle) toggleState = TOGGLE_ACTIVE;
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw control
|
// Draw control
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue