Added ImGuiInputTextFlags_CharsNoBlank stock filter. Tweak examples.

This commit is contained in:
ocornut 2015-02-11 18:01:32 +00:00
parent 2df4735904
commit a597664672
2 changed files with 26 additions and 17 deletions

View File

@ -5235,6 +5235,8 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f
if (c >= 0xE000 && c <= 0xF8FF) // Filter private Unicode range. I don't imagine anybody would want to input them. GLFW on OSX seems to send private characters for special keys like arrow keys. if (c >= 0xE000 && c <= 0xF8FF) // Filter private Unicode range. I don't imagine anybody would want to input them. GLFW on OSX seems to send private characters for special keys like arrow keys.
return false; return false;
if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank))
{
if (flags & ImGuiInputTextFlags_CharsDecimal) if (flags & ImGuiInputTextFlags_CharsDecimal)
if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/')) if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/'))
return false; return false;
@ -5247,6 +5249,11 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f
if (c >= 'a' && c <= 'z') if (c >= 'a' && c <= 'z')
*p_char = (c += 'A'-'a'); *p_char = (c += 'A'-'a');
if (flags & ImGuiInputTextFlags_CharsNoBlank)
if (c == ' ' || c == '\t')
return false;
}
if (flags & ImGuiInputTextFlags_CallbackCharFilter) if (flags & ImGuiInputTextFlags_CallbackCharFilter)
{ {
ImGuiTextEditCallbackData callback_data; ImGuiTextEditCallbackData callback_data;
@ -8353,8 +8360,9 @@ void ImGui::ShowTestWindow(bool* opened)
static char buf2[64] = ""; ImGui::InputText("decimal", buf2, 64, ImGuiInputTextFlags_CharsDecimal); 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 buf3[64] = ""; ImGui::InputText("hexadecimal", buf3, 64, ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase);
static char buf4[64] = ""; ImGui::InputText("uppercase", buf4, 64, ImGuiInputTextFlags_CharsUppercase); static char buf4[64] = ""; ImGui::InputText("uppercase", buf4, 64, ImGuiInputTextFlags_CharsUppercase);
struct TextFilters { static int FilterNoSpace(ImGuiTextEditCallbackData* data) { if (data->EventChar == ' ') return 1; return 0; } }; static char buf5[64] = ""; ImGui::InputText("no blank", buf5, 64, ImGuiInputTextFlags_CharsNoBlank);
static char buf5[64] = ""; ImGui::InputText("custom: no spaces", buf5, 64, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterNoSpace); struct TextFilters { static int FilterImGuiLetters(ImGuiTextEditCallbackData* data) { if (data->EventChar < 256 && strchr("imgui", (char)data->EventChar)) return 0; return 1; } };
static char buf6[64] = ""; ImGui::InputText("\"imgui\" letters", buf6, 64, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterImGuiLetters);
ImGui::TreePop(); ImGui::TreePop();
} }

13
imgui.h
View File

@ -389,12 +389,13 @@ enum ImGuiInputTextFlags_
ImGuiInputTextFlags_CharsDecimal = 1 << 0, // Allow 0123456789.+-*/ ImGuiInputTextFlags_CharsDecimal = 1 << 0, // Allow 0123456789.+-*/
ImGuiInputTextFlags_CharsHexadecimal = 1 << 1, // Allow 0123456789ABCDEFabcdef ImGuiInputTextFlags_CharsHexadecimal = 1 << 1, // Allow 0123456789ABCDEFabcdef
ImGuiInputTextFlags_CharsUppercase = 1 << 2, // Turn a..z into A..Z ImGuiInputTextFlags_CharsUppercase = 1 << 2, // Turn a..z into A..Z
ImGuiInputTextFlags_AutoSelectAll = 1 << 3, // Select entire text when first taking focus ImGuiInputTextFlags_CharsNoBlank = 1 << 3, // Filter out spaces, tabs
ImGuiInputTextFlags_EnterReturnsTrue = 1 << 4, // Return 'true' when Enter is pressed (as opposed to when the value was modified) ImGuiInputTextFlags_AutoSelectAll = 1 << 4, // Select entire text when first taking focus
ImGuiInputTextFlags_CallbackCompletion = 1 << 5, // Call user function on pressing TAB (for completion handling) ImGuiInputTextFlags_EnterReturnsTrue = 1 << 5, // Return 'true' when Enter is pressed (as opposed to when the value was modified)
ImGuiInputTextFlags_CallbackHistory = 1 << 6, // Call user function on pressing Up/Down arrows (for history handling) ImGuiInputTextFlags_CallbackCompletion = 1 << 6, // Call user function on pressing TAB (for completion handling)
ImGuiInputTextFlags_CallbackAlways = 1 << 7, // Call user function every time ImGuiInputTextFlags_CallbackHistory = 1 << 7, // Call user function on pressing Up/Down arrows (for history handling)
ImGuiInputTextFlags_CallbackCharFilter = 1 << 8 // Call user function to filter character. Modify data->EventChar to replace/filter input, or return 1 to discard character. ImGuiInputTextFlags_CallbackAlways = 1 << 8, // Call user function every time
ImGuiInputTextFlags_CallbackCharFilter = 1 << 9 // Call user function to filter character. Modify data->EventChar to replace/filter input, or return 1 to discard character.
//ImGuiInputTextFlags_AlignCenter = 1 << 6, //ImGuiInputTextFlags_AlignCenter = 1 << 6,
}; };