From 6d7ffe0873e0eb34a006f4acd31af570affb1416 Mon Sep 17 00:00:00 2001 From: SweetId <2630750+SweetId@users.noreply.github.com> Date: Wed, 11 Oct 2023 20:37:09 -0400 Subject: [PATCH] add tooltip drawing --- include/NazaraEditor/Core/Reflection/Core.hpp | 1 + include/NazaraEditor/Core/Reflection/Math.hpp | 17 +++++++++++------ .../NazaraEditor/Core/Reflection/Reflection.hpp | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/include/NazaraEditor/Core/Reflection/Core.hpp b/include/NazaraEditor/Core/Reflection/Core.hpp index 31af127..7bdb26e 100644 --- a/include/NazaraEditor/Core/Reflection/Core.hpp +++ b/include/NazaraEditor/Core/Reflection/Core.hpp @@ -37,6 +37,7 @@ namespace Nz { obj = Color(values[0], values[1], values[2], values[3]); } + Tooltip(tooltip); return false; } diff --git a/include/NazaraEditor/Core/Reflection/Math.hpp b/include/NazaraEditor/Core/Reflection/Math.hpp index 8a052d3..7fe9efa 100644 --- a/include/NazaraEditor/Core/Reflection/Math.hpp +++ b/include/NazaraEditor/Core/Reflection/Math.hpp @@ -9,20 +9,22 @@ namespace Nz { namespace EditorImgui { - inline bool Begin(bool& obj, const std::string& name, const std::string& /*tooltip*/) + inline bool Begin(bool& obj, const std::string& name, const std::string& tooltip) { ImGui::Checkbox(name.c_str(), &obj); + Tooltip(tooltip); return false; } inline void End(bool&) {} #define IMGUI_BASIC_INTEGER(Type) \ - inline bool Begin(Type& obj, const std::string& name, const std::string& /*tooltip*/) \ + inline bool Begin(Type& obj, const std::string& name, const std::string& tooltip) \ { \ int value = static_cast(obj); \ if (ImGui::DragInt(name.c_str(), &value, 1.f, std::numeric_limits::min(), std::numeric_limits::max())) \ obj = static_cast(value); \ + Tooltip(tooltip); \ return false; \ } \ inline void End(Type&) {} @@ -37,12 +39,13 @@ namespace Nz IMGUI_BASIC_INTEGER(Nz::UInt64); #define IMGUI_BASIC_FLOAT(Type) \ - inline bool Begin(Type& obj, const std::string& name, const std::string& /*tooltip*/) \ + inline bool Begin(Type& obj, const std::string& name, const std::string& tooltip) \ { \ float value = (float)obj; \ if (ImGui::DragFloat(name.c_str(), &value, 1.f, std::numeric_limits::min(), std::numeric_limits::max())) \ obj = (Type)value; \ - return false; \ + Tooltip(tooltip); \ + return false; \ } \ inline void End(Type&) {} @@ -50,18 +53,19 @@ namespace Nz IMGUI_BASIC_FLOAT(double); - inline bool Begin(Nz::Vector3f& obj, const std::string& name, const std::string& /*tooltip*/) + inline bool Begin(Nz::Vector3f& obj, const std::string& name, const std::string& tooltip) { float value[] = { obj.x, obj.y, obj.z }; if (ImGui::DragFloat3(name.c_str(), value, 1.f, std::numeric_limits::min(), std::numeric_limits::max())) obj = Nz::Vector3f(value[0], value[1], value[2]); + Tooltip(tooltip); return false; } inline void End(Nz::Vector3f&) {} - inline bool Begin(Nz::Quaternionf& obj, const std::string& name, const std::string& /*tooltip*/) + inline bool Begin(Nz::Quaternionf& obj, const std::string& name, const std::string& tooltip) { auto euler = obj.ToEulerAngles(); float value[] = { euler.pitch.ToDegrees(), euler.yaw.ToDegrees(), euler.roll.ToDegrees() }; @@ -69,6 +73,7 @@ namespace Nz { obj = EulerAnglesf(value[0], value[1], value[2]).ToQuaternion(); } + Tooltip(tooltip); return false; } diff --git a/include/NazaraEditor/Core/Reflection/Reflection.hpp b/include/NazaraEditor/Core/Reflection/Reflection.hpp index 5da04e4..3f18097 100644 --- a/include/NazaraEditor/Core/Reflection/Reflection.hpp +++ b/include/NazaraEditor/Core/Reflection/Reflection.hpp @@ -1,5 +1,7 @@ #pragma once +#include + namespace Nz { template @@ -9,4 +11,17 @@ namespace Nz template static void Reflect(TEnumerator&, T&) { } // default specialization }; + + namespace EditorImgui + { + inline void Tooltip(const std::string& tooltip) + { + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::Text(tooltip.c_str()); + ImGui::EndTooltip(); + } + } + } } \ No newline at end of file