Return false to discard a character.
| 3768 | |
| 3769 | // Return false to discard a character. |
| 3770 | static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data, ImGuiInputSource input_source) |
| 3771 | { |
| 3772 | IM_ASSERT(input_source == ImGuiInputSource_Keyboard || input_source == ImGuiInputSource_Clipboard); |
| 3773 | unsigned int c = *p_char; |
| 3774 | |
| 3775 | // Filter non-printable (NB: isprint is unreliable! see #2467) |
| 3776 | if (c < 0x20) |
| 3777 | { |
| 3778 | bool pass = false; |
| 3779 | pass |= (c == '\n' && (flags & ImGuiInputTextFlags_Multiline)); |
| 3780 | pass |= (c == '\t' && (flags & ImGuiInputTextFlags_AllowTabInput)); |
| 3781 | if (!pass) |
| 3782 | return false; |
| 3783 | } |
| 3784 | |
| 3785 | if (input_source != ImGuiInputSource_Clipboard) |
| 3786 | { |
| 3787 | // We ignore Ascii representation of delete (emitted from Backspace on OSX, see #2578, #2817) |
| 3788 | if (c == 127) |
| 3789 | return false; |
| 3790 | |
| 3791 | // Filter private Unicode range. GLFW on OSX seems to send private characters for special keys like arrow keys (FIXME) |
| 3792 | if (c >= 0xE000 && c <= 0xF8FF) |
| 3793 | return false; |
| 3794 | } |
| 3795 | |
| 3796 | // Filter Unicode ranges we are not handling in this build |
| 3797 | if (c > IM_UNICODE_CODEPOINT_MAX) |
| 3798 | return false; |
| 3799 | |
| 3800 | // Generic named filters |
| 3801 | if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank | ImGuiInputTextFlags_CharsScientific)) |
| 3802 | { |
| 3803 | // The libc allows overriding locale, with e.g. 'setlocale(LC_NUMERIC, "de_DE.UTF-8");' which affect the output/input of printf/scanf. |
| 3804 | // The standard mandate that programs starts in the "C" locale where the decimal point is '.'. |
| 3805 | // 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. |
| 3806 | // Change the default decimal_point with: |
| 3807 | // ImGui::GetCurrentContext()->PlatformLocaleDecimalPoint = *localeconv()->decimal_point; |
| 3808 | ImGuiContext& g = *GImGui; |
| 3809 | const unsigned c_decimal_point = (unsigned int)g.PlatformLocaleDecimalPoint; |
| 3810 | |
| 3811 | // Allow 0-9 . - + * / |
| 3812 | if (flags & ImGuiInputTextFlags_CharsDecimal) |
| 3813 | if (!(c >= '0' && c <= '9') && (c != c_decimal_point) && (c != '-') && (c != '+') && (c != '*') && (c != '/')) |
| 3814 | return false; |
| 3815 | |
| 3816 | // Allow 0-9 . - + * / e E |
| 3817 | if (flags & ImGuiInputTextFlags_CharsScientific) |
| 3818 | if (!(c >= '0' && c <= '9') && (c != c_decimal_point) && (c != '-') && (c != '+') && (c != '*') && (c != '/') && (c != 'e') && (c != 'E')) |
| 3819 | return false; |
| 3820 | |
| 3821 | // Allow 0-9 a-F A-F |
| 3822 | if (flags & ImGuiInputTextFlags_CharsHexadecimal) |
| 3823 | if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F')) |
| 3824 | return false; |
| 3825 | |
| 3826 | // Turn a-z into A-Z |
| 3827 | if (flags & ImGuiInputTextFlags_CharsUppercase) |
no test coverage detected