Return false to discard a character.
| 3319 | |
| 3320 | // Return false to discard a character. |
| 3321 | static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data) |
| 3322 | { |
| 3323 | unsigned int c = *p_char; |
| 3324 | |
| 3325 | // Filter non-printable (NB: isprint is unreliable! see #2467) |
| 3326 | if (c < 0x20) |
| 3327 | { |
| 3328 | bool pass = false; |
| 3329 | pass |= (c == '\n' && (flags & ImGuiInputTextFlags_Multiline)); |
| 3330 | pass |= (c == '\t' && (flags & ImGuiInputTextFlags_AllowTabInput)); |
| 3331 | if (!pass) |
| 3332 | return false; |
| 3333 | } |
| 3334 | |
| 3335 | // Filter private Unicode range. GLFW on OSX seems to send private characters for special keys like arrow keys (FIXME) |
| 3336 | if (c >= 0xE000 && c <= 0xF8FF) |
| 3337 | return false; |
| 3338 | |
| 3339 | // Generic named filters |
| 3340 | if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank | ImGuiInputTextFlags_CharsScientific)) |
| 3341 | { |
| 3342 | if (flags & ImGuiInputTextFlags_CharsDecimal) |
| 3343 | if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/')) |
| 3344 | return false; |
| 3345 | |
| 3346 | if (flags & ImGuiInputTextFlags_CharsScientific) |
| 3347 | if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/') && (c != 'e') && (c != 'E')) |
| 3348 | return false; |
| 3349 | |
| 3350 | if (flags & ImGuiInputTextFlags_CharsHexadecimal) |
| 3351 | if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F')) |
| 3352 | return false; |
| 3353 | |
| 3354 | if (flags & ImGuiInputTextFlags_CharsUppercase) |
| 3355 | if (c >= 'a' && c <= 'z') |
| 3356 | *p_char = (c += (unsigned int)('A'-'a')); |
| 3357 | |
| 3358 | if (flags & ImGuiInputTextFlags_CharsNoBlank) |
| 3359 | if (ImCharIsBlankW(c)) |
| 3360 | return false; |
| 3361 | } |
| 3362 | |
| 3363 | // Custom callback filter |
| 3364 | if (flags & ImGuiInputTextFlags_CallbackCharFilter) |
| 3365 | { |
| 3366 | ImGuiInputTextCallbackData callback_data; |
| 3367 | memset(&callback_data, 0, sizeof(ImGuiInputTextCallbackData)); |
| 3368 | callback_data.EventFlag = ImGuiInputTextFlags_CallbackCharFilter; |
| 3369 | callback_data.EventChar = (ImWchar)c; |
| 3370 | callback_data.Flags = flags; |
| 3371 | callback_data.UserData = user_data; |
| 3372 | if (callback(&callback_data) != 0) |
| 3373 | return false; |
| 3374 | *p_char = callback_data.EventChar; |
| 3375 | if (!callback_data.EventChar) |
| 3376 | return false; |
| 3377 | } |
| 3378 |
no test coverage detected