diff --git a/examples/controls_test_suite/controls_test_suite.c b/examples/controls_test_suite/controls_test_suite.c index 92064e5..6e3361c 100644 --- a/examples/controls_test_suite/controls_test_suite.c +++ b/examples/controls_test_suite/controls_test_suite.c @@ -204,7 +204,7 @@ int main() if (showTextInputBox) { 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..."), NULL, textInput, "Ok;Cancel"); + int result = GuiTextInputBox((Rectangle){ GetScreenWidth()/2 - 120, GetScreenHeight()/2 - 60, 240, 140 }, GuiIconText(RICON_FILE_SAVE, "Save file as..."), "Introduce a save file name", "Ok;Cancel", textInput); if (result == 1) { diff --git a/src/raygui.h b/src/raygui.h index 1516873..45ce22d 100644 --- a/src/raygui.h +++ b/src/raygui.h @@ -408,8 +408,8 @@ RAYGUIDEF int GuiTextBoxGetByteIndex(const char *text, int start, int from, int #endif // Container/separator controls, useful for controls organization -RAYGUIDEF bool GuiWindowBox(Rectangle bounds, const char *text); // Window Box control, shows a window that can be closed -RAYGUIDEF void GuiGroupBox(Rectangle bounds, const char *text); // Group Box control with title name +RAYGUIDEF bool GuiWindowBox(Rectangle bounds, const char *title); // Window Box control, shows a window that can be closed +RAYGUIDEF void GuiGroupBox(Rectangle bounds, const char *text); // Group Box control with text name RAYGUIDEF void GuiLine(Rectangle bounds, const char *text); // Line separator control, could contain text RAYGUIDEF void GuiPanel(Rectangle bounds); // Panel control, useful to group controls RAYGUIDEF Rectangle GuiScrollPanel(Rectangle bounds, Rectangle content, Vector2 *scroll); // Scroll Panel control @@ -439,9 +439,9 @@ RAYGUIDEF Vector2 GuiGrid(Rectangle bounds, float spacing, int subdivs); // Advance controls set RAYGUIDEF int GuiListView(Rectangle bounds, const char *text, int *scrollIndex, int active); // List View control, returns selected list element index -RAYGUIDEF int GuiListViewEx(Rectangle bounds, const char **text, int count, int *focus, int *scrollIndex, int active); // List View with extended parameters -RAYGUIDEF int GuiMessageBox(Rectangle bounds, const char *windowTitle, const char *message, const char *buttons); // Message Box control, displays a message -RAYGUIDEF int GuiTextInputBox(Rectangle bounds, const char *windowTitle, const char *message, char *text, const char *buttons); // Text Input Box control, ask for text +RAYGUIDEF int GuiListViewEx(Rectangle bounds, const char **text, int count, int *focus, int *scrollIndex, int active); // List View with extended parameters +RAYGUIDEF int GuiMessageBox(Rectangle bounds, const char *title, const char *message, const char *buttons); // Message Box control, displays a message +RAYGUIDEF int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, const char *buttons, char *text); // Text Input Box control, ask for text RAYGUIDEF Color GuiColorPicker(Rectangle bounds, Color color); // Color Picker control // Styles loading functions @@ -833,7 +833,7 @@ RAYGUIDEF void GuiTextBoxSetState(GuiTextBoxState state) #endif // Window Box control -RAYGUIDEF bool GuiWindowBox(Rectangle bounds, const char *text) +RAYGUIDEF bool GuiWindowBox(Rectangle bounds, const char *title) { // NOTE: This define is also used by GuiMessageBox() and GuiTextInputBox() #define WINDOW_STATUSBAR_HEIGHT 22 @@ -865,7 +865,7 @@ RAYGUIDEF bool GuiWindowBox(Rectangle bounds, const char *text) Fade(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)), guiAlpha)); // Draw window header as status bar - GuiStatusBar(statusBar, text); + GuiStatusBar(statusBar, title); // Draw window close button int tempBorderWidth = GuiGetStyle(BUTTON, BORDER_WIDTH); @@ -884,7 +884,7 @@ RAYGUIDEF bool GuiWindowBox(Rectangle bounds, const char *text) return clicked; } -// Group Box control with title name +// Group Box control with text name RAYGUIDEF void GuiGroupBox(Rectangle bounds, const char *text) { #define GROUPBOX_LINE_THICK 1 @@ -3747,7 +3747,7 @@ RAYGUIDEF Color GuiColorPicker(Rectangle bounds, Color color) } // Message Box control -RAYGUIDEF int GuiMessageBox(Rectangle bounds, const char *windowTitle, const char *message, const char *buttons) +RAYGUIDEF int GuiMessageBox(Rectangle bounds, const char *title, const char *message, const char *buttons) { #define MESSAGEBOX_BUTTON_HEIGHT 24 #define MESSAGEBOX_BUTTON_PADDING 10 @@ -3772,7 +3772,7 @@ RAYGUIDEF int GuiMessageBox(Rectangle bounds, const char *windowTitle, const cha // Draw control //-------------------------------------------------------------------- - if (GuiWindowBox(bounds, windowTitle)) clicked = 0; + if (GuiWindowBox(bounds, title)) clicked = 0; int prevTextAlignment = GuiGetStyle(LABEL, TEXT_ALIGNMENT); GuiSetStyle(LABEL, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_CENTER); @@ -3795,7 +3795,7 @@ RAYGUIDEF int GuiMessageBox(Rectangle bounds, const char *windowTitle, const cha } // Text Input Box control, ask for text -RAYGUIDEF int GuiTextInputBox(Rectangle bounds, const char *windowTitle, const char *message, char *text, const char *buttons) +RAYGUIDEF int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, const char *buttons, char *text) { #define TEXTINPUTBOX_BUTTON_HEIGHT 24 #define TEXTINPUTBOX_BUTTON_PADDING 10 @@ -3816,16 +3816,40 @@ RAYGUIDEF int GuiTextInputBox(Rectangle bounds, const char *windowTitle, const c buttonBounds.y = bounds.y + bounds.height - TEXTINPUTBOX_BUTTON_HEIGHT - TEXTINPUTBOX_BUTTON_PADDING; buttonBounds.width = (bounds.width - TEXTINPUTBOX_BUTTON_PADDING*(buttonsCount + 1))/buttonsCount; buttonBounds.height = TEXTINPUTBOX_BUTTON_HEIGHT; + + int messageInputHeight = bounds.height - WINDOW_STATUSBAR_HEIGHT - GuiGetStyle(STATUSBAR, BORDER_WIDTH) - TEXTINPUTBOX_BUTTON_HEIGHT - 2*TEXTINPUTBOX_BUTTON_PADDING; + + Rectangle textBounds = { 0 }; + if (message != NULL) + { + Vector2 textSize = MeasureTextEx(guiFont, message, GuiGetStyle(DEFAULT, TEXT_SIZE), 1); + + textBounds.x = bounds.x + bounds.width/2 - textSize.x/2; + textBounds.y = bounds.y + WINDOW_STATUSBAR_HEIGHT + messageInputHeight/4 - textSize.y/2; + textBounds.width = textSize.x; + textBounds.height = textSize.y; + } Rectangle textBoxBounds = { 0 }; textBoxBounds.x = bounds.x + TEXTINPUTBOX_BUTTON_PADDING; - textBoxBounds.y = bounds.y + WINDOW_STATUSBAR_HEIGHT + (bounds.height - WINDOW_STATUSBAR_HEIGHT - TEXTINPUTBOX_BUTTON_HEIGHT - TEXTINPUTBOX_BUTTON_PADDING)/2 - TEXTINPUTBOX_HEIGHT/2; + textBoxBounds.y = bounds.y + WINDOW_STATUSBAR_HEIGHT - TEXTINPUTBOX_HEIGHT/2; + if (message == NULL) textBoxBounds.y += messageInputHeight/2; + else textBoxBounds.y += (messageInputHeight/2 + messageInputHeight/4); textBoxBounds.width = bounds.width - TEXTINPUTBOX_BUTTON_PADDING*2; textBoxBounds.height = TEXTINPUTBOX_HEIGHT; // Draw control //-------------------------------------------------------------------- - if (GuiWindowBox(bounds, windowTitle)) btnIndex = 0; + if (GuiWindowBox(bounds, title)) btnIndex = 0; + + // Draw message if available + if (message != NULL) + { + int prevTextAlignment = GuiGetStyle(LABEL, TEXT_ALIGNMENT); + GuiSetStyle(LABEL, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_CENTER); + GuiLabel(textBounds, message); + GuiSetStyle(LABEL, TEXT_ALIGNMENT, prevTextAlignment); + } if (GuiTextBox(textBoxBounds, text, MAX_FILENAME_LENGTH, textEditMode)) textEditMode = !textEditMode;