From 4c81641aba2a875986749fc814599177e4cd260f Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 28 Nov 2018 17:17:14 +0100 Subject: [PATCH] Added GuiToggleGroupEx() Improved GuiToggleGroup() --- .../controls_test_suite/controls_test_suite.c | 10 +++++--- src/raygui.h | 25 +++++++++++++++++-- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/examples/controls_test_suite/controls_test_suite.c b/examples/controls_test_suite/controls_test_suite.c index 02c338d..8b22caf 100644 --- a/examples/controls_test_suite/controls_test_suite.c +++ b/examples/controls_test_suite/controls_test_suite.c @@ -83,6 +83,8 @@ int main() bool forceSquaredChecked = false; int comboBoxActive = 1; + + int toggleGroupActive = 0; //---------------------------------------------------------------------------------- // Custom GUI font loading @@ -127,7 +129,7 @@ int main() GuiState(GUI_STATE_NORMAL); GuiUnlock(); - comboBoxActive = GuiComboBox((Rectangle){25, 470, 125, 30}, dropdownBox001TextList, 5, comboBoxActive); + comboBoxActive = GuiComboBox((Rectangle){ 25, 470, 125, 30 }, dropdownBox001TextList, 5, comboBoxActive); // NOTE: GuiDropdownBox must draw after any other control that can be covered on unfolding if (GuiDropdownBox((Rectangle){ 25, 65, 125, 30 }, dropdownBox001TextList, 5, &dropdownBox001Active, dropDown001EditMode)) dropDown001EditMode = !dropDown001EditMode; @@ -138,12 +140,14 @@ int main() if (GuiListViewEx((Rectangle){ 165, 180, 140, 200 }, listViewExList, listViewExElementsEnable, 8, &listViewExScrollIndex, &listViewExActive, &listViewExFocus, listViewExEditMode)) listViewExEditMode = !listViewExEditMode; if (listViewExFocus >= 0 && listViewExFocus < 8) DrawText(FormatText("FOCUS: %s", listViewExList[listViewExFocus]), 165, 390, 10, listViewExElementsEnable[listViewExFocus] ? LIME : MAROON); + toggleGroupActive = GuiToggleGroupPro((Rectangle){ 165, 400, 140, 25 }, dropdownBox001TextList, 4, toggleGroupActive, 4, 1); + // Third GUI column if (GuiTextBoxMulti((Rectangle){ 320, 25, 225, 140 }, multiTextBoxText, 141, multiTextBoxEditMode)) multiTextBoxEditMode = !multiTextBoxEditMode; colorPickerValue = GuiColorPicker((Rectangle){ 320, 185, 196, 192 }, colorPickerValue); - sliderValue = GuiSliderEx((Rectangle){ 320, 400, 200, 20 }, sliderValue, -50, 100, "SLIDER", true); - sliderBarValue = GuiSliderBarEx((Rectangle){ 320, 430, 200, 20 }, sliderBarValue, 0, 100, "SLIDERBAR", true); + sliderValue = GuiSliderEx((Rectangle){ 320, 400, 200, 20 }, sliderValue, -50, 100, " ", true); + sliderBarValue = GuiSliderBarEx((Rectangle){ 320, 430, 200, 20 }, sliderBarValue, 0, 100, " ", true); progressValue = GuiProgressBarEx((Rectangle){ 320, 460, 200, 20 }, progressValue, 0, 1, true); //GuiEnable(); diff --git a/src/raygui.h b/src/raygui.h index 3d00e65..f4d1589 100644 --- a/src/raygui.h +++ b/src/raygui.h @@ -334,6 +334,7 @@ RAYGUIDEF bool GuiImageButton(Rectangle bounds, Texture2D texture); RAYGUIDEF bool GuiImageButtonEx(Rectangle bounds, Texture2D texture, Rectangle texSource, const char *text); // Image button extended control, returns true when clicked RAYGUIDEF bool GuiToggle(Rectangle bounds, const char *text, bool toggle); // Toggle Button control, returns true when active RAYGUIDEF int GuiToggleGroup(Rectangle bounds, const char **text, int count, int active); // Toggle Group control, returns toggled button index +RAYGUIDEF int GuiToggleGroupEx(Rectangle bounds, const char **text, int count, int active, int padding, int columns); // Toggle Group with extended parameters RAYGUIDEF bool GuiCheckBox(Rectangle bounds, bool checked); // Check Box control, returns true when active RAYGUIDEF bool GuiCheckBoxEx(Rectangle bounds, bool checked, const char *text); // Check Box control with text, returns true when active RAYGUIDEF int GuiComboBox(Rectangle bounds, const char **text, int count, int active); // Combo Box control, returns selected item index @@ -1040,10 +1041,30 @@ RAYGUIDEF bool GuiToggle(Rectangle bounds, const char *text, bool active) // Toggle Group control, returns toggled button index RAYGUIDEF int GuiToggleGroup(Rectangle bounds, const char **text, int count, int active) { + return GuiToggleGroupEx(bounds, text, count, active, GuiGetStyle(TOGGLE, GROUP_PADDING), 512); +} + +// Toggle Group with pro parameters, returns toggled button index +// NOTE: bounds refer to an individual toggle size, spacing refers to toggles separation and columns defines number of columns +RAYGUIDEF int GuiToggleGroupEx(Rectangle bounds, const char **text, int count, int active, int padding, int columns) +{ + float initBoundsX = bounds.x; + int currentColumn = 0; + for (int i = 0; i < count; i++) { - if (i == active) GuiToggle((Rectangle){ bounds.x + i*(bounds.width/count + GuiGetStyle(TOGGLE, GROUP_PADDING)), bounds.y, (int)(bounds.width - GuiGetStyle(TOGGLE, GROUP_PADDING)*(count -1))/count, bounds.height }, text[i], true); - else if (GuiToggle((Rectangle){ bounds.x + i*(bounds.width/count + GuiGetStyle(TOGGLE, GROUP_PADDING)), bounds.y, (int)(bounds.width - GuiGetStyle(TOGGLE, GROUP_PADDING)*(count -1))/count, bounds.height }, text[i], false) == true) active = i; + if (i == active) GuiToggle(bounds, text[i], true); + else if (GuiToggle(bounds, text[i], false) == true) active = i; + + bounds.x += (bounds.width + padding); + currentColumn++; + + if ((currentColumn + 1) > columns) + { + currentColumn = 0; + bounds.y += (bounds.height + padding); + bounds.x = initBoundsX; + } } return active;