Cleaned widget's debug code and fixed it for platforms using other than char or wchar_t characters.

This commit is contained in:
Sebastian 2020-06-28 17:36:59 +01:00
parent b94bb7b5ef
commit 5d5bd8a284

View File

@ -736,6 +736,25 @@ static TArray<FKey> GetImGuiMappedKeys()
return Keys; return Keys;
} }
namespace
{
void Text(const char* Str)
{
ImGui::Text("%s:", Str);
}
void Text(const wchar_t* Str)
{
ImGui::Text("%ls:", Str);
}
template<typename CharType = std::enable_if_t<!std::is_same<TCHAR, char>::value && !std::is_same<TCHAR, wchar_t>::value, TCHAR>>
void Text(const CharType* Str)
{
ImGui::Text("%ls", TCHAR_TO_WCHAR(Str));
}
}
// Column layout utilities. // Column layout utilities.
namespace Columns namespace Columns
{ {
@ -761,58 +780,45 @@ namespace TwoColumns
Columns::CollapsingGroup(Name, 2, std::forward<FunctorType>(DrawContent)); Columns::CollapsingGroup(Name, 2, std::forward<FunctorType>(DrawContent));
} }
namespace
{
void LabelText(const char* Label)
{
ImGui::Text("%s:", Label);
}
void LabelText(const wchar_t* Label)
{
ImGui::Text("%ls:", Label);
}
}
template<typename LabelType> template<typename LabelType>
static void Value(LabelType&& Label, int32 Value) static void Value(LabelType&& Label, int32 Value)
{ {
LabelText(Label); ImGui::NextColumn(); Text(Label); ImGui::NextColumn();
ImGui::Text("%d", Value); ImGui::NextColumn(); ImGui::Text("%d", Value); ImGui::NextColumn();
} }
template<typename LabelType> template<typename LabelType>
static void Value(LabelType&& Label, uint32 Value) static void Value(LabelType&& Label, uint32 Value)
{ {
LabelText(Label); ImGui::NextColumn(); Text(Label); ImGui::NextColumn();
ImGui::Text("%u", Value); ImGui::NextColumn(); ImGui::Text("%u", Value); ImGui::NextColumn();
} }
template<typename LabelType> template<typename LabelType>
static void Value(LabelType&& Label, float Value) static void Value(LabelType&& Label, float Value)
{ {
LabelText(Label); ImGui::NextColumn(); Text(Label); ImGui::NextColumn();
ImGui::Text("%f", Value); ImGui::NextColumn(); ImGui::Text("%f", Value); ImGui::NextColumn();
} }
template<typename LabelType> template<typename LabelType>
static void Value(LabelType&& Label, bool bValue) static void Value(LabelType&& Label, bool bValue)
{ {
LabelText(Label); ImGui::NextColumn(); Text(Label); ImGui::NextColumn();
ImGui::Text("%ls", TEXT_BOOL(bValue)); ImGui::NextColumn(); Text(TEXT_BOOL(bValue)); ImGui::NextColumn();
} }
template<typename LabelType> template<typename LabelType>
static void Value(LabelType&& Label, const TCHAR* Value) static void Value(LabelType&& Label, const TCHAR* Value)
{ {
LabelText(Label); ImGui::NextColumn(); Text(Label); ImGui::NextColumn();
ImGui::Text("%ls", Value); ImGui::NextColumn(); Text(Value); ImGui::NextColumn();
} }
template<typename LabelType> template<typename LabelType>
static void ValueWidthHeight(LabelType&& Label, const FVector2D& Value) static void ValueWidthHeight(LabelType&& Label, const FVector2D& Value)
{ {
LabelText(Label); ImGui::NextColumn(); Text(Label); ImGui::NextColumn();
ImGui::Text("Width = %.0f, Height = %.0f", Value.X, Value.Y); ImGui::NextColumn(); ImGui::Text("Width = %.0f, Height = %.0f", Value.X, Value.Y); ImGui::NextColumn();
} }
} }
@ -846,20 +852,25 @@ void SImGuiWidget::OnDebugDraw()
{ {
ImGui::Spacing(); ImGui::Spacing();
TwoColumns::CollapsingGroup("Context", [&]()
{
TwoColumns::Value("Context Index", ContextIndex);
TwoColumns::Value("Context Name", ContextProxy ? *ContextProxy->GetName() : TEXT("< Null >"));
TwoColumns::Value("Game Viewport", *GameViewport->GetName());
});
TwoColumns::CollapsingGroup("Canvas Size", [&]() TwoColumns::CollapsingGroup("Canvas Size", [&]()
{ {
TwoColumns::Value("Is Adaptive", bAdaptiveCanvasSize); TwoColumns::Value("Is Adaptive", bAdaptiveCanvasSize);
TwoColumns::Value("Is Updating", bUpdateCanvasSize); TwoColumns::Value("Is Updating", bUpdateCanvasSize);
TwoColumns::ValueWidthHeight("Min Canvas Size", MinCanvasSize); TwoColumns::ValueWidthHeight("Min Canvas Size", MinCanvasSize);
TwoColumns::ValueWidthHeight("Canvas Size", CanvasSize); TwoColumns::ValueWidthHeight("Canvas Size", CanvasSize);
TwoColumns::Value("DPI Scale", DPIScale);
}); });
TwoColumns::CollapsingGroup("Context", [&]() TwoColumns::CollapsingGroup("DPI Scale", [&]()
{ {
TwoColumns::Value("Context Index", ContextIndex); TwoColumns::Value("Slate Scale", DPIScale);
TwoColumns::Value("Context Name", ContextProxy ? *ContextProxy->GetName() : TEXT("< Null >")); TwoColumns::Value("ImGui Scale", ContextProxy ? ContextProxy->GetDPIScale() : 1.f);
TwoColumns::Value("Game Viewport", *GameViewport->GetName());
}); });
TwoColumns::CollapsingGroup("Input Mode", [&]() TwoColumns::CollapsingGroup("Input Mode", [&]()