MCPcopy Create free account
hub / github.com/VictorGordan/opengl-tutorials / InputTextEx

Method InputTextEx

ImGUI GLFW Tutorial/imgui/imgui_widgets.cpp:3861–4663  ·  view source on GitHub ↗

Edit a string of text - buf_size account for the zero-terminator, so a buf_size of 6 can hold "Hello" but not "Hello!". This is so we can easily call InputText() on static arrays using ARRAYSIZE() and to match Note that in std::string world, capacity() would omit 1 byte used by the zero-terminator. - When active, hold on a privately held copy of the text (and apply back to 'buf'). So changing 'buf

Source from the content-addressed store, hash-verified

3859// (FIXME: Rather confusing and messy function, among the worse part of our codebase, expecting to rewrite a V2 at some point.. Partly because we are
3860// doing UTF8 > U16 > UTF8 conversions on the go to easily interface with stb_textedit. Ideally should stay in UTF-8 all the time. See https://github.com/nothings/stb/issues/188)
3861bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* callback_user_data)
3862{
3863 ImGuiWindow* window = GetCurrentWindow();
3864 if (window->SkipItems)
3865 return false;
3866
3867 IM_ASSERT(buf != NULL && buf_size >= 0);
3868 IM_ASSERT(!((flags & ImGuiInputTextFlags_CallbackHistory) && (flags & ImGuiInputTextFlags_Multiline))); // Can't use both together (they both use up/down keys)
3869 IM_ASSERT(!((flags & ImGuiInputTextFlags_CallbackCompletion) && (flags & ImGuiInputTextFlags_AllowTabInput))); // Can't use both together (they both use tab key)
3870
3871 ImGuiContext& g = *GImGui;
3872 ImGuiIO& io = g.IO;
3873 const ImGuiStyle& style = g.Style;
3874
3875 const bool RENDER_SELECTION_WHEN_INACTIVE = false;
3876 const bool is_multiline = (flags & ImGuiInputTextFlags_Multiline) != 0;
3877 const bool is_readonly = (flags & ImGuiInputTextFlags_ReadOnly) != 0;
3878 const bool is_password = (flags & ImGuiInputTextFlags_Password) != 0;
3879 const bool is_undoable = (flags & ImGuiInputTextFlags_NoUndoRedo) == 0;
3880 const bool is_resizable = (flags & ImGuiInputTextFlags_CallbackResize) != 0;
3881 if (is_resizable)
3882 IM_ASSERT(callback != NULL); // Must provide a callback if you set the ImGuiInputTextFlags_CallbackResize flag!
3883
3884 if (is_multiline) // Open group before calling GetID() because groups tracks id created within their scope,
3885 BeginGroup();
3886 const ImGuiID id = window->GetID(label);
3887 const ImVec2 label_size = CalcTextSize(label, NULL, true);
3888 const ImVec2 frame_size = CalcItemSize(size_arg, CalcItemWidth(), (is_multiline ? g.FontSize * 8.0f : label_size.y) + style.FramePadding.y * 2.0f); // Arbitrary default of 8 lines high for multi-line
3889 const ImVec2 total_size = ImVec2(frame_size.x + (label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f), frame_size.y);
3890
3891 const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size);
3892 const ImRect total_bb(frame_bb.Min, frame_bb.Min + total_size);
3893
3894 ImGuiWindow* draw_window = window;
3895 ImVec2 inner_size = frame_size;
3896 if (is_multiline)
3897 {
3898 if (!ItemAdd(total_bb, id, &frame_bb, ImGuiItemAddFlags_Focusable))
3899 {
3900 ItemSize(total_bb, style.FramePadding.y);
3901 EndGroup();
3902 return false;
3903 }
3904
3905 // We reproduce the contents of BeginChildFrame() in order to provide 'label' so our window internal data are easier to read/debug.
3906 PushStyleColor(ImGuiCol_ChildBg, style.Colors[ImGuiCol_FrameBg]);
3907 PushStyleVar(ImGuiStyleVar_ChildRounding, style.FrameRounding);
3908 PushStyleVar(ImGuiStyleVar_ChildBorderSize, style.FrameBorderSize);
3909 bool child_visible = BeginChildEx(label, id, frame_bb.GetSize(), true, ImGuiWindowFlags_NoMove);
3910 PopStyleVar(2);
3911 PopStyleColor();
3912 if (!child_visible)
3913 {
3914 EndChild();
3915 EndGroup();
3916 return false;
3917 }
3918 draw_window = g.CurrentWindow; // Child window

Callers

nothing calls this directly

Calls 15

GetCurrentWindowFunction · 0.70
ImVec2Function · 0.70
GetInputTextStateFunction · 0.70
ImTextStrFromUtf8Function · 0.70
stb_textedit_clickFunction · 0.70
stb_textedit_dragFunction · 0.70
IsKeyPressedMapFunction · 0.70
InputTextFilterCharacterFunction · 0.70
ImMaxFunction · 0.70
ImMinFunction · 0.70

Tested by

no test coverage detected