From 5d5bd8a284dba702ea3194a601724dd374d08fc1 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 28 Jun 2020 17:36:59 +0100 Subject: [PATCH] Cleaned widget's debug code and fixed it for platforms using other than char or wchar_t characters. --- Source/ImGui/Private/Widgets/SImGuiWidget.cpp | 63 +++++++++++-------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/Source/ImGui/Private/Widgets/SImGuiWidget.cpp b/Source/ImGui/Private/Widgets/SImGuiWidget.cpp index dcd9d3a..a715e83 100644 --- a/Source/ImGui/Private/Widgets/SImGuiWidget.cpp +++ b/Source/ImGui/Private/Widgets/SImGuiWidget.cpp @@ -736,6 +736,25 @@ static TArray GetImGuiMappedKeys() return Keys; } +namespace +{ + void Text(const char* Str) + { + ImGui::Text("%s:", Str); + } + + void Text(const wchar_t* Str) + { + ImGui::Text("%ls:", Str); + } + + template::value && !std::is_same::value, TCHAR>> + void Text(const CharType* Str) + { + ImGui::Text("%ls", TCHAR_TO_WCHAR(Str)); + } +} + // Column layout utilities. namespace Columns { @@ -761,58 +780,45 @@ namespace TwoColumns Columns::CollapsingGroup(Name, 2, std::forward(DrawContent)); } - namespace - { - void LabelText(const char* Label) - { - ImGui::Text("%s:", Label); - } - - void LabelText(const wchar_t* Label) - { - ImGui::Text("%ls:", Label); - } - } - template static void Value(LabelType&& Label, int32 Value) { - LabelText(Label); ImGui::NextColumn(); + Text(Label); ImGui::NextColumn(); ImGui::Text("%d", Value); ImGui::NextColumn(); } template static void Value(LabelType&& Label, uint32 Value) { - LabelText(Label); ImGui::NextColumn(); + Text(Label); ImGui::NextColumn(); ImGui::Text("%u", Value); ImGui::NextColumn(); } template static void Value(LabelType&& Label, float Value) { - LabelText(Label); ImGui::NextColumn(); + Text(Label); ImGui::NextColumn(); ImGui::Text("%f", Value); ImGui::NextColumn(); } template static void Value(LabelType&& Label, bool bValue) { - LabelText(Label); ImGui::NextColumn(); - ImGui::Text("%ls", TEXT_BOOL(bValue)); ImGui::NextColumn(); + Text(Label); ImGui::NextColumn(); + Text(TEXT_BOOL(bValue)); ImGui::NextColumn(); } template static void Value(LabelType&& Label, const TCHAR* Value) { - LabelText(Label); ImGui::NextColumn(); - ImGui::Text("%ls", Value); ImGui::NextColumn(); + Text(Label); ImGui::NextColumn(); + Text(Value); ImGui::NextColumn(); } template 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(); } } @@ -846,20 +852,25 @@ void SImGuiWidget::OnDebugDraw() { 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::Value("Is Adaptive", bAdaptiveCanvasSize); TwoColumns::Value("Is Updating", bUpdateCanvasSize); TwoColumns::ValueWidthHeight("Min Canvas Size", MinCanvasSize); TwoColumns::ValueWidthHeight("Canvas Size", CanvasSize); - TwoColumns::Value("DPI Scale", DPIScale); }); - TwoColumns::CollapsingGroup("Context", [&]() + TwoColumns::CollapsingGroup("DPI Scale", [&]() { - TwoColumns::Value("Context Index", ContextIndex); - TwoColumns::Value("Context Name", ContextProxy ? *ContextProxy->GetName() : TEXT("< Null >")); - TwoColumns::Value("Game Viewport", *GameViewport->GetName()); + TwoColumns::Value("Slate Scale", DPIScale); + TwoColumns::Value("ImGui Scale", ContextProxy ? ContextProxy->GetDPIScale() : 1.f); }); TwoColumns::CollapsingGroup("Input Mode", [&]()