Add configurable docking flag

This commit is contained in:
Kevin Poretti 2024-11-23 18:27:50 -05:00
parent b58d17177e
commit c8e465ce2d
6 changed files with 44 additions and 8 deletions

View File

@ -3,6 +3,7 @@
#include "ImGuiInteroperability.h" #include "ImGuiInteroperability.h"
#include "ImGuiInputState.h" #include "ImGuiInputState.h"
#include "ImGuiModule.h"
#include "Utilities/Arrays.h" #include "Utilities/Arrays.h"
@ -429,7 +430,8 @@ namespace ImGuiInterops
SetFlag(IO.ConfigFlags, ImGuiConfigFlags_NavEnableKeyboard, InputState.IsKeyboardNavigationEnabled()); SetFlag(IO.ConfigFlags, ImGuiConfigFlags_NavEnableKeyboard, InputState.IsKeyboardNavigationEnabled());
SetFlag(IO.ConfigFlags, ImGuiConfigFlags_NavEnableGamepad, InputState.IsGamepadNavigationEnabled()); SetFlag(IO.ConfigFlags, ImGuiConfigFlags_NavEnableGamepad, InputState.IsGamepadNavigationEnabled());
SetFlag(IO.BackendFlags, ImGuiBackendFlags_HasGamepad, InputState.HasGamepad()); SetFlag(IO.BackendFlags, ImGuiBackendFlags_HasGamepad, InputState.HasGamepad());
SetFlag(IO.ConfigFlags, ImGuiConfigFlags_DockingEnable, FImGuiModule::Get().GetProperties().IsDockingEnabled());
// Check whether we need to draw cursor. // Check whether we need to draw cursor.
IO.MouseDrawCursor = InputState.HasMousePointer(); IO.MouseDrawCursor = InputState.HasMousePointer();
@ -438,23 +440,17 @@ namespace ImGuiInterops
{ {
// Copy the touch position to mouse position. // Copy the touch position to mouse position.
IO.AddMousePosEvent(InputState.GetTouchPosition().X, InputState.GetTouchPosition().Y); IO.AddMousePosEvent(InputState.GetTouchPosition().X, InputState.GetTouchPosition().Y);
//IO.MousePos.x = InputState.GetTouchPosition().X;
//IO.MousePos.y = InputState.GetTouchPosition().Y;
// With touch active one frame longer than it is down, we have one frame to processed touch up. // With touch active one frame longer than it is down, we have one frame to processed touch up.
IO.AddMouseButtonEvent(0, InputState.IsTouchDown()); IO.AddMouseButtonEvent(0, InputState.IsTouchDown());
//IO.MouseDown[0] = InputState.IsTouchDown();
} }
else else
{ {
// Copy the mouse position. // Copy the mouse position.
IO.AddMousePosEvent(InputState.GetMousePosition().X, InputState.GetMousePosition().Y); IO.AddMousePosEvent(InputState.GetMousePosition().X, InputState.GetMousePosition().Y);
//IO.MousePos.x = InputState.GetMousePosition().X;
//IO.MousePos.y = InputState.GetMousePosition().Y;
// Copy mouse wheel delta. // Copy mouse wheel delta.
IO.AddMouseWheelEvent(0, IO.MouseWheel + InputState.GetMouseWheelDelta()); IO.AddMouseWheelEvent(0, IO.MouseWheel + InputState.GetMouseWheelDelta());
//IO.MouseWheel += InputState.GetMouseWheelDelta();
} }
} }
} }

View File

@ -12,6 +12,7 @@ const TCHAR* const FImGuiModuleCommands::ToggleGamepadNavigation = TEXT("ImGui.T
const TCHAR* const FImGuiModuleCommands::ToggleKeyboardInputSharing = TEXT("ImGui.ToggleKeyboardInputSharing"); const TCHAR* const FImGuiModuleCommands::ToggleKeyboardInputSharing = TEXT("ImGui.ToggleKeyboardInputSharing");
const TCHAR* const FImGuiModuleCommands::ToggleGamepadInputSharing = TEXT("ImGui.ToggleGamepadInputSharing"); const TCHAR* const FImGuiModuleCommands::ToggleGamepadInputSharing = TEXT("ImGui.ToggleGamepadInputSharing");
const TCHAR* const FImGuiModuleCommands::ToggleMouseInputSharing = TEXT("ImGui.ToggleMouseInputSharing"); const TCHAR* const FImGuiModuleCommands::ToggleMouseInputSharing = TEXT("ImGui.ToggleMouseInputSharing");
const TCHAR* const FImGuiModuleCommands::ToggleDockingEnabled = TEXT("ImGui.ToggleDockingEnabled");
const TCHAR* const FImGuiModuleCommands::SetMouseInputSharing = TEXT("ImGui.SetMouseInputSharing"); const TCHAR* const FImGuiModuleCommands::SetMouseInputSharing = TEXT("ImGui.SetMouseInputSharing");
const TCHAR* const FImGuiModuleCommands::ToggleDemo = TEXT("ImGui.ToggleDemo"); const TCHAR* const FImGuiModuleCommands::ToggleDemo = TEXT("ImGui.ToggleDemo");
@ -35,6 +36,9 @@ FImGuiModuleCommands::FImGuiModuleCommands(FImGuiModuleProperties& InProperties)
, ToggleMouseInputSharingCommand(ToggleMouseInputSharing, , ToggleMouseInputSharingCommand(ToggleMouseInputSharing,
TEXT("Toggle ImGui mouse input sharing."), TEXT("Toggle ImGui mouse input sharing."),
FConsoleCommandDelegate::CreateRaw(this, &FImGuiModuleCommands::ToggleMouseInputSharingImpl)) FConsoleCommandDelegate::CreateRaw(this, &FImGuiModuleCommands::ToggleMouseInputSharingImpl))
, ToggleDockingEnabledCommand(ToggleDockingEnabled,
TEXT("Toggle ImGui docking."),
FConsoleCommandDelegate::CreateRaw(this, &FImGuiModuleCommands::ToggleDockingEnabledImpl))
, SetMouseInputSharingCommand(SetMouseInputSharing, , SetMouseInputSharingCommand(SetMouseInputSharing,
TEXT("Toggle ImGui mouse input sharing."), TEXT("Toggle ImGui mouse input sharing."),
FConsoleCommandWithArgsDelegate::CreateRaw(this, &FImGuiModuleCommands::SetMouseInputSharingImpl)) FConsoleCommandWithArgsDelegate::CreateRaw(this, &FImGuiModuleCommands::SetMouseInputSharingImpl))
@ -79,6 +83,11 @@ void FImGuiModuleCommands::ToggleMouseInputSharingImpl()
Properties.ToggleMouseInputSharing(); Properties.ToggleMouseInputSharing();
} }
void FImGuiModuleCommands::ToggleDockingEnabledImpl()
{
Properties.ToggleDockingEnabled();
}
void FImGuiModuleCommands::SetMouseInputSharingImpl(const TArray<FString>& Args) void FImGuiModuleCommands::SetMouseInputSharingImpl(const TArray<FString>& Args)
{ {
bool bIsEnabled = false; bool bIsEnabled = false;

View File

@ -19,6 +19,7 @@ public:
static const TCHAR* const ToggleKeyboardInputSharing; static const TCHAR* const ToggleKeyboardInputSharing;
static const TCHAR* const ToggleGamepadInputSharing; static const TCHAR* const ToggleGamepadInputSharing;
static const TCHAR* const ToggleMouseInputSharing; static const TCHAR* const ToggleMouseInputSharing;
static const TCHAR* const ToggleDockingEnabled;
static const TCHAR* const SetMouseInputSharing; static const TCHAR* const SetMouseInputSharing;
static const TCHAR* const ToggleDemo; static const TCHAR* const ToggleDemo;
@ -34,6 +35,7 @@ private:
void ToggleKeyboardInputSharingImpl(); void ToggleKeyboardInputSharingImpl();
void ToggleGamepadInputSharingImpl(); void ToggleGamepadInputSharingImpl();
void ToggleMouseInputSharingImpl(); void ToggleMouseInputSharingImpl();
void ToggleDockingEnabledImpl();
void SetMouseInputSharingImpl(const TArray< FString >& Args); void SetMouseInputSharingImpl(const TArray< FString >& Args);
void ToggleDemoImpl(); void ToggleDemoImpl();
@ -45,6 +47,7 @@ private:
FAutoConsoleCommand ToggleKeyboardInputSharingCommand; FAutoConsoleCommand ToggleKeyboardInputSharingCommand;
FAutoConsoleCommand ToggleGamepadInputSharingCommand; FAutoConsoleCommand ToggleGamepadInputSharingCommand;
FAutoConsoleCommand ToggleMouseInputSharingCommand; FAutoConsoleCommand ToggleMouseInputSharingCommand;
FAutoConsoleCommand ToggleDockingEnabledCommand;
FAutoConsoleCommand SetMouseInputSharingCommand; FAutoConsoleCommand SetMouseInputSharingCommand;
FAutoConsoleCommand ToggleDemoCommand; FAutoConsoleCommand ToggleDemoCommand;
}; };

View File

@ -182,6 +182,15 @@ void FImGuiModuleSettings::SetToggleInputKey(const FImGuiKeyInfo& KeyInfo)
} }
} }
void FImGuiModuleSettings::SetIsDockingEnabled(bool bDockingEnabled)
{
if (bIsDockingEnabled != bDockingEnabled)
{
bIsDockingEnabled = bDockingEnabled;
Properties.SetDockingEnabled(bDockingEnabled);
}
}
void FImGuiModuleSettings::SetCanvasSizeInfo(const FImGuiCanvasSizeInfo& CanvasSizeInfo) void FImGuiModuleSettings::SetCanvasSizeInfo(const FImGuiCanvasSizeInfo& CanvasSizeInfo)
{ {
if (CanvasSize != CanvasSizeInfo) if (CanvasSize != CanvasSizeInfo)

View File

@ -196,12 +196,18 @@ protected:
UPROPERTY(EditAnywhere, config, Category = "Input") UPROPERTY(EditAnywhere, config, Category = "Input")
bool bShareMouseInput = false; bool bShareMouseInput = false;
// Whether docking should be enabled.
// This defines initial behaviour which can be later changed using 'ImGui.ToggleDockingEnabled' command or
// module properties interface.
UPROPERTY(EditAnywhere, config, Category = "Input")
bool bIsDockingEnabled = true;
// If true, then in input mode ImGui will draw its own cursor in place of the hardware one. // If true, then in input mode ImGui will draw its own cursor in place of the hardware one.
// When disabled (default) there is a noticeable difference between cursor position seen by ImGui and position on // When disabled (default) there is a noticeable difference between cursor position seen by ImGui and position on
// the screen. Enabling this option removes that effect but with lower frame-rates UI becomes quickly unusable. // the screen. Enabling this option removes that effect but with lower frame-rates UI becomes quickly unusable.
UPROPERTY(EditAnywhere, config, Category = "Input", AdvancedDisplay) UPROPERTY(EditAnywhere, config, Category = "Input", AdvancedDisplay)
bool bUseSoftwareCursor = false; bool bUseSoftwareCursor = false;
// Define a shortcut key to 'ImGui.ToggleInput' command. Binding is only set if the key field is valid. // Define a shortcut key to 'ImGui.ToggleInput' command. Binding is only set if the key field is valid.
// Note that modifier key properties can be set to one of the three values: undetermined means that state of the given // Note that modifier key properties can be set to one of the three values: undetermined means that state of the given
// modifier is not important, checked means that it needs to be pressed and unchecked means that it cannot be pressed. // modifier is not important, checked means that it needs to be pressed and unchecked means that it cannot be pressed.
@ -291,6 +297,7 @@ private:
void SetShareMouseInput(bool bShare); void SetShareMouseInput(bool bShare);
void SetUseSoftwareCursor(bool bUse); void SetUseSoftwareCursor(bool bUse);
void SetToggleInputKey(const FImGuiKeyInfo& KeyInfo); void SetToggleInputKey(const FImGuiKeyInfo& KeyInfo);
void SetIsDockingEnabled(bool bDockingEnabled);
void SetCanvasSizeInfo(const FImGuiCanvasSizeInfo& CanvasSizeInfo); void SetCanvasSizeInfo(const FImGuiCanvasSizeInfo& CanvasSizeInfo);
void SetDPIScaleInfo(const FImGuiDPIScaleInfo& ScaleInfo); void SetDPIScaleInfo(const FImGuiDPIScaleInfo& ScaleInfo);
@ -309,4 +316,5 @@ private:
bool bShareGamepadInput = false; bool bShareGamepadInput = false;
bool bShareMouseInput = false; bool bShareMouseInput = false;
bool bUseSoftwareCursor = false; bool bUseSoftwareCursor = false;
bool bIsDockingEnabled = true;
}; };

View File

@ -72,6 +72,15 @@ public:
/** Toggle ImGui demo. */ /** Toggle ImGui demo. */
void ToggleDemo() { SetShowDemo(!ShowDemo()); } void ToggleDemo() { SetShowDemo(!ShowDemo()); }
/** Check whether docking is enabled. */
bool IsDockingEnabled() const { return bIsDockingEnabled; }
/** Set whether docking is enabled. */
void SetDockingEnabled(bool bDockingEnabled) { bIsDockingEnabled = bDockingEnabled; }
/** Toggle whether docking is enabled. */
void ToggleDockingEnabled() { SetDockingEnabled(!IsDockingEnabled()); }
/** Adds a new font to initialize */ /** Adds a new font to initialize */
void AddCustomFont(FName FontName, TSharedPtr<ImFontConfig> Font) { CustomFonts.Emplace(FontName, Font); } void AddCustomFont(FName FontName, TSharedPtr<ImFontConfig> Font) { CustomFonts.Emplace(FontName, Font); }
@ -94,5 +103,7 @@ private:
bool bShowDemo = false; bool bShowDemo = false;
bool bIsDockingEnabled = true;
TMap<FName, TSharedPtr<ImFontConfig>> CustomFonts; TMap<FName, TSharedPtr<ImFontConfig>> CustomFonts;
}; };