diff --git a/examples/controls_test_suite/controls_test_suite.c b/examples/controls_test_suite/controls_test_suite.c index 1a47efe..51d6dc2 100644 --- a/examples/controls_test_suite/controls_test_suite.c +++ b/examples/controls_test_suite/controls_test_suite.c @@ -103,6 +103,8 @@ int main() char textInput[256] = { 0 }; bool showTextInputBox = false; + + char textInputFileName[256] = { 0 }; SetTargetFPS(60); //-------------------------------------------------------------------------------------- @@ -213,12 +215,21 @@ int main() if (showTextInputBox) { - char textInputTemp[256] = { 0 }; DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, 0.8f)); - int result = GuiTextInputBox((Rectangle){ GetScreenWidth()/2 - 120, GetScreenHeight()/2 - 60, 240, 120 }, GuiIconText(RICON_FILE_SAVE, "Save file as..."), textInputTemp, "Ok;Cancel"); + int result = GuiTextInputBox((Rectangle){ GetScreenWidth()/2 - 120, GetScreenHeight()/2 - 60, 240, 120 }, GuiIconText(RICON_FILE_SAVE, "Save file as..."), textInput, "Ok;Cancel"); - if ((result == 0) || (result == 2)) showTextInputBox = false; - else if (result == 1) strcpy(textInput, textInputTemp); + if (result == 1) + { + // TODO: Validate textInput value and save + + strcpy(textInputFileName, textInput); + } + + if ((result == 0) || (result == 1) || (result == 2)) + { + showTextInputBox = false; + strcpy(textInput, "\0"); + } } GuiUnlock(); diff --git a/examples/controls_test_suite/gui_file_dialog.h b/examples/controls_test_suite/gui_file_dialog.h index 673ac61..70f9c79 100644 --- a/examples/controls_test_suite/gui_file_dialog.h +++ b/examples/controls_test_suite/gui_file_dialog.h @@ -115,7 +115,7 @@ typedef struct FileInfo { static char **ReadDirectoryFiles(const char *dir, int *filesCount, char *filterExt); // List View control for files info with extended parameters -static int GuiListViewFiles(Rectangle bounds, const char **text, int count, int *focus, int *scrollIndex, int active) +static int GuiListViewFiles(Rectangle bounds, const char **text, int count, int *focus, int *scrollIndex, int active); //static int GuiListViewFiles(Rectangle bounds, FileInfo *files, int count, int *focus, int *scrollIndex, int active) //---------------------------------------------------------------------------------- diff --git a/src/raygui.h b/src/raygui.h index 61c44c5..b7363ba 100644 --- a/src/raygui.h +++ b/src/raygui.h @@ -3714,6 +3714,12 @@ RAYGUIDEF int GuiTextInputBox(Rectangle bounds, const char *windowTitle, char *t #define TEXTINPUTBOX_BUTTON_PADDING 10 #define TEXTINPUTBOX_HEIGHT 30 + #define MAX_FILENAME_LENGTH 256 + + // Used to enable text edit mode + // WARNING: No more than one GuiTextInputBox() should be open at the same time + static textEditMode = false; + int btnIndex = -1; int buttonsCount = 0; @@ -3734,7 +3740,7 @@ RAYGUIDEF int GuiTextInputBox(Rectangle bounds, const char *windowTitle, char *t //-------------------------------------------------------------------- if (GuiWindowBox(bounds, windowTitle)) btnIndex = 0; - GuiTextBox(textBoxBounds, text, 256, true); + if (GuiTextBox(textBoxBounds, text, MAX_FILENAME_LENGTH, textEditMode)) textEditMode = !textEditMode; int prevBtnTextAlignment = GuiGetStyle(BUTTON, TEXT_ALIGNMENT); GuiSetStyle(BUTTON, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_CENTER);