1
0
mirror of synced 2024-12-15 17:21:16 +01:00
ImHex/lib/libimhex/include/hex/helpers/debugging.hpp
2023-11-10 20:47:08 +01:00

47 lines
1.8 KiB
C++

#pragma once
#include <wolv/utils/preproc.hpp>
#include <hex/ui/imgui_imhex_extensions.h>
#if defined(DEBUG)
#define DBG_DEFINE_DEBUG_VARIABLE(type, name) \
static type name; \
hex::dbg::impl::drawDebugVariable(name, WOLV_STRINGIFY(name));
#else
#define DBG_DEFINE_DEBUG_VARIABLE(type, name) \
static_assert(false, "Debug variables are only intended for use during development.");
#endif
namespace hex::dbg {
namespace impl {
bool &getDebugWindowState();
template<typename T>
static void drawDebugVariable(T &variable, std::string_view name) {
if (!getDebugWindowState())
return;
if (ImGui::Begin("Debug Variables", &getDebugWindowState(), ImGuiWindowFlags_AlwaysAutoResize)) {
using Type = std::remove_cvref_t<T>;
if constexpr (std::same_as<Type, bool>) {
ImGui::Checkbox(name.data(), &variable);
} else if constexpr (std::integral<Type> || std::floating_point<Type>) {
ImGui::InputScalar(name.data(), ImGui::getImGuiDataType<Type>(), &variable);
} else if constexpr (std::same_as<Type, ImVec2>) {
ImGui::InputFloat2(name.data(), &variable.x);
} else if constexpr (std::same_as<Type, std::string>) {
ImGui::InputText(name.data(), variable);
} else if constexpr (std::same_as<Type, ImColor>) {
ImGui::ColorEdit4(name.data(), &variable.Value.x, ImGuiColorEditFlags_AlphaBar);
} else {
static_assert(hex::always_false<Type>::value, "Unsupported type");
}
}
ImGui::End();
}
}
}