mirror of
https://github.com/raysan5/raygui.git
synced 2026-02-04 21:29:18 -05:00
REDESIGNED: GuiTextInputBox()
Support text message (if provided).
This commit is contained in:
@ -204,7 +204,7 @@ int main()
|
|||||||
if (showTextInputBox)
|
if (showTextInputBox)
|
||||||
{
|
{
|
||||||
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, 0.8f));
|
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)
|
if (result == 1)
|
||||||
{
|
{
|
||||||
|
|||||||
50
src/raygui.h
50
src/raygui.h
@ -408,8 +408,8 @@ RAYGUIDEF int GuiTextBoxGetByteIndex(const char *text, int start, int from, int
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Container/separator controls, useful for controls organization
|
// 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 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 title name
|
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 GuiLine(Rectangle bounds, const char *text); // Line separator control, could contain text
|
||||||
RAYGUIDEF void GuiPanel(Rectangle bounds); // Panel control, useful to group controls
|
RAYGUIDEF void GuiPanel(Rectangle bounds); // Panel control, useful to group controls
|
||||||
RAYGUIDEF Rectangle GuiScrollPanel(Rectangle bounds, Rectangle content, Vector2 *scroll); // Scroll Panel control
|
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
|
// 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 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 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 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 *windowTitle, const char *message, char *text, const char *buttons); // Text Input Box control, ask for text
|
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
|
RAYGUIDEF Color GuiColorPicker(Rectangle bounds, Color color); // Color Picker control
|
||||||
|
|
||||||
// Styles loading functions
|
// Styles loading functions
|
||||||
@ -833,7 +833,7 @@ RAYGUIDEF void GuiTextBoxSetState(GuiTextBoxState state)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Window Box control
|
// 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()
|
// NOTE: This define is also used by GuiMessageBox() and GuiTextInputBox()
|
||||||
#define WINDOW_STATUSBAR_HEIGHT 22
|
#define WINDOW_STATUSBAR_HEIGHT 22
|
||||||
@ -865,7 +865,7 @@ RAYGUIDEF bool GuiWindowBox(Rectangle bounds, const char *text)
|
|||||||
Fade(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)), guiAlpha));
|
Fade(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)), guiAlpha));
|
||||||
|
|
||||||
// Draw window header as status bar
|
// Draw window header as status bar
|
||||||
GuiStatusBar(statusBar, text);
|
GuiStatusBar(statusBar, title);
|
||||||
|
|
||||||
// Draw window close button
|
// Draw window close button
|
||||||
int tempBorderWidth = GuiGetStyle(BUTTON, BORDER_WIDTH);
|
int tempBorderWidth = GuiGetStyle(BUTTON, BORDER_WIDTH);
|
||||||
@ -884,7 +884,7 @@ RAYGUIDEF bool GuiWindowBox(Rectangle bounds, const char *text)
|
|||||||
return clicked;
|
return clicked;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Group Box control with title name
|
// Group Box control with text name
|
||||||
RAYGUIDEF void GuiGroupBox(Rectangle bounds, const char *text)
|
RAYGUIDEF void GuiGroupBox(Rectangle bounds, const char *text)
|
||||||
{
|
{
|
||||||
#define GROUPBOX_LINE_THICK 1
|
#define GROUPBOX_LINE_THICK 1
|
||||||
@ -3747,7 +3747,7 @@ RAYGUIDEF Color GuiColorPicker(Rectangle bounds, Color color)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Message Box control
|
// 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_HEIGHT 24
|
||||||
#define MESSAGEBOX_BUTTON_PADDING 10
|
#define MESSAGEBOX_BUTTON_PADDING 10
|
||||||
@ -3772,7 +3772,7 @@ RAYGUIDEF int GuiMessageBox(Rectangle bounds, const char *windowTitle, const cha
|
|||||||
|
|
||||||
// Draw control
|
// Draw control
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
if (GuiWindowBox(bounds, windowTitle)) clicked = 0;
|
if (GuiWindowBox(bounds, title)) clicked = 0;
|
||||||
|
|
||||||
int prevTextAlignment = GuiGetStyle(LABEL, TEXT_ALIGNMENT);
|
int prevTextAlignment = GuiGetStyle(LABEL, TEXT_ALIGNMENT);
|
||||||
GuiSetStyle(LABEL, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_CENTER);
|
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
|
// 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_HEIGHT 24
|
||||||
#define TEXTINPUTBOX_BUTTON_PADDING 10
|
#define TEXTINPUTBOX_BUTTON_PADDING 10
|
||||||
@ -3817,15 +3817,39 @@ RAYGUIDEF int GuiTextInputBox(Rectangle bounds, const char *windowTitle, const c
|
|||||||
buttonBounds.width = (bounds.width - TEXTINPUTBOX_BUTTON_PADDING*(buttonsCount + 1))/buttonsCount;
|
buttonBounds.width = (bounds.width - TEXTINPUTBOX_BUTTON_PADDING*(buttonsCount + 1))/buttonsCount;
|
||||||
buttonBounds.height = TEXTINPUTBOX_BUTTON_HEIGHT;
|
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 };
|
Rectangle textBoxBounds = { 0 };
|
||||||
textBoxBounds.x = bounds.x + TEXTINPUTBOX_BUTTON_PADDING;
|
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.width = bounds.width - TEXTINPUTBOX_BUTTON_PADDING*2;
|
||||||
textBoxBounds.height = TEXTINPUTBOX_HEIGHT;
|
textBoxBounds.height = TEXTINPUTBOX_HEIGHT;
|
||||||
|
|
||||||
// Draw control
|
// 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;
|
if (GuiTextBox(textBoxBounds, text, MAX_FILENAME_LENGTH, textEditMode)) textEditMode = !textEditMode;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user