#include "client/gui/ColorFulText.h"

#include <imgui.h>
#include <imgui_internal.h>

namespace blitz {
namespace gui {

void RenderColorfulText(const protocol::ColoredText& parts, float alpha) {
	ImGuiContext& g = *ImGui::GetCurrentContext();
	for (auto& part : parts) {
		const bool need_backup = (g.CurrentWindow->DC.TextWrapPos < 0.0f);	// Keep existing wrap position if one is already set
		if (need_backup)
			ImGui::PushTextWrapPos(0.0f);
		ImGui::TextColored({part.color.r, part.color.g, part.color.b, alpha}, "%s", part.text.c_str());
		if (need_backup)
			ImGui::PopTextWrapPos();
		ImGui::SameLine();
		ImGui::SetCursorPosX(ImGui::GetCursorPosX() - ImGui::CalcTextSize(".").x);
	}

	ImGui::NewLine();
};

}  // namespace gui
}  // namespace blitz
