#include "GUIWidgets.h" #include "imgui_internal.h" void GUIWidgets::RenderRuns(ImageRegistry *registry, std::vector* runs) { ImFont* font = ImGui::GetFont(); for (const auto& run : *runs) { if (run.type == TEXT) { auto textRun = std::get(run.data); auto realText = textRun.text.c_str(); const char* text = &realText[0]; while (strlen(text) > 0) { auto remainingWidth = ImGui::CalcWrapWidthForPos(ImGui::GetCursorScreenPos(), 0.0f); // calculate ending position of text auto end = font->CalcWordWrapPosition(20.f, text, text + strlen(text), remainingWidth); if (textRun.is_link) { ImGui::PushOverrideID(ImGui::GetID(text, end)); ImGui::TextLinkOpenURL(realText, textRun.link.c_str()); ImGui::PopID(); break; } ImGui::TextUnformatted(text, end); if (text == end && strlen(text) > 0) { ImGui::NewLine(); break; } if (strlen(text) == strlen(end)) { ImGui::SameLine(); } text = end; } ImGui::SameLine(); } else if (run.type == EMOJI) { auto remainingWidth = ImGui::CalcWrapWidthForPos(ImGui::GetCursorScreenPos(), 0.0f); auto emoji = std::get(run.data); auto img = registry->Get(emoji.name, emoji.url); if (remainingWidth - 32 < 0) { ImGui::NewLine(); } if (img) { ImGui::Image(img->textureId, ImVec2(20.f, 20.f)); ImGui::SameLine(); } } } }