Something went wrong. Try again.
Youtube chat viewer inspired by chatterino
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051#include "GUIWidgets.h"#include "imgui_internal.h"
void GUIWidgets::RenderRuns(ImageRegistry *registry, std::vector<Run>* runs) { ImFont* font = ImGui::GetFont(); for (const auto& run : *runs) { if (run.type == TEXT) { auto textRun = std::get<TextRun>(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<EmojiRun>(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(); } } }}