MCPcopy Create free account
hub / github.com/Overload-Technologies/Overload / InputTextEx

Method InputTextEx

Dependencies/ImGui/src/imgui_widgets.cpp:4461–5424  ·  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

4459// (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
4460// 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)
4461bool 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)
4462{
4463 ImGuiWindow* window = GetCurrentWindow();
4464 if (window->SkipItems)
4465 return false;
4466
4467 IM_ASSERT(buf != NULL && buf_size >= 0);
4468 IM_ASSERT(!((flags & ImGuiInputTextFlags_CallbackHistory) && (flags & ImGuiInputTextFlags_Multiline))); // Can't use both together (they both use up/down keys)
4469 IM_ASSERT(!((flags & ImGuiInputTextFlags_CallbackCompletion) && (flags & ImGuiInputTextFlags_AllowTabInput))); // Can't use both together (they both use tab key)
4470 IM_ASSERT(!((flags & ImGuiInputTextFlags_ElideLeft) && (flags & ImGuiInputTextFlags_Multiline))); // Multiline will not work with left-trimming
4471
4472 ImGuiContext& g = *GImGui;
4473 ImGuiIO& io = g.IO;
4474 const ImGuiStyle& style = g.Style;
4475
4476 const bool RENDER_SELECTION_WHEN_INACTIVE = false;
4477 const bool is_multiline = (flags & ImGuiInputTextFlags_Multiline) != 0;
4478
4479 if (is_multiline) // Open group before calling GetID() because groups tracks id created within their scope (including the scrollbar)
4480 BeginGroup();
4481 const ImGuiID id = window->GetID(label);
4482 const ImVec2 label_size = CalcTextSize(label, NULL, true);
4483 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
4484 const ImVec2 total_size = ImVec2(frame_size.x + (label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f), frame_size.y);
4485
4486 const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size);
4487 const ImRect total_bb(frame_bb.Min, frame_bb.Min + total_size);
4488
4489 ImGuiWindow* draw_window = window;
4490 ImVec2 inner_size = frame_size;
4491 ImGuiLastItemData item_data_backup;
4492 if (is_multiline)
4493 {
4494 ImVec2 backup_pos = window->DC.CursorPos;
4495 ItemSize(total_bb, style.FramePadding.y);
4496 if (!ItemAdd(total_bb, id, &frame_bb, ImGuiItemFlags_Inputable))
4497 {
4498 EndGroup();
4499 return false;
4500 }
4501 item_data_backup = g.LastItemData;
4502 window->DC.CursorPos = backup_pos;
4503
4504 // Prevent NavActivation from Tabbing when our widget accepts Tab inputs: this allows cycling through widgets without stopping.
4505 if (g.NavActivateId == id && (g.NavActivateFlags & ImGuiActivateFlags_FromTabbing) && (flags & ImGuiInputTextFlags_AllowTabInput))
4506 g.NavActivateId = 0;
4507
4508 // Prevent NavActivate reactivating in BeginChild() when we are already active.
4509 const ImGuiID backup_activate_id = g.NavActivateId;
4510 if (g.ActiveId == id) // Prevent reactivation
4511 g.NavActivateId = 0;
4512
4513 // We reproduce the contents of BeginChildFrame() in order to provide 'label' so our window internal data are easier to read/debug.
4514 PushStyleColor(ImGuiCol_ChildBg, style.Colors[ImGuiCol_FrameBg]);
4515 PushStyleVar(ImGuiStyleVar_ChildRounding, style.FrameRounding);
4516 PushStyleVar(ImGuiStyleVar_ChildBorderSize, style.FrameBorderSize);
4517 PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); // Ensure no clip rect so mouse hover can reach FramePadding edges
4518 bool child_visible = BeginChildEx(label, id, frame_bb.GetSize(), ImGuiChildFlags_Borders, ImGuiWindowFlags_NoMove);

Callers

nothing calls this directly

Calls 15

GetCurrentWindowFunction · 0.85
ImVec2Function · 0.85
ItemSizeFunction · 0.85
GetInputTextStateFunction · 0.85
ImMaxFunction · 0.85
stb_textedit_clickFunction · 0.85
STB_TEXTEDIT_GETCHARFunction · 0.85
stb_textedit_clampFunction · 0.85

Tested by

no test coverage detected