MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / InputTextFilterCharacter

Function InputTextFilterCharacter

lib/imgui/imgui_widgets.cpp:3361–3428  ·  view source on GitHub ↗

Return false to discard a character.

Source from the content-addressed store, hash-verified

3359
3360// Return false to discard a character.
3361static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data)
3362{
3363 unsigned int c = *p_char;
3364
3365 // Filter non-printable (NB: isprint is unreliable! see #2467)
3366 if (c < 0x20)
3367 {
3368 bool pass = false;
3369 pass |= (c == '\n' && (flags & ImGuiInputTextFlags_Multiline));
3370 pass |= (c == '\t' && (flags & ImGuiInputTextFlags_AllowTabInput));
3371 if (!pass)
3372 return false;
3373 }
3374
3375 // We ignore Ascii representation of delete (emitted from Backspace on OSX, see #2578, #2817)
3376 if (c == 127)
3377 return false;
3378
3379 // Filter private Unicode range. GLFW on OSX seems to send private characters for special keys like arrow keys (FIXME)
3380 if (c >= 0xE000 && c <= 0xF8FF)
3381 return false;
3382
3383 // Filter Unicode ranges we are not handling in this build.
3384 if (c > IM_UNICODE_CODEPOINT_MAX)
3385 return false;
3386
3387 // Generic named filters
3388 if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank | ImGuiInputTextFlags_CharsScientific))
3389 {
3390 if (flags & ImGuiInputTextFlags_CharsDecimal)
3391 if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/'))
3392 return false;
3393
3394 if (flags & ImGuiInputTextFlags_CharsScientific)
3395 if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/') && (c != 'e') && (c != 'E'))
3396 return false;
3397
3398 if (flags & ImGuiInputTextFlags_CharsHexadecimal)
3399 if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F'))
3400 return false;
3401
3402 if (flags & ImGuiInputTextFlags_CharsUppercase)
3403 if (c >= 'a' && c <= 'z')
3404 *p_char = (c += (unsigned int)('A'-'a'));
3405
3406 if (flags & ImGuiInputTextFlags_CharsNoBlank)
3407 if (ImCharIsBlankW(c))
3408 return false;
3409 }
3410
3411 // Custom callback filter
3412 if (flags & ImGuiInputTextFlags_CallbackCharFilter)
3413 {
3414 ImGuiInputTextCallbackData callback_data;
3415 memset(&callback_data, 0, sizeof(ImGuiInputTextCallbackData));
3416 callback_data.EventFlag = ImGuiInputTextFlags_CallbackCharFilter;
3417 callback_data.EventChar = (ImWchar)c;
3418 callback_data.Flags = flags;

Callers 1

InputTextExMethod · 0.85

Calls 2

ImCharIsBlankWFunction · 0.85
callbackFunction · 0.85

Tested by

no test coverage detected