From 2df4735904e021ee5891af05f951b696a35a2b42 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 11 Feb 2015 17:55:26 +0000 Subject: [PATCH] ImGuiInputTextFlags_CallbackCharFilter can return 1 to filter character --- imgui.cpp | 5 +++-- imgui.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index e6997fb2b..eb65beda1 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5255,7 +5255,8 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f callback_data.EventChar = c; callback_data.Flags = flags; callback_data.UserData = user_data; - callback(&callback_data); + if (callback(&callback_data) != 0) + return false; *p_char = callback_data.EventChar; if (!callback_data.EventChar) return false; @@ -8352,7 +8353,7 @@ void ImGui::ShowTestWindow(bool* opened) static char buf2[64] = ""; ImGui::InputText("decimal", buf2, 64, ImGuiInputTextFlags_CharsDecimal); 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; } }; + struct TextFilters { static int FilterNoSpace(ImGuiTextEditCallbackData* data) { if (data->EventChar == ' ') return 1; 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 aef6204c1..94712b3c6 100644 --- a/imgui.h +++ b/imgui.h @@ -394,7 +394,7 @@ enum ImGuiInputTextFlags_ 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_CallbackCharFilter = 1 << 8 // Call user function to filter character. Modify data->EventChar to replace/filter input, or return 1 to discard character. //ImGuiInputTextFlags_AlignCenter = 1 << 6, };