Edit a string of text NB: when active, hold on a privately held copy of the text (and apply back to 'buf'). So changing 'buf' while active has no effect. FIXME: Rather messy function partly because we are doing UTF8 > u16 > UTF8 conversions on the go to more easily handle stb_textedit calls. Ideally we should stay in UTF-8 all the time. See https://github.com/nothings/stb/issues/188
| 10065 | // NB: when active, hold on a privately held copy of the text (and apply back to 'buf'). So changing 'buf' while active has no effect. |
| 10066 | // FIXME: Rather messy function partly because we are doing UTF8 > u16 > UTF8 conversions on the go to more easily handle stb_textedit calls. Ideally we should stay in UTF-8 all the time. See https://github.com/nothings/stb/issues/188 |
| 10067 | bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data) |
| 10068 | { |
| 10069 | ImGuiWindow* window = GetCurrentWindow(); |
| 10070 | if (window->SkipItems) |
| 10071 | return false; |
| 10072 | |
| 10073 | IM_ASSERT(!((flags & ImGuiInputTextFlags_CallbackHistory) && (flags & ImGuiInputTextFlags_Multiline))); // Can't use both together (they both use up/down keys) |
| 10074 | IM_ASSERT(!((flags & ImGuiInputTextFlags_CallbackCompletion) && (flags & ImGuiInputTextFlags_AllowTabInput))); // Can't use both together (they both use tab key) |
| 10075 | |
| 10076 | ImGuiContext& g = *GImGui; |
| 10077 | const ImGuiIO& io = g.IO; |
| 10078 | const ImGuiStyle& style = g.Style; |
| 10079 | |
| 10080 | const bool is_multiline = (flags & ImGuiInputTextFlags_Multiline) != 0; |
| 10081 | const bool is_editable = (flags & ImGuiInputTextFlags_ReadOnly) == 0; |
| 10082 | const bool is_password = (flags & ImGuiInputTextFlags_Password) != 0; |
| 10083 | const bool is_undoable = (flags & ImGuiInputTextFlags_NoUndoRedo) == 0; |
| 10084 | |
| 10085 | if (is_multiline) // Open group before calling GetID() because groups tracks id created during their spawn |
| 10086 | BeginGroup(); |
| 10087 | const ImGuiID id = window->GetID(label); |
| 10088 | const ImVec2 label_size = CalcTextSize(label, NULL, true); |
| 10089 | ImVec2 size = CalcItemSize(size_arg, CalcItemWidth(), (is_multiline ? GetTextLineHeight() * 8.0f : label_size.y) + style.FramePadding.y * 2.0f); // Arbitrary default of 8 lines high for multi-line |
| 10090 | const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + size); |
| 10091 | const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? (style.ItemInnerSpacing.x + label_size.x) : 0.0f, 0.0f)); |
| 10092 | |
| 10093 | ImGuiWindow* draw_window = window; |
| 10094 | if (is_multiline) |
| 10095 | { |
| 10096 | ItemAdd(total_bb, id, &frame_bb); |
| 10097 | if (!BeginChildFrame(id, frame_bb.GetSize())) |
| 10098 | { |
| 10099 | EndChildFrame(); |
| 10100 | EndGroup(); |
| 10101 | return false; |
| 10102 | } |
| 10103 | draw_window = GetCurrentWindow(); |
| 10104 | size.x -= draw_window->ScrollbarSizes.x; |
| 10105 | } |
| 10106 | else |
| 10107 | { |
| 10108 | ItemSize(total_bb, style.FramePadding.y); |
| 10109 | if (!ItemAdd(total_bb, id, &frame_bb)) |
| 10110 | return false; |
| 10111 | } |
| 10112 | const bool hovered = ItemHoverable(frame_bb, id); |
| 10113 | if (hovered) |
| 10114 | g.MouseCursor = ImGuiMouseCursor_TextInput; |
| 10115 | |
| 10116 | // Password pushes a temporary font with only a fallback glyph |
| 10117 | if (is_password) |
| 10118 | { |
| 10119 | const ImFontGlyph* glyph = g.Font->FindGlyph('*'); |
| 10120 | ImFont* password_font = &g.InputTextPasswordFont; |
| 10121 | password_font->FontSize = g.Font->FontSize; |
| 10122 | password_font->Scale = g.Font->Scale; |
| 10123 | password_font->DisplayOffset = g.Font->DisplayOffset; |
| 10124 | password_font->Ascent = g.Font->Ascent; |
nothing calls this directly
no test coverage detected