pikaConsoleWindow.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "pikaConsoleWindow.h"
  2. #include <logs/assert.h>
  3. #include <iostream>
  4. namespace pika
  5. {
  6. void ConsoleWindow::init(pika::pikaImgui::ImGuiIdsManager &idManager)
  7. {
  8. imguiId = idManager.getImguiIds();
  9. s.reserve(4000);
  10. }
  11. void ConsoleWindow::update(pika::LogManager &logManager, bool &open)
  12. {
  13. //s += buffer->get;
  14. //*buffer = std::streambuf();
  15. //s += std::string{(std::istreambuf_iterator<char>(buffer)),
  16. // std::istreambuf_iterator<char>()};
  17. constexpr int SIZE = 3000; //todo
  18. if (s.size() > SIZE)
  19. {
  20. s.erase(0, s.size() - SIZE);
  21. }
  22. ImGui::PushID(imguiId);
  23. if (!ImGui::Begin(ICON_NAME, &open))
  24. {
  25. ImGui::End();
  26. ImGui::PopID();
  27. return;
  28. }
  29. ImGui::BeginChild("##console scrolling", ImVec2(0, 0), false);
  30. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
  31. ImGui::TextWrapped(s.c_str());
  32. //ImGui::TextUnformatted(s.c_str());
  33. ImGui::PopStyleVar();
  34. if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
  35. ImGui::SetScrollHereY(1.0f);
  36. ImGui::EndChild();
  37. ImGui::End();
  38. ImGui::PopID();
  39. }
  40. };