mirror of
https://github.com/kevinporetti/UnrealImGui.git
synced 2025-01-18 00:10:32 +00:00
Clean-up in debug code:
- Added common debug config file for module-wide debug symbols and loggers. - Added IMGUI_MODULE_DEVELOPER symbol to enable or disable module developer mode, that is intended to add additional module debug options hidden from normal usage. - ImGui Widget debug is only available in developer mode because in normal usage it adds noise to ImGui console variables while not being very useful. - Merged LogImGuiInputHandler and LogImGuiInputHandlerFactory loggers as they are part of the same feature. - Renamed LogImGuiInputState to LogImGuiInput.
This commit is contained in:
parent
20d1490bd3
commit
fc6fd2e498
@ -18,7 +18,8 @@
|
||||
#endif // WITH_EDITOR
|
||||
|
||||
|
||||
DEFINE_LOG_CATEGORY_STATIC(LogImGuiInputHandler, Warning, All);
|
||||
DEFINE_LOG_CATEGORY(LogImGuiInputHandler);
|
||||
|
||||
|
||||
FImGuiInputResponse UImGuiInputHandler::OnKeyDown(const FKeyEvent& KeyEvent)
|
||||
{
|
||||
|
@ -8,8 +8,6 @@
|
||||
#include "ImGuiSettings.h"
|
||||
|
||||
|
||||
DEFINE_LOG_CATEGORY_STATIC(LogImGuiInputHandlerFactory, Warning, All);
|
||||
|
||||
UImGuiInputHandler* FImGuiInputHandlerFactory::NewHandler(FImGuiModuleManager* ModuleManager, UGameViewportClient* GameViewport, int32 ContextIndex)
|
||||
{
|
||||
UClass* HandlerClass = nullptr;
|
||||
@ -22,7 +20,7 @@ UImGuiInputHandler* FImGuiInputHandlerFactory::NewHandler(FImGuiModuleManager* M
|
||||
|
||||
if (!HandlerClass)
|
||||
{
|
||||
UE_LOG(LogImGuiInputHandlerFactory, Error, TEXT("Couldn't load ImGui Input Handler class '%s'."), *HandlerClassReference.ToString());
|
||||
UE_LOG(LogImGuiInputHandler, Error, TEXT("Couldn't load ImGui Input Handler class '%s'."), *HandlerClassReference.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -40,7 +38,7 @@ UImGuiInputHandler* FImGuiInputHandlerFactory::NewHandler(FImGuiModuleManager* M
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogImGuiInputHandlerFactory, Error, TEXT("Failed attempt to create Input Handler: HandlerClass = %s."), *GetNameSafe(HandlerClass));
|
||||
UE_LOG(LogImGuiInputHandler, Error, TEXT("Failed attempt to create Input Handler: HandlerClass = %s."), *GetNameSafe(HandlerClass));
|
||||
}
|
||||
|
||||
return Handler;
|
||||
|
@ -13,7 +13,7 @@
|
||||
#define VALIDATE_INPUT_CHARACTERS 1
|
||||
|
||||
#if VALIDATE_INPUT_CHARACTERS
|
||||
DEFINE_LOG_CATEGORY_STATIC(LogImGuiInputState, Warning, All);
|
||||
DEFINE_LOG_CATEGORY_STATIC(LogImGuiInput, Warning, All);
|
||||
#endif
|
||||
|
||||
namespace
|
||||
@ -34,7 +34,7 @@ namespace
|
||||
// truncations.
|
||||
static constexpr auto MinLimit = (std::numeric_limits<std::make_signed_t<ImWchar>>::min)();
|
||||
static constexpr auto MaxLimit = (std::numeric_limits<std::make_unsigned_t<ImWchar>>::max)();
|
||||
UE_CLOG(!(Char >= MinLimit && Char <= MaxLimit), LogImGuiInputState, Error,
|
||||
UE_CLOG(!(Char >= MinLimit && Char <= MaxLimit), LogImGuiInput, Error,
|
||||
TEXT("TCHAR value '%c' (%#x) is out of range %d (%#x) to %u (%#x) that can be safely converted to ImWchar. ")
|
||||
TEXT("If you wish to disable this validation, please set VALIDATE_INPUT_CHARACTERS in ImGuiInputState.cpp to 0."),
|
||||
Char, Char, MinLimit, MinLimit, MaxLimit, MaxLimit);
|
||||
|
16
Source/ImGui/Private/ImGuiModuleDebug.h
Normal file
16
Source/ImGui/Private/ImGuiModuleDebug.h
Normal file
@ -0,0 +1,16 @@
|
||||
// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Logging/LogMacros.h>
|
||||
|
||||
|
||||
// Module-wide debug symbols and loggers.
|
||||
|
||||
|
||||
// If enabled, it activates debug code and console variables that in normal usage are hidden.
|
||||
#define IMGUI_MODULE_DEVELOPER 0
|
||||
|
||||
|
||||
// Input Handler logger (used also in non-developer mode to raise problems with handler extensions).
|
||||
DECLARE_LOG_CATEGORY_EXTERN(LogImGuiInputHandler, Warning, All);
|
@ -1,8 +1,11 @@
|
||||
// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
|
||||
|
||||
// Module-wide macros
|
||||
#include "VersionCompatibility.h"
|
||||
#include "ImGuiModuleDebug.h"
|
||||
|
||||
// Module
|
||||
#include "ImGuiModule.h"
|
||||
#include "VersionCompatibility.h"
|
||||
|
||||
// Engine
|
||||
#include <Core.h>
|
||||
|
@ -25,8 +25,12 @@
|
||||
constexpr int32 IMGUI_WIDGET_Z_ORDER = 10000;
|
||||
|
||||
|
||||
#if IMGUI_WIDGET_DEBUG
|
||||
|
||||
DEFINE_LOG_CATEGORY_STATIC(LogImGuiWidget, Warning, All);
|
||||
|
||||
#define IMGUI_WIDGET_LOG(Verbosity, Format, ...) UE_LOG(LogImGuiWidget, Verbosity, Format, __VA_ARGS__)
|
||||
|
||||
#define TEXT_INPUT_MODE(Val) (\
|
||||
(Val) == EInputMode::Full ? TEXT("Full") :\
|
||||
(Val) == EInputMode::MousePointerOnly ? TEXT("MousePointerOnly") :\
|
||||
@ -34,6 +38,11 @@ DEFINE_LOG_CATEGORY_STATIC(LogImGuiWidget, Warning, All);
|
||||
|
||||
#define TEXT_BOOL(Val) ((Val) ? TEXT("true") : TEXT("false"))
|
||||
|
||||
#else
|
||||
|
||||
#define IMGUI_WIDGET_LOG(...)
|
||||
|
||||
#endif // IMGUI_WIDGET_DEBUG
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -61,7 +70,11 @@ namespace CVars
|
||||
TEXT("2: gamepad navigation (gamepad input is consumed)\n")
|
||||
TEXT("3: keyboard and gamepad navigation (gamepad input is consumed)"),
|
||||
ECVF_Default);
|
||||
}
|
||||
|
||||
#if IMGUI_WIDGET_DEBUG
|
||||
namespace CVars
|
||||
{
|
||||
TAutoConsoleVariable<int> DebugWidget(TEXT("ImGui.Debug.Widget"), 0,
|
||||
TEXT("Show debug for SImGuiWidget.\n")
|
||||
TEXT("0: disabled (default)\n")
|
||||
@ -74,6 +87,7 @@ namespace CVars
|
||||
TEXT("1: enabled"),
|
||||
ECVF_Default);
|
||||
}
|
||||
#endif // IMGUI_WIDGET_DEBUG
|
||||
|
||||
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
|
||||
void SImGuiWidget::Construct(const FArguments& InArgs)
|
||||
@ -101,7 +115,9 @@ void SImGuiWidget::Construct(const FArguments& InArgs)
|
||||
// Bind this widget to its context proxy.
|
||||
auto* ContextProxy = ModuleManager->GetContextManager().GetContextProxy(ContextIndex);
|
||||
checkf(ContextProxy, TEXT("Missing context during widget construction: ContextIndex = %d"), ContextIndex);
|
||||
#if IMGUI_WIDGET_DEBUG
|
||||
ContextProxy->OnDraw().AddRaw(this, &SImGuiWidget::OnDebugDraw);
|
||||
#endif // IMGUI_WIDGET_DEBUG
|
||||
ContextProxy->SetInputState(&InputState);
|
||||
|
||||
// Cache locally software cursor mode.
|
||||
@ -126,7 +142,9 @@ SImGuiWidget::~SImGuiWidget()
|
||||
// Remove binding between this widget and its context proxy.
|
||||
if (auto* ContextProxy = ModuleManager->GetContextManager().GetContextProxy(ContextIndex))
|
||||
{
|
||||
#if IMGUI_WIDGET_DEBUG
|
||||
ContextProxy->OnDraw().RemoveAll(this);
|
||||
#endif // IMGUI_WIDGET_DEBUG
|
||||
ContextProxy->RemoveInputState(&InputState);
|
||||
}
|
||||
|
||||
@ -323,7 +341,7 @@ FReply SImGuiWidget::OnFocusReceived(const FGeometry& MyGeometry, const FFocusEv
|
||||
{
|
||||
Super::OnFocusReceived(MyGeometry, FocusEvent);
|
||||
|
||||
UE_LOG(LogImGuiWidget, VeryVerbose, TEXT("ImGui Widget %d - Focus Received."), ContextIndex);
|
||||
IMGUI_WIDGET_LOG(VeryVerbose, TEXT("ImGui Widget %d - Focus Received."), ContextIndex);
|
||||
|
||||
// If widget has a keyboard focus we always maintain mouse input. Technically, if mouse is outside of the widget
|
||||
// area it won't generate events but we freeze its state until it either comes back or input is completely lost.
|
||||
@ -337,7 +355,7 @@ void SImGuiWidget::OnFocusLost(const FFocusEvent& FocusEvent)
|
||||
{
|
||||
Super::OnFocusLost(FocusEvent);
|
||||
|
||||
UE_LOG(LogImGuiWidget, VeryVerbose, TEXT("ImGui Widget %d - Focus Lost."), ContextIndex);
|
||||
IMGUI_WIDGET_LOG(VeryVerbose, TEXT("ImGui Widget %d - Focus Lost."), ContextIndex);
|
||||
|
||||
UpdateInputMode(false, IsDirectlyHovered());
|
||||
}
|
||||
@ -346,7 +364,7 @@ void SImGuiWidget::OnMouseEnter(const FGeometry& MyGeometry, const FPointerEvent
|
||||
{
|
||||
Super::OnMouseEnter(MyGeometry, MouseEvent);
|
||||
|
||||
UE_LOG(LogImGuiWidget, VeryVerbose, TEXT("ImGui Widget %d - Mouse Enter."), ContextIndex);
|
||||
IMGUI_WIDGET_LOG(VeryVerbose, TEXT("ImGui Widget %d - Mouse Enter."), ContextIndex);
|
||||
|
||||
// If mouse enters while input is active then we need to update mouse buttons because there is a chance that we
|
||||
// missed some events.
|
||||
@ -365,7 +383,7 @@ void SImGuiWidget::OnMouseLeave(const FPointerEvent& MouseEvent)
|
||||
{
|
||||
Super::OnMouseLeave(MouseEvent);
|
||||
|
||||
UE_LOG(LogImGuiWidget, VeryVerbose, TEXT("ImGui Widget %d - Mouse Leave."), ContextIndex);
|
||||
IMGUI_WIDGET_LOG(VeryVerbose, TEXT("ImGui Widget %d - Mouse Leave."), ContextIndex);
|
||||
|
||||
// We don't get any events when application loses focus, but often this is followed by OnMouseLeave, so we can use
|
||||
// this event to immediately disable keyboard input if application lost focus.
|
||||
@ -497,7 +515,7 @@ void SImGuiWidget::SetVisibilityFromInputEnabled()
|
||||
// If we don't use input disable hit test to make this widget invisible for cursors hit detection.
|
||||
SetVisibility(bInputEnabled ? EVisibility::Visible : EVisibility::HitTestInvisible);
|
||||
|
||||
UE_LOG(LogImGuiWidget, VeryVerbose, TEXT("ImGui Widget %d - Visibility updated to '%s'."),
|
||||
IMGUI_WIDGET_LOG(VeryVerbose, TEXT("ImGui Widget %d - Visibility updated to '%s'."),
|
||||
ContextIndex, *GetVisibility().ToString());
|
||||
}
|
||||
|
||||
@ -508,7 +526,7 @@ void SImGuiWidget::UpdateInputEnabled()
|
||||
{
|
||||
bInputEnabled = bEnabled;
|
||||
|
||||
UE_LOG(LogImGuiWidget, Log, TEXT("ImGui Widget %d - Input Enabled changed to '%s'."),
|
||||
IMGUI_WIDGET_LOG(Log, TEXT("ImGui Widget %d - Input Enabled changed to '%s'."),
|
||||
ContextIndex, TEXT_BOOL(bInputEnabled));
|
||||
|
||||
SetVisibilityFromInputEnabled();
|
||||
@ -568,7 +586,7 @@ void SImGuiWidget::UpdateInputMode(bool bHasKeyboardFocus, bool bHasMousePointer
|
||||
|
||||
if (InputMode != NewInputMode)
|
||||
{
|
||||
UE_LOG(LogImGuiWidget, Verbose, TEXT("ImGui Widget %d - Input Mode changed from '%s' to '%s'."),
|
||||
IMGUI_WIDGET_LOG(Verbose, TEXT("ImGui Widget %d - Input Mode changed from '%s' to '%s'."),
|
||||
ContextIndex, TEXT_INPUT_MODE(InputMode), TEXT_INPUT_MODE(NewInputMode));
|
||||
|
||||
// We need to reset input components if we are either fully shutting down or we are downgrading from full to
|
||||
@ -1048,6 +1066,8 @@ FVector2D SImGuiWidget::ComputeDesiredSize(float) const
|
||||
return FVector2D{ 3840.f, 2160.f };
|
||||
}
|
||||
|
||||
#if IMGUI_WIDGET_DEBUG
|
||||
|
||||
static TArray<FKey> GetImGuiMappedKeys()
|
||||
{
|
||||
TArray<FKey> Keys;
|
||||
@ -1329,3 +1349,7 @@ void SImGuiWidget::OnDebugDraw()
|
||||
|
||||
#undef TEXT_INPUT_MODE
|
||||
#undef TEXT_BOOL
|
||||
|
||||
#endif // IMGUI_WIDGET_DEBUG
|
||||
|
||||
#undef IMGUI_WIDGET_LOG
|
||||
|
@ -3,10 +3,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "ImGuiInputState.h"
|
||||
#include "ImGuiModuleDebug.h"
|
||||
|
||||
#include <Widgets/SLeafWidget.h>
|
||||
|
||||
|
||||
// Hide ImGui Widget debug in non-developer mode.
|
||||
#define IMGUI_WIDGET_DEBUG IMGUI_MODULE_DEVELOPER
|
||||
|
||||
class FImGuiModuleManager;
|
||||
class UImGuiInputHandler;
|
||||
|
||||
@ -151,7 +155,9 @@ private:
|
||||
|
||||
virtual FVector2D ComputeDesiredSize(float) const override;
|
||||
|
||||
#if IMGUI_WIDGET_DEBUG
|
||||
void OnDebugDraw();
|
||||
#endif // IMGUI_WIDGET_DEBUG
|
||||
|
||||
FImGuiModuleManager* ModuleManager = nullptr;
|
||||
TWeakObjectPtr<UGameViewportClient> GameViewport;
|
||||
|
Loading…
Reference in New Issue
Block a user