ImGuiHelpers.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2018 Jérémie Dumas <jeremie.dumas@ens-lyon.org>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_OPENGL_GLFW_IMGUI_IMGUIHELPERS_H
  9. #define IGL_OPENGL_GLFW_IMGUI_IMGUIHELPERS_H
  10. ////////////////////////////////////////////////////////////////////////////////
  11. #include <imgui/imgui.h>
  12. #include <vector>
  13. #include <string>
  14. ////////////////////////////////////////////////////////////////////////////////
  15. // Extend ImGui by populating its namespace directly
  16. //
  17. // Code snippets taken from there:
  18. // https://eliasdaler.github.io/using-imgui-with-sfml-pt2/
  19. namespace ImGui
  20. {
  21. static auto vector_getter = [](void* vec, int idx, const char** out_text)
  22. {
  23. auto& vector = *static_cast<std::vector<std::string>*>(vec);
  24. if (idx < 0 || idx >= static_cast<int>(vector.size())) { return false; }
  25. *out_text = vector.at(idx).c_str();
  26. return true;
  27. };
  28. inline bool Combo(const char* label, int* idx, std::vector<std::string>& values)
  29. {
  30. if (values.empty()) { return false; }
  31. return Combo(label, idx, vector_getter,
  32. static_cast<void*>(&values), values.size());
  33. }
  34. inline bool ListBox(const char* label, int* idx, std::vector<std::string>& values)
  35. {
  36. if (values.empty()) { return false; }
  37. return ListBox(label, idx, vector_getter,
  38. static_cast<void*>(&values), values.size());
  39. }
  40. } // namespace ImGui
  41. #endif // IGL_OPENGL_GLFW_IMGUI_IMGUIHELPERS_H