From 013f1a27725023aa4202f4882d20a819daf73269 Mon Sep 17 00:00:00 2001 From: gulrak Date: Sun, 29 May 2022 17:26:08 +0200 Subject: [PATCH] add distinct icon-only buffer for internal use (#208) --- examples/controls_test_suite/controls_test_suite.c | 2 +- src/raygui.h | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/examples/controls_test_suite/controls_test_suite.c b/examples/controls_test_suite/controls_test_suite.c index 9b1ffc4..ba5209a 100644 --- a/examples/controls_test_suite/controls_test_suite.c +++ b/examples/controls_test_suite/controls_test_suite.c @@ -219,7 +219,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, 140 }, "Save", GuiIconText(ICON_FILE_SAVE, "Save file as..."), "Introduce a save file name", "Ok;Cancel", textInput, NULL); + int result = GuiTextInputBox((Rectangle){ GetScreenWidth()/2 - 120, GetScreenHeight()/2 - 60, 240, 140 }, "Save", GuiIconText(ICON_FILE_SAVE, "Save file as..."), "Ok;Cancel", textInput, 255, NULL); if (result == 1) { diff --git a/src/raygui.h b/src/raygui.h index dafe437..2ab71f1 100644 --- a/src/raygui.h +++ b/src/raygui.h @@ -3546,20 +3546,23 @@ const char *GuiIconText(int iconId, const char *text) return NULL; #else static char buffer[1024] = { 0 }; - memset(buffer, 0, 1024); - - sprintf(buffer, "#%03i#", iconId); + static char iconBuffer[6] = {0}; if (text != NULL) { + memset(buffer, 0, 1024); + sprintf(buffer, "#%03i#", iconId); for (int i = 5; i < 1024; i++) { buffer[i] = text[i - 5]; if (text[i - 5] == '\0') break; } - } - return buffer; + } + else { + sprintf(iconBuffer, "#%03i#", iconId&0x1ff); + return iconBuffer; + } #endif }