1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-24 15:50:25 +01:00

ImGuiInputTextFlags_CallbackCharFilter can return 1 to filter character

This commit is contained in:
ocornut 2015-02-11 17:55:26 +00:00
parent b73484a66b
commit 2df4735904
2 changed files with 4 additions and 3 deletions

View File

@ -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();
}

View File

@ -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,
};