From 8a13b16246b622fb66f38b5ecd057ee54e01e461 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 8 Feb 2019 12:52:26 +0100 Subject: [PATCH] Working on issue #22 -WIP- Trying to remove styling elements from functions --- .../controls_test_suite/controls_test_suite.c | 4 +- src/raygui.h | 47 +++++++++++-------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/examples/controls_test_suite/controls_test_suite.c b/examples/controls_test_suite/controls_test_suite.c index 8df7ba8..11cd207 100644 --- a/examples/controls_test_suite/controls_test_suite.c +++ b/examples/controls_test_suite/controls_test_suite.c @@ -114,7 +114,7 @@ int main() // First GUI column forceSquaredChecked = GuiCheckBox((Rectangle){ 25, 108, 15, 15 }, "Force Square", forceSquaredChecked); - if (GuiSpinner((Rectangle){ 25, 135, 125, 30 }, &spinner001Value, 0, 100, 25, spinnerEditMode)) spinnerEditMode = !spinnerEditMode; + if (GuiSpinner((Rectangle){ 25, 135, 125, 30 }, &spinner001Value, 0, 100, spinnerEditMode)) spinnerEditMode = !spinnerEditMode; if (GuiValueBox((Rectangle){ 25, 175, 125, 30 }, &valueBox002Value, 0, 100, valueBoxEditMode)) valueBoxEditMode = !valueBoxEditMode; if (GuiTextBox((Rectangle){ 25, 215, 125, 30 }, textBoxText, 64, textBoxEditMode)) textBoxEditMode = !textBoxEditMode; @@ -142,7 +142,7 @@ int main() if (GuiListViewEx((Rectangle){ 165, 180, 140, 200 }, listViewExList, 8, listViewExElementsEnable, &listViewExActive, &listViewExFocus, &listViewExScrollIndex, listViewExEditMode)) listViewExEditMode = !listViewExEditMode; if (listViewExFocus >= 0 && listViewExFocus < 8) DrawText(FormatText("FOCUS: %s", listViewExList[listViewExFocus]), 165, 390, 10, listViewExElementsEnable[listViewExFocus] ? LIME : MAROON); - toggleGroupActive = GuiToggleGroupEx((Rectangle){ 165, 400, 140, 25 }, "ONE;TWO;THREE;FOUR", toggleGroupActive, 4, 1); + toggleGroupActive = GuiToggleGroup((Rectangle){ 165, 400, 140, 25 }, "ONE\nTWO\nTHREE\nFOUR", toggleGroupActive); // Third GUI column if (GuiTextBoxMulti((Rectangle){ 320, 25, 225, 140 }, multiTextBoxText, 141, multiTextBoxEditMode)) multiTextBoxEditMode = !multiTextBoxEditMode; diff --git a/src/raygui.h b/src/raygui.h index bc12fdd..098d462 100644 --- a/src/raygui.h +++ b/src/raygui.h @@ -360,12 +360,11 @@ 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 active); // Toggle Button control, returns true when active RAYGUIDEF int GuiToggleGroup(Rectangle bounds, const char *text, int active); // Toggle Group control, returns active toggle index -RAYGUIDEF int GuiToggleGroupEx(Rectangle bounds, const char *text, int active, int padding, int columns); // Toggle Group with extended parameters RAYGUIDEF bool GuiCheckBox(Rectangle bounds, const char *text, bool checked); // Check Box control, returns true when active RAYGUIDEF int GuiComboBox(Rectangle bounds, const char *text, int active); // Combo Box control, returns selected item index RAYGUIDEF bool GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMode); // Dropdown Box control, returns selected item -RAYGUIDEF bool GuiSpinner(Rectangle bounds, int *value, int minValue, int maxValue, int btnWidth, bool editMode); // Spinner control, returns selected value -RAYGUIDEF bool GuiValueBox(Rectangle bounds, int *value, int minValue, int maxValue, bool editMode); // Value Box control, updates input text with numbers +RAYGUIDEF bool GuiSpinner(Rectangle bounds, int *value, int minValue, int maxValue, bool editMode); // Spinner control, returns selected value +RAYGUIDEF bool GuiValueBox(Rectangle bounds, int *value, int minValue, int maxValue, bool editMode); // Value Box control, updates input text with numbers RAYGUIDEF bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode); // Text Box control, updates input text RAYGUIDEF bool GuiTextBoxMulti(Rectangle bounds, char *text, int textSize, bool editMode); // Text Box control with multiple lines RAYGUIDEF float GuiSlider(Rectangle bounds, const char *text, float value, float minValue, float maxValue, bool showValue); // Slider control, returns selected value @@ -373,7 +372,7 @@ RAYGUIDEF float GuiSliderBar(Rectangle bounds, const char *text, float value, fl RAYGUIDEF float GuiProgressBar(Rectangle bounds, const char *text, float value, float minValue, float maxValue, bool showValue); // Progress Bar control, shows current progress value RAYGUIDEF void GuiStatusBar(Rectangle bounds, const char *text, int offsetX); // Status Bar control, shows info text RAYGUIDEF void GuiDummyRec(Rectangle bounds, const char *text); // Dummy control for placeholders -RAYGUIDEF int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue); +RAYGUIDEF int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue); // Scroll Bar control // Advance controls set RAYGUIDEF bool GuiListView(Rectangle bounds, const char *text, int *active, int *scrollIndex, bool editMode); // List View control, returns selected list element index @@ -1188,19 +1187,24 @@ 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 active) -{ - return GuiToggleGroupEx(bounds, text, active, GuiGetStyle(TOGGLE, GROUP_PADDING), 32); -} - -// 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 active, int padding, int columns) { #define TOGGLEGROUP_MAX_ELEMENTS 16 #define TOGGLEGROUP_ELEMENTS_DELIMITER ';' float initBoundsX = bounds.x; int currentColumn = 0; + + // TODO: columns parameter + int textLen = strlen(text); + int currrentRow = 0; + int currentElement = 0; + bool elementRow[TOGGLEGROUP_MAX_ELEMENTS] = { 0 }; + for (int i = 0; i < textLen; i++) + { + elementRow[currentElement] = currrentRow; + if (text[i] == ';') currentElement++; + if (text[i] == '\n') currrentRow++; + } // Get substrings elements from text (elements pointers, lengths and count) const char *elementsPtrs[TOGGLEGROUP_MAX_ELEMENTS] = { NULL }; @@ -1213,15 +1217,18 @@ RAYGUIDEF int GuiToggleGroupEx(Rectangle bounds, const char *text, int active, i if (i == active) GuiToggle(bounds, TextSubtext(elementsPtrs[i], 0, elementsLen[i]), true); else if (GuiToggle(bounds, TextSubtext(elementsPtrs[i], 0, elementsLen[i]), false) == true) active = i; - bounds.x += (bounds.width + padding); + bounds.x += (bounds.width + GuiGetStyle(TOGGLE, GROUP_PADDING)); currentColumn++; - if ((currentColumn + 1) > columns) + // TODO: Implement columns logic + /* + if ((currentColumn + 1) > columns) { currentColumn = 0; - bounds.y += (bounds.height + padding); + bounds.y += (bounds.height + GuiGetStyle(TOGGLE, GROUP_PADDING)); bounds.x = initBoundsX; } + */ } return active; @@ -1545,15 +1552,16 @@ RAYGUIDEF bool GuiDropdownBox(Rectangle bounds, const char *text, int *active, b // Spinner control, returns selected value // NOTE: Requires static variables: framesCounter, valueSpeed - ERROR! -RAYGUIDEF bool GuiSpinner(Rectangle bounds, int *value, int minValue, int maxValue, int btnWidth, bool editMode) +RAYGUIDEF bool GuiSpinner(Rectangle bounds, int *value, int minValue, int maxValue, bool editMode) { bool pressed = false; int tempValue = *value; int tempBorderWidth = GuiGetStyle(BUTTON, BORDER_WIDTH); - Rectangle spinner = { bounds.x + btnWidth + GuiGetStyle(TEXTBOX, SPINNER_BUTTON_PADDING), bounds.y, bounds.width - 2*(btnWidth + GuiGetStyle(TEXTBOX, SPINNER_BUTTON_PADDING)), bounds.height }; - Rectangle leftButtonBound = { bounds.x, bounds.y, btnWidth, bounds.height }; - Rectangle rightButtonBound = { bounds.x + bounds.width - btnWidth, bounds.y, btnWidth, bounds.height }; + Rectangle spinner = { bounds.x + GuiGetStyle(TEXTBOX, SPINNER_BUTTON_WIDTH) + GuiGetStyle(TEXTBOX, SPINNER_BUTTON_PADDING), bounds.y, + bounds.width - 2*(GuiGetStyle(TEXTBOX, SPINNER_BUTTON_WIDTH) + GuiGetStyle(TEXTBOX, SPINNER_BUTTON_PADDING)), bounds.height }; + Rectangle leftButtonBound = { bounds.x, bounds.y, GuiGetStyle(TEXTBOX, SPINNER_BUTTON_WIDTH), bounds.height }; + Rectangle rightButtonBound = { bounds.x + bounds.width - GuiGetStyle(TEXTBOX, SPINNER_BUTTON_WIDTH), bounds.y, GuiGetStyle(TEXTBOX, SPINNER_BUTTON_WIDTH), bounds.height }; int textWidth = GuiTextWidth(TextFormat("%i", tempValue)); int textHeight = GuiGetStyle(DEFAULT, TEXT_SIZE); @@ -2275,6 +2283,7 @@ RAYGUIDEF void GuiDummyRec(Rectangle bounds, const char *text) //------------------------------------------------------------------ } +// Scroll Bar control RAYGUIDEF int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue) { GuiControlState state = guiState; @@ -3293,7 +3302,7 @@ RAYGUIDEF void GuiLoadStyleDefault(void) GuiSetStyle(DROPDOWNBOX, ARROW_RIGHT_PADDING, 16); GuiSetStyle(TEXTBOX, INNER_PADDING, 4); GuiSetStyle(TEXTBOX, MULTILINE_PADDING, 5); - GuiSetStyle(TEXTBOX, SPINNER_BUTTON_PADDING, 20); // SPINNER specific property + GuiSetStyle(TEXTBOX, SPINNER_BUTTON_WIDTH, 20); // SPINNER specific property GuiSetStyle(TEXTBOX, SPINNER_BUTTON_PADDING, 2); // SPINNER specific property GuiSetStyle(TEXTBOX, SPINNER_BUTTON_BORDER_WIDTH, 1); // SPINNER specific property GuiSetStyle(COLORPICKER, COLOR_SELECTOR_SIZE, 6);