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
| 4680 | // - When active, hold on a privately held copy of the text (and apply back to 'buf'). So changing 'buf' while the InputText is active has no effect. |
| 4681 | // - If you want to use InputText() with std::string or any custom dynamic string type, use the wrapper in misc/cpp/imgui_stdlib.h/.cpp! |
| 4682 | bool 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) |
| 4683 | { |
| 4684 | ImGuiWindow* window = GetCurrentWindow(); |
| 4685 | if (window->SkipItems) |
| 4686 | return false; |
| 4687 | |
| 4688 | IM_ASSERT(buf != NULL && buf_size >= 0); |
| 4689 | IM_ASSERT(!((flags & ImGuiInputTextFlags_CallbackHistory) && (flags & ImGuiInputTextFlags_Multiline))); // Can't use both together (they both use up/down keys) |
| 4690 | IM_ASSERT(!((flags & ImGuiInputTextFlags_CallbackCompletion) && (flags & ImGuiInputTextFlags_AllowTabInput))); // Can't use both together (they both use tab key) |
| 4691 | IM_ASSERT(!((flags & ImGuiInputTextFlags_ElideLeft) && (flags & ImGuiInputTextFlags_Multiline))); // Multiline does not not work with left-trimming |
| 4692 | IM_ASSERT((flags & ImGuiInputTextFlags_WordWrap) == 0 || (flags & ImGuiInputTextFlags_Password) == 0); // WordWrap does not work with Password mode. |
| 4693 | IM_ASSERT((flags & ImGuiInputTextFlags_WordWrap) == 0 || (flags & ImGuiInputTextFlags_Multiline) != 0); // WordWrap does not work in single-line mode. |
| 4694 | |
| 4695 | ImGuiContext& g = *GImGui; |
| 4696 | ImGuiIO& io = g.IO; |
| 4697 | const ImGuiStyle& style = g.Style; |
| 4698 | |
| 4699 | const bool RENDER_SELECTION_WHEN_INACTIVE = false; |
| 4700 | const bool is_multiline = (flags & ImGuiInputTextFlags_Multiline) != 0; |
| 4701 | |
| 4702 | if (is_multiline) // Open group before calling GetID() because groups tracks id created within their scope (including the scrollbar) |
| 4703 | BeginGroup(); |
| 4704 | const ImGuiID id = window->GetID(label); |
| 4705 | const ImVec2 label_size = CalcTextSize(label, NULL, true); |
| 4706 | 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 |
| 4707 | const ImVec2 total_size = ImVec2(frame_size.x + (label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f), frame_size.y); |
| 4708 | |
| 4709 | const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size); |
| 4710 | const ImRect total_bb(frame_bb.Min, frame_bb.Min + total_size); |
| 4711 | |
| 4712 | ImGuiWindow* draw_window = window; |
| 4713 | ImVec2 inner_size = frame_size; |
| 4714 | ImGuiLastItemData item_data_backup; |
| 4715 | if (is_multiline) |
| 4716 | { |
| 4717 | ImVec2 backup_pos = window->DC.CursorPos; |
| 4718 | ItemSize(total_bb, style.FramePadding.y); |
| 4719 | bool no_clip = (g.InputTextDeactivatedState.ID == id) || (g.ActiveId == id) || (id == g.NavActivateId); // Mimic some of ItemAdd() logic + add InputTextDeactivatedState.ID check. |
| 4720 | if (!ItemAdd(total_bb, id, &frame_bb, ImGuiItemFlags_Inputable) && !no_clip) |
| 4721 | { |
| 4722 | EndGroup(); |
| 4723 | return false; |
| 4724 | } |
| 4725 | item_data_backup = g.LastItemData; |
| 4726 | window->DC.CursorPos = backup_pos; |
| 4727 | |
| 4728 | // Prevent NavActivation from explicit Tabbing when our widget accepts Tab inputs: this allows cycling through widgets without stopping. |
| 4729 | if (g.NavActivateId == id && (g.NavActivateFlags & ImGuiActivateFlags_FromTabbing) && !(g.NavActivateFlags & ImGuiActivateFlags_FromFocusApi) && (flags & ImGuiInputTextFlags_AllowTabInput)) |
| 4730 | g.NavActivateId = 0; |
| 4731 | |
| 4732 | // Prevent NavActivate reactivating in BeginChild() when we are already active. |
| 4733 | const ImGuiID backup_activate_id = g.NavActivateId; |
| 4734 | if (g.ActiveId == id) // Prevent reactivation |
| 4735 | g.NavActivateId = 0; |
| 4736 | |
| 4737 | // We reproduce the contents of BeginChildFrame() in order to provide 'label' so our window internal data are easier to read/debug. |
| 4738 | PushStyleColor(ImGuiCol_ChildBg, style.Colors[ImGuiCol_FrameBg]); |
| 4739 | PushStyleVar(ImGuiStyleVar_ChildRounding, style.FrameRounding); |
nothing calls this directly
no test coverage detected