| 3738 | //----------------------------------------------------------------------------- |
| 3739 | |
| 3740 | static void DemoWindowWidgetsTextInput() |
| 3741 | { |
| 3742 | // To wire InputText() with std::string or any other custom string type, |
| 3743 | // see the "Text Input > Resize Callback" section of this demo, and the misc/cpp/imgui_stdlib.h file. |
| 3744 | if (ImGui::TreeNode("Text Input")) |
| 3745 | { |
| 3746 | IMGUI_DEMO_MARKER("Widgets/Text Input"); |
| 3747 | if (ImGui::TreeNode("Multi-line Text Input")) |
| 3748 | { |
| 3749 | IMGUI_DEMO_MARKER("Widgets/Text Input/Multi-line Text Input"); |
| 3750 | // WE ARE USING A FIXED-SIZE BUFFER FOR SIMPLICITY HERE. |
| 3751 | // If you want to use InputText() with std::string or any custom dynamic string type: |
| 3752 | // - For std::string: use the wrapper in misc/cpp/imgui_stdlib.h/.cpp |
| 3753 | // - Otherwise, see the 'Dear ImGui Demo->Widgets->Text Input->Resize Callback' for using ImGuiInputTextFlags_CallbackResize. |
| 3754 | static char text[1024 * 16] = |
| 3755 | "/*\n" |
| 3756 | " The Pentium F00F bug, shorthand for F0 0F C7 C8,\n" |
| 3757 | " the hexadecimal encoding of one offending instruction,\n" |
| 3758 | " more formally, the invalid operand with locked CMPXCHG8B\n" |
| 3759 | " instruction bug, is a design flaw in the majority of\n" |
| 3760 | " Intel Pentium, Pentium MMX, and Pentium OverDrive\n" |
| 3761 | " processors (all in the P5 microarchitecture).\n" |
| 3762 | "*/\n\n" |
| 3763 | "label:\n" |
| 3764 | "\tlock cmpxchg8b eax\n"; |
| 3765 | |
| 3766 | static ImGuiInputTextFlags flags = ImGuiInputTextFlags_AllowTabInput; |
| 3767 | HelpMarker("You can use the ImGuiInputTextFlags_CallbackResize facility if you need to wire InputTextMultiline() to a dynamic string type. See misc/cpp/imgui_stdlib.h for an example. (This is not demonstrated in imgui_demo.cpp because we don't want to include <string> in here)"); |
| 3768 | ImGui::CheckboxFlags("ImGuiInputTextFlags_ReadOnly", &flags, ImGuiInputTextFlags_ReadOnly); |
| 3769 | ImGui::CheckboxFlags("ImGuiInputTextFlags_WordWrap", &flags, ImGuiInputTextFlags_WordWrap); |
| 3770 | ImGui::SameLine(); HelpMarker("Feature is currently in Beta. Please read comments in imgui.h"); |
| 3771 | ImGui::CheckboxFlags("ImGuiInputTextFlags_AllowTabInput", &flags, ImGuiInputTextFlags_AllowTabInput); |
| 3772 | ImGui::SameLine(); HelpMarker("When _AllowTabInput is set, passing through the widget with Tabbing doesn't automatically activate it, in order to also cycling through subsequent widgets."); |
| 3773 | ImGui::CheckboxFlags("ImGuiInputTextFlags_CtrlEnterForNewLine", &flags, ImGuiInputTextFlags_CtrlEnterForNewLine); |
| 3774 | ImGui::InputTextMultiline("##source", text, IM_COUNTOF(text), ImVec2(-FLT_MIN, ImGui::GetTextLineHeight() * 16), flags); |
| 3775 | ImGui::TreePop(); |
| 3776 | } |
| 3777 | |
| 3778 | if (ImGui::TreeNode("Filtered Text Input")) |
| 3779 | { |
| 3780 | IMGUI_DEMO_MARKER("Widgets/Text Input/Filtered Text Input"); |
| 3781 | struct TextFilters |
| 3782 | { |
| 3783 | // Modify character input by altering 'data->Eventchar' (ImGuiInputTextFlags_CallbackCharFilter callback) |
| 3784 | static int FilterCasingSwap(ImGuiInputTextCallbackData* data) |
| 3785 | { |
| 3786 | if (data->EventChar >= 'a' && data->EventChar <= 'z') { data->EventChar -= 'a' - 'A'; } // Lowercase becomes uppercase |
| 3787 | else if (data->EventChar >= 'A' && data->EventChar <= 'Z') { data->EventChar += 'a' - 'A'; } // Uppercase becomes lowercase |
| 3788 | return 0; |
| 3789 | } |
| 3790 | |
| 3791 | // Return 0 (pass) if the character is 'i' or 'm' or 'g' or 'u' or 'i', otherwise return 1 (filter out) |
| 3792 | static int FilterImGuiLetters(ImGuiInputTextCallbackData* data) |
| 3793 | { |
| 3794 | if (data->EventChar < 256 && strchr("imgui", (char)data->EventChar)) |
| 3795 | return 0; |
| 3796 | return 1; |
| 3797 | } |
no test coverage detected