add tooltip drawing
This commit is contained in:
parent
42926a0c9b
commit
6d7ffe0873
|
|
@ -37,6 +37,7 @@ namespace Nz
|
|||
{
|
||||
obj = Color(values[0], values[1], values[2], values[3]);
|
||||
}
|
||||
Tooltip(tooltip);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<int>(obj); \
|
||||
if (ImGui::DragInt(name.c_str(), &value, 1.f, std::numeric_limits<Type>::min(), std::numeric_limits<Type>::max())) \
|
||||
obj = static_cast<Type>(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<Type>::min(), std::numeric_limits<Type>::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<float>::min(), std::numeric_limits<float>::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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template <typename T>
|
||||
|
|
@ -9,4 +11,17 @@ namespace Nz
|
|||
template <typename TEnumerator>
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue