Return false to discard a character.
| 3701 | |
| 3702 | // Return false to discard a character. |
| 3703 | static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data) |
| 3704 | { |
| 3705 | unsigned int c = *p_char; |
| 3706 | |
| 3707 | // Filter non-printable (NB: isprint is unreliable! see #2467) |
| 3708 | if (c < 0x20) |
| 3709 | { |
| 3710 | bool pass = false; |
| 3711 | pass |= (c == '\n' && (flags & ImGuiInputTextFlags_Multiline)); |
| 3712 | pass |= (c == '\t' && (flags & ImGuiInputTextFlags_AllowTabInput)); |
| 3713 | if (!pass) |
| 3714 | return false; |
| 3715 | } |
| 3716 | |
| 3717 | // We ignore Ascii representation of delete (emitted from Backspace on OSX, see #2578, #2817) |
| 3718 | if (c == 127) |
| 3719 | return false; |
| 3720 | |
| 3721 | // Filter private Unicode range. GLFW on OSX seems to send private characters for special keys like arrow keys (FIXME) |
| 3722 | if (c >= 0xE000 && c <= 0xF8FF) |
| 3723 | return false; |
| 3724 | |
| 3725 | // Filter Unicode ranges we are not handling in this build. |
| 3726 | if (c > IM_UNICODE_CODEPOINT_MAX) |
| 3727 | return false; |
| 3728 | |
| 3729 | // Generic named filters |
| 3730 | if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank | ImGuiInputTextFlags_CharsScientific)) |
| 3731 | { |
| 3732 | // The libc allows overriding locale, with e.g. 'setlocale(LC_NUMERIC, "de_DE.UTF-8");' which affect the output/input of printf/scanf. |
| 3733 | // The standard mandate that programs starts in the "C" locale where the decimal point is '.'. |
| 3734 | // We don't really intend to provide widespread support for it, but out of empathy for people stuck with using odd API, we support the bare minimum aka overriding the decimal point. |
| 3735 | // Change the default decimal_point with: |
| 3736 | // ImGui::GetCurrentContext()->PlatformLocaleDecimalPoint = *localeconv()->decimal_point; |
| 3737 | ImGuiContext& g = *GImGui; |
| 3738 | const unsigned c_decimal_point = (unsigned int)g.PlatformLocaleDecimalPoint; |
| 3739 | |
| 3740 | // Allow 0-9 . - + * / |
| 3741 | if (flags & ImGuiInputTextFlags_CharsDecimal) |
| 3742 | if (!(c >= '0' && c <= '9') && (c != c_decimal_point) && (c != '-') && (c != '+') && (c != '*') && (c != '/')) |
| 3743 | return false; |
| 3744 | |
| 3745 | // Allow 0-9 . - + * / e E |
| 3746 | if (flags & ImGuiInputTextFlags_CharsScientific) |
| 3747 | if (!(c >= '0' && c <= '9') && (c != c_decimal_point) && (c != '-') && (c != '+') && (c != '*') && (c != '/') && (c != 'e') && (c != 'E')) |
| 3748 | return false; |
| 3749 | |
| 3750 | // Allow 0-9 a-F A-F |
| 3751 | if (flags & ImGuiInputTextFlags_CharsHexadecimal) |
| 3752 | if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F')) |
| 3753 | return false; |
| 3754 | |
| 3755 | // Turn a-z into A-Z |
| 3756 | if (flags & ImGuiInputTextFlags_CharsUppercase) |
| 3757 | if (c >= 'a' && c <= 'z') |
| 3758 | *p_char = (c += (unsigned int)('A' - 'a')); |
| 3759 | |
| 3760 | if (flags & ImGuiInputTextFlags_CharsNoBlank) |
no test coverage detected