You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently we can't do if(GuiToggleGroup(...)) because the return value is always 0. It should return 1 in the frames where user interacts with it. The only way to achieve running any logic when it's interacted is to store the active parameter right before drawing it and checking if the value of active is changed afterwards.
Suggested changes:
int GuiToggleGroup(Rectangle bounds, const char *text, int *active)
{
#if !defined(RAYGUI_TOGGLEGROUP_MAX_ITEMS)
#define RAYGUI_TOGGLEGROUP_MAX_ITEMS 32
#endif
float initBoundsX = bounds.x;
int temp = 0;
if (active == NULL) active = &temp;
+ int prev_active = active;
bool toggle = false; // Required for individual toggles
// Get substrings items from text (items pointers)
int rows[RAYGUI_TOGGLEGROUP_MAX_ITEMS] = { 0 };
int itemCount = 0;
const char **items = GuiTextSplit(text, ';', &itemCount, rows);
int prevRow = rows[0];
for (int i = 0; i < itemCount; i++)
{
if (prevRow != rows[i])
{
bounds.x = initBoundsX;
bounds.y += (bounds.height + GuiGetStyle(TOGGLE, GROUP_PADDING));
prevRow = rows[i];
}
if (i == (*active))
{
toggle = true;
GuiToggle(bounds, items[i], &toggle);
}
else
{
toggle = false;
GuiToggle(bounds, items[i], &toggle);
if (toggle) *active = i;
}
bounds.x += (bounds.width + GuiGetStyle(TOGGLE, GROUP_PADDING));
}
+ return active != prev_active;
}
The text was updated successfully, but these errors were encountered:
raysan5
changed the title
GuiToggleGroup should return interaction status in current frameGuiToggleGroup() should return interaction status in current frame
Nov 17, 2024
Currently we can't do
if(GuiToggleGroup(...))
because the return value is always 0. It should return 1 in the frames where user interacts with it. The only way to achieve running any logic when it's interacted is to store theactive
parameter right before drawing it and checking if the value ofactive
is changed afterwards.Suggested changes:
Usage
Current (ugh):
With changes:
The text was updated successfully, but these errors were encountered: