ImGuiTraits.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_IMGUITRAITS_H
  9. #define IGL_OPENGL_GLFW_IMGUI_IMGUITRAITS_H
  10. #include <imgui/imgui.h>
  11. // Extend ImGui by populating its namespace directly
  12. namespace ImGui
  13. {
  14. // Infer ImGuiDataType enum based on actual type
  15. template<typename T>
  16. class ImGuiDataTypeTraits
  17. {
  18. static const ImGuiDataType value; // link error
  19. static const char * format;
  20. };
  21. template<>
  22. class ImGuiDataTypeTraits<int>
  23. {
  24. static constexpr ImGuiDataType value = ImGuiDataType_S32;
  25. static constexpr char format [] = "%d";
  26. };
  27. template<>
  28. class ImGuiDataTypeTraits<unsigned int>
  29. {
  30. static constexpr ImGuiDataType value = ImGuiDataType_U32;
  31. static constexpr char format [] = "%u";
  32. };
  33. template<>
  34. class ImGuiDataTypeTraits<long long>
  35. {
  36. static constexpr ImGuiDataType value = ImGuiDataType_S64;
  37. static constexpr char format [] = "%lld";
  38. };
  39. template<>
  40. class ImGuiDataTypeTraits<unsigned long long>
  41. {
  42. static constexpr ImGuiDataType value = ImGuiDataType_U64;
  43. static constexpr char format [] = "%llu";
  44. };
  45. template<>
  46. class ImGuiDataTypeTraits<float>
  47. {
  48. static constexpr ImGuiDataType value = ImGuiDataType_Float;
  49. static constexpr char format [] = "%.3f";
  50. };
  51. template<>
  52. class ImGuiDataTypeTraits<double>
  53. {
  54. static constexpr ImGuiDataType value = ImGuiDataType_Double;
  55. static constexpr char format [] = "%.6f";
  56. };
  57. } // namespace ImGui
  58. #endif // IGL_OPENGL_GLFW_IMGUI_IMGUIHELPERS_H