From b73484a66b10e813321b25f8a7f46ac20fb21980 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 11 Feb 2015 17:46:16 +0000 Subject: [PATCH] Added ImGuiInputTextFlags_CharsUppercase stock filter --- imgui.cpp | 28 ++++++++-------------------- imgui.h | 13 +++++++------ 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index cb994ecbd..e6997fb2b 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5243,6 +5243,10 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F')) return false; + if (flags & ImGuiInputTextFlags_CharsUppercase) + if (c >= 'a' && c <= 'z') + *p_char = (c += 'A'-'a'); + if (flags & ImGuiInputTextFlags_CallbackCharFilter) { ImGuiTextEditCallbackData callback_data; @@ -8346,26 +8350,10 @@ void ImGui::ShowTestWindow(bool* opened) { static char buf1[64] = ""; ImGui::InputText("default", buf1, 64); static char buf2[64] = ""; ImGui::InputText("decimal", buf2, 64, ImGuiInputTextFlags_CharsDecimal); - static char buf3[64] = ""; ImGui::InputText("hexadecimal", buf3, 64, ImGuiInputTextFlags_CharsHexadecimal); - struct TextFilters - { - static int FilterAZ(ImGuiTextEditCallbackData* data) - { - const ImWchar c = data->EventChar; - if (!((c >= 'a' && c <= 'z') || c >= 'A' && c <= 'Z')) - data->EventChar = 0; - return 0; - } - static int FilterUppercase(ImGuiTextEditCallbackData* data) - { - const ImWchar c = data->EventChar; - if (c >= 'a' && c <= 'z') - data->EventChar += 'A'-'a'; - return 0; - } - }; - static char buf4[64] = ""; ImGui::InputText("a-z only", buf4, 64, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterAZ); - static char buf5[64] = ""; ImGui::InputText("uppercase", buf5, 64, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterUppercase); + static char buf3[64] = ""; ImGui::InputText("hexadecimal", buf3, 64, ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase); + static char buf4[64] = ""; ImGui::InputText("uppercase", buf4, 64, ImGuiInputTextFlags_CharsUppercase); + struct TextFilters { static int FilterNoSpace(ImGuiTextEditCallbackData* data) { if (data->EventChar == ' ') data->EventChar = 0; return 0; } }; + static char buf5[64] = ""; ImGui::InputText("custom: no spaces", buf5, 64, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterNoSpace); ImGui::TreePop(); } diff --git a/imgui.h b/imgui.h index ef592a037..aef6204c1 100644 --- a/imgui.h +++ b/imgui.h @@ -388,12 +388,13 @@ enum ImGuiInputTextFlags_ // Default: 0 ImGuiInputTextFlags_CharsDecimal = 1 << 0, // Allow 0123456789.+-*/ ImGuiInputTextFlags_CharsHexadecimal = 1 << 1, // Allow 0123456789ABCDEFabcdef - ImGuiInputTextFlags_AutoSelectAll = 1 << 2, // Select entire text when first taking focus - ImGuiInputTextFlags_EnterReturnsTrue = 1 << 3, // Return 'true' when Enter is pressed (as opposed to when the value was modified) - ImGuiInputTextFlags_CallbackCompletion = 1 << 4, // Call user function on pressing TAB (for completion handling) - ImGuiInputTextFlags_CallbackHistory = 1 << 5, // Call user function on pressing Up/Down arrows (for history handling) - ImGuiInputTextFlags_CallbackAlways = 1 << 6, // Call user function every time - ImGuiInputTextFlags_CallbackCharFilter = 1 << 7 // Call user function to filter character. Modify data->EventChar to replace/filter input. + ImGuiInputTextFlags_CharsUppercase = 1 << 2, // Turn a..z into A..Z + ImGuiInputTextFlags_AutoSelectAll = 1 << 3, // Select entire text when first taking focus + ImGuiInputTextFlags_EnterReturnsTrue = 1 << 4, // Return 'true' when Enter is pressed (as opposed to when the value was modified) + ImGuiInputTextFlags_CallbackCompletion = 1 << 5, // Call user function on pressing TAB (for completion handling) + ImGuiInputTextFlags_CallbackHistory = 1 << 6, // Call user function on pressing Up/Down arrows (for history handling) + ImGuiInputTextFlags_CallbackAlways = 1 << 7, // Call user function every time + ImGuiInputTextFlags_CallbackCharFilter = 1 << 8 // Call user function to filter character. Modify data->EventChar to replace/filter input. //ImGuiInputTextFlags_AlignCenter = 1 << 6, };