pikaImgui.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #pragma once
  2. #include <pikaConfig.h>
  3. #include "imgui.h"
  4. #include "imfilebrowser.h"
  5. #include "backends/imgui_impl_glfw.h"
  6. #include "backends/imgui_impl_opengl3.h"
  7. #include "imguiThemes.h"
  8. #include <IconsForkAwesome.h>
  9. #include <pikaAllocator/freeListAllocator.h>
  10. #include <pikaContext.h>
  11. #include <glm/vec4.hpp>
  12. #include <vector>
  13. #include <string>
  14. #ifdef PIKA_WINDOWS
  15. #define IM_PRId64 "I64d"
  16. #define IM_PRIu64 "I64u"
  17. #define IM_PRIx64 "I64X"
  18. #else
  19. #define IM_PRId64 "lld"
  20. #define IM_PRIu64 "llu"
  21. #define IM_PRIx64 "llX"
  22. #endif
  23. namespace pika
  24. {
  25. namespace pikaImgui
  26. {
  27. void *imguiCustomAlloc(size_t sz, void *user_data);
  28. void imguiCustomFree(void *ptr, void *user_data);
  29. void setImguiAllocator(pika::memory::FreeListAllocator &allocator);
  30. void initImgui(PikaContext &pikaContext);
  31. void setImguiContext(PikaContext pikaContext);
  32. void imguiStartFrame(PikaContext pikaContext);
  33. void imguiEndFrame(PikaContext pikaContext);
  34. namespace EditorImguiIds
  35. {
  36. enum
  37. {
  38. idsCount = 4000
  39. };
  40. }
  41. struct ImGuiIdsManager
  42. {
  43. int counter = EditorImguiIds::idsCount + 1;
  44. //returns the first id. (count) ids will be reserved.
  45. //if you want 5 ids and the function returns 10, then ids 10 11 12 13 14 will be reserved.
  46. int getImguiIds(unsigned int count = 1)
  47. {
  48. if (count == 0) { return 0; }
  49. auto c = counter;
  50. counter += count;
  51. return c;
  52. }
  53. };
  54. bool redButton(const char *label, const ImVec2 &size_arg = {});
  55. bool greenButton(const char *label, const ImVec2 &size_arg = {});
  56. bool blueButton(const char *label, const ImVec2 &size_arg = {});
  57. bool colouredButton(const char *label, glm::vec4 color, const ImVec2 &size_arg = {});
  58. bool ColorEdit4Swatches(const char *label, float col[4], ImGuiColorEditFlags flags = 0);
  59. bool BeginChildFrameColoured(ImGuiID id,
  60. glm::vec4 color,
  61. const ImVec2 &size = {},
  62. ImGuiWindowFlags extra_flags = 0);
  63. void addErrorSymbol();
  64. void addWarningSymbol();
  65. void helpMarker(const char *desc);
  66. //todo another namespace for pika imgui adons
  67. void alignForWidth(float width, float alignment = 0.5f);
  68. void displayMemorySizeValue(size_t value);
  69. //todo move to internal
  70. void displayMemorySizeToggle();
  71. struct FileSelector
  72. {
  73. FileSelector() {};
  74. FileSelector(std::string title, std::string pwd, std::vector<std::string> typeFilters)
  75. {
  76. setInfo(std::move(title), std::move(pwd), std::move(typeFilters));
  77. }
  78. void setInfo(std::string title, std::string pwd, std::vector<std::string> typeFilters);
  79. char file[260] = {};
  80. ImGui::FileBrowser fileBrowser;
  81. //returns true on new file selected
  82. bool run(int id);
  83. };
  84. void removeFocusToCurrentWindow();
  85. };
  86. };