From 78cd3d650d3324f14d6fc7184ecb91e55410d775 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 1 Mar 2022 22:13:05 +0100 Subject: [PATCH] REVIEWED: `GuiTextinputBox()` to support secret text --- src/raygui.h | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/raygui.h b/src/raygui.h index e2ace47..c331a64 100644 --- a/src/raygui.h +++ b/src/raygui.h @@ -529,7 +529,7 @@ RAYGUIAPI Vector2 GuiGrid(Rectangle bounds, const char *text, float spacing, int RAYGUIAPI int GuiListView(Rectangle bounds, const char *text, int *scrollIndex, int active); // List View control, returns selected list item index RAYGUIAPI int GuiListViewEx(Rectangle bounds, const char **text, int count, int *focus, int *scrollIndex, int active); // List View with extended parameters RAYGUIAPI int GuiMessageBox(Rectangle bounds, const char *title, const char *message, const char *buttons); // Message Box control, displays a message -RAYGUIAPI int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, const char *buttons, char *text); // Text Input Box control, ask for text +RAYGUIAPI int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, const char *buttons, char *text, bool secret); // Text Input Box control, ask for text, supports secret RAYGUIAPI Color GuiColorPicker(Rectangle bounds, const char *text, Color color); // Color Picker control (multiple color controls) RAYGUIAPI Color GuiColorPanel(Rectangle bounds, const char *text, Color color); // Color Panel control RAYGUIAPI float GuiColorBarAlpha(Rectangle bounds, const char *text, float alpha); // Color Bar Alpha control @@ -3083,16 +3083,16 @@ int GuiMessageBox(Rectangle bounds, const char *title, const char *message, cons } // Text Input Box control, ask for text -int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, const char *buttons, char *text) +int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, const char *buttons, char *text, int *secretViewActive) { #if !defined(RAYGUI_TEXTINPUTBOX_BUTTON_HEIGHT) - #define RAYGUI_TEXTINPUTBOX_BUTTON_HEIGHT 24 + #define RAYGUI_TEXTINPUTBOX_BUTTON_HEIGHT 28 #endif #if !defined(RAYGUI_TEXTINPUTBOX_BUTTON_PADDING) - #define RAYGUI_TEXTINPUTBOX_BUTTON_PADDING 10 + #define RAYGUI_TEXTINPUTBOX_BUTTON_PADDING 12 #endif #if !defined(RAYGUI_TEXTINPUTBOX_HEIGHT) - #define RAYGUI_TEXTINPUTBOX_HEIGHT 24 + #define RAYGUI_TEXTINPUTBOX_HEIGHT 28 #endif #if !defined(RAYGUI_TEXTINPUTBOX_MAX_TEXT_LENGTH) #define RAYGUI_TEXTINPUTBOX_MAX_TEXT_LENGTH 256 @@ -3146,7 +3146,17 @@ int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, co GuiSetStyle(LABEL, TEXT_ALIGNMENT, prevTextAlignment); } - if (GuiTextBox(textBoxBounds, text, RAYGUI_TEXTINPUTBOX_MAX_TEXT_LENGTH, textEditMode)) textEditMode = !textEditMode; + if (secretViewActive != NULL) + { + if (GuiTextBox((Rectangle){ textBoxBounds.x, textBoxBounds.y, textBoxBounds.width - 4 - RAYGUI_TEXTINPUTBOX_HEIGHT, textBoxBounds.height }, + ((*secretViewActive == 1) || textEditMode)? text : "****************", RAYGUI_TEXTINPUTBOX_MAX_TEXT_LENGTH, textEditMode)) textEditMode = !textEditMode; + + *secretViewActive = GuiToggle((Rectangle){ textBoxBounds.x + textBoxBounds.width - RAYGUI_TEXTINPUTBOX_HEIGHT, textBoxBounds.y, RAYGUI_TEXTINPUTBOX_HEIGHT, RAYGUI_TEXTINPUTBOX_HEIGHT }, (*secretViewActive == 1)? "#44#" : "#45#", *secretViewActive); + } + else + { + if (GuiTextBox(textBoxBounds, text, RAYGUI_TEXTINPUTBOX_MAX_TEXT_LENGTH, textEditMode)) textEditMode = !textEditMode; + } int prevBtnTextAlignment = GuiGetStyle(BUTTON, TEXT_ALIGNMENT); GuiSetStyle(BUTTON, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_CENTER);