MCPcopy Create free account
hub / github.com/Apress/Ray-Tracing-Gems-II / InputTextEx

Method InputTextEx

Chapter_16/shared_sources/imgui/imgui_widgets.cpp:3394–4151  ·  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

3392// (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
3393// 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)
3394bool 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)
3395{
3396 ImGuiWindow* window = GetCurrentWindow();
3397 if (window->SkipItems)
3398 return false;
3399
3400 IM_ASSERT(!((flags & ImGuiInputTextFlags_CallbackHistory) && (flags & ImGuiInputTextFlags_Multiline))); // Can't use both together (they both use up/down keys)
3401 IM_ASSERT(!((flags & ImGuiInputTextFlags_CallbackCompletion) && (flags & ImGuiInputTextFlags_AllowTabInput))); // Can't use both together (they both use tab key)
3402
3403 ImGuiContext& g = *GImGui;
3404 ImGuiIO& io = g.IO;
3405 const ImGuiStyle& style = g.Style;
3406
3407 const bool RENDER_SELECTION_WHEN_INACTIVE = false;
3408 const bool is_multiline = (flags & ImGuiInputTextFlags_Multiline) != 0;
3409 const bool is_readonly = (flags & ImGuiInputTextFlags_ReadOnly) != 0;
3410 const bool is_password = (flags & ImGuiInputTextFlags_Password) != 0;
3411 const bool is_undoable = (flags & ImGuiInputTextFlags_NoUndoRedo) == 0;
3412 const bool is_resizable = (flags & ImGuiInputTextFlags_CallbackResize) != 0;
3413 if (is_resizable)
3414 IM_ASSERT(callback != NULL); // Must provide a callback if you set the ImGuiInputTextFlags_CallbackResize flag!
3415
3416 if (is_multiline) // Open group before calling GetID() because groups tracks id created within their scope,
3417 BeginGroup();
3418 const ImGuiID id = window->GetID(label);
3419 const ImVec2 label_size = CalcTextSize(label, NULL, true);
3420 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
3421 const ImVec2 total_size = ImVec2(frame_size.x + (label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f), frame_size.y);
3422
3423 const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size);
3424 const ImRect total_bb(frame_bb.Min, frame_bb.Min + total_size);
3425
3426 ImGuiWindow* draw_window = window;
3427 ImVec2 inner_size = frame_size;
3428 if (is_multiline)
3429 {
3430 if (!ItemAdd(total_bb, id, &frame_bb))
3431 {
3432 ItemSize(total_bb, style.FramePadding.y);
3433 EndGroup();
3434 return false;
3435 }
3436 if (!BeginChildFrame(id, frame_bb.GetSize()))
3437 {
3438 EndChildFrame();
3439 EndGroup();
3440 return false;
3441 }
3442 draw_window = g.CurrentWindow; // Child window
3443 draw_window->DC.NavLayerActiveMaskNext |= draw_window->DC.NavLayerCurrentMask; // This is to ensure that EndChild() will display a navigation highlight
3444 inner_size.x -= draw_window->ScrollbarSizes.x;
3445 }
3446 else
3447 {
3448 ItemSize(total_bb, style.FramePadding.y);
3449 if (!ItemAdd(total_bb, id, &frame_bb))
3450 return false;
3451 }

Callers

nothing calls this directly

Calls 15

GetCurrentWindowFunction · 0.85
ImVec2Class · 0.85
ImTextStrFromUtf8Function · 0.85
stb_textedit_clickFunction · 0.85
stb_textedit_dragFunction · 0.85
IsKeyPressedMapFunction · 0.85
InputTextFilterCharacterFunction · 0.85
ImMaxFunction · 0.85
ImMinFunction · 0.85
ImTextStrToUtf8Function · 0.85

Tested by

no test coverage detected