MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / DemoWindowWidgetsTextInput

Function DemoWindowWidgetsTextInput

imgui_tiny_app/imgui/imgui_demo.cpp:3826–4040  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3824//-----------------------------------------------------------------------------
3825
3826static void DemoWindowWidgetsTextInput()
3827{
3828 // To wire InputText() with std::string or any other custom string type,
3829 // see the "Text Input > Resize Callback" section of this demo, and the misc/cpp/imgui_stdlib.h file.
3830 if (ImGui::TreeNode("Text Input"))
3831 {
3832 IMGUI_DEMO_MARKER("Widgets/Text Input");
3833 if (ImGui::TreeNode("Multi-line Text Input"))
3834 {
3835 IMGUI_DEMO_MARKER("Widgets/Text Input/Multi-line Text Input");
3836 // WE ARE USING A FIXED-SIZE BUFFER FOR SIMPLICITY HERE.
3837 // If you want to use InputText() with std::string or any custom dynamic string type:
3838 // - For std::string: use the wrapper in misc/cpp/imgui_stdlib.h/.cpp
3839 // - Otherwise, see the 'Dear ImGui Demo->Widgets->Text Input->Resize Callback' for using ImGuiInputTextFlags_CallbackResize.
3840 static char text[1024 * 16] =
3841 "/*\n"
3842 " The Pentium F00F bug, shorthand for F0 0F C7 C8,\n"
3843 " the hexadecimal encoding of one offending instruction,\n"
3844 " more formally, the invalid operand with locked CMPXCHG8B\n"
3845 " instruction bug, is a design flaw in the majority of\n"
3846 " Intel Pentium, Pentium MMX, and Pentium OverDrive\n"
3847 " processors (all in the P5 microarchitecture).\n"
3848 "*/\n\n"
3849 "label:\n"
3850 "\tlock cmpxchg8b eax\n";
3851
3852 static ImGuiInputTextFlags flags = ImGuiInputTextFlags_AllowTabInput;
3853 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)");
3854 ImGui::CheckboxFlags("ImGuiInputTextFlags_ReadOnly", &flags, ImGuiInputTextFlags_ReadOnly);
3855 ImGui::CheckboxFlags("ImGuiInputTextFlags_WordWrap", &flags, ImGuiInputTextFlags_WordWrap);
3856 ImGui::SameLine(); HelpMarker("Feature is currently in Beta. Please read comments in imgui.h");
3857 ImGui::CheckboxFlags("ImGuiInputTextFlags_AllowTabInput", &flags, ImGuiInputTextFlags_AllowTabInput);
3858 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.");
3859 ImGui::CheckboxFlags("ImGuiInputTextFlags_CtrlEnterForNewLine", &flags, ImGuiInputTextFlags_CtrlEnterForNewLine);
3860 ImGui::InputTextMultiline("##source", text, IM_COUNTOF(text), ImVec2(-FLT_MIN, ImGui::GetTextLineHeight() * 16), flags);
3861 ImGui::TreePop();
3862 }
3863
3864 if (ImGui::TreeNode("Filtered Text Input"))
3865 {
3866 IMGUI_DEMO_MARKER("Widgets/Text Input/Filtered Text Input");
3867 struct TextFilters
3868 {
3869 // Modify character input by altering 'data->Eventchar' (ImGuiInputTextFlags_CallbackCharFilter callback)
3870 static int FilterCasingSwap(ImGuiInputTextCallbackData* data)
3871 {
3872 if (data->EventChar >= 'a' && data->EventChar <= 'z') { data->EventChar -= 'a' - 'A'; } // Lowercase becomes uppercase
3873 else if (data->EventChar >= 'A' && data->EventChar <= 'Z') { data->EventChar += 'a' - 'A'; } // Uppercase becomes lowercase
3874 return 0;
3875 }
3876
3877 // Return 0 (pass) if the character is 'i' or 'm' or 'g' or 'u' or 'i', otherwise return 1 (filter out)
3878 static int FilterImGuiLetters(ImGuiInputTextCallbackData* data)
3879 {
3880 if (data->EventChar < 256 && strchr("imgui", (char)data->EventChar))
3881 return 0;
3882 return 1;
3883 }

Callers 1

DemoWindowWidgetsFunction · 0.85

Calls 6

HelpMarkerFunction · 0.85
ImVec2Function · 0.85
emptyMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected