improve inspector

This commit is contained in:
Arnaud Jamin
2023-10-16 00:00:05 -04:00
parent 667439e5fa
commit da02827408
16 changed files with 468 additions and 256 deletions
@@ -5,30 +5,10 @@
#include "imgui.h"
#include "CogEngineWindow_Inspector.generated.h"
typedef int32 ECogEngineInspectorFlags;
enum ECogEngineInspectorFlags_
{
ECogEngineInspectorFlags_None = 0,
ECogEngineInspectorFlags_ShowDisplayName = 1 << 0,
ECogEngineInspectorFlags_ShowRowBackground = 1 << 1,
ECogEngineInspectorFlags_ShowBorders = 1 << 2,
ECogEngineInspectorFlags_ShowCategories = 1 << 3,
ECogEngineInspectorFlags_SortByName = 1 << 4,
ECogEngineInspectorFlags_CollapseAllCategories = 1 << 5,
ECogEngineInspectorFlags_ExpandAllCategories = 1 << 6,
ECogEngineInspectorFlags_DisplaySearch = 1 << 7,
ECogEngineInspectorFlags_DisplayOptions = 1 << 8,
};
class FCogEngineInspectorHost
{
public:
virtual void InspectObject(const UObject* Object) = 0;
};
using FCogEngineInspectorApplyFunction = TFunction<void(UObject*)>;
UCLASS(Config = Cog)
class COGENGINE_API UCogEngineWindow_Inspector : public UCogWindow, public FCogEngineInspectorHost
class COGENGINE_API UCogEngineWindow_Inspector : public UCogWindow
{
GENERATED_BODY()
@@ -36,46 +16,108 @@ public:
UCogEngineWindow_Inspector();
virtual void InspectObject(const UObject* Object) override;
virtual UObject* GetInspectedObject() const { return InspectedObject.Get(); }
static void RenderMenu(FCogEngineInspectorHost& Host, ImGuiTextFilter& Filter, ECogEngineInspectorFlags& Flags);
static bool RenderInspector(FCogEngineInspectorHost& Host, const UObject* Object, ImGuiTextFilter& Filter, ECogEngineInspectorFlags Flags);
static bool RenderBegin(FCogEngineInspectorHost& Host, ECogEngineInspectorFlags Flags);
static void RenderEnd(FCogEngineInspectorHost& Host);
static bool HasPropertyAnyChildren(FCogEngineInspectorHost& Host, const FProperty* Property, uint8* PointerToValue);
static bool RenderPropertyList(FCogEngineInspectorHost& Host, TArray<const FProperty*>& Properties, uint8* PointerToValue, ECogEngineInspectorFlags Flags);
static bool RenderProperty(FCogEngineInspectorHost& Host, const FProperty* Property, uint8* PointerToValue, int IndexInArray, ECogEngineInspectorFlags Flags);
static bool RenderBool(FCogEngineInspectorHost& Host, const FBoolProperty* BoolProperty, uint8* PointerToValue);
static bool RenderByte(FCogEngineInspectorHost& Host, const FByteProperty* ByteProperty, uint8* PointerToValue);
static bool RenderInt8(FCogEngineInspectorHost& Host, const FInt8Property* Int8Property, uint8* PointerToValue);
static bool RenderInt(FCogEngineInspectorHost& Host, const FIntProperty* IntProperty, uint8* PointerToValue);
static bool RenderInt64(FCogEngineInspectorHost& Host, const FInt64Property* Int64Property, uint8* PointerToValue);
static bool RenderUInt32(FCogEngineInspectorHost& Host, const FUInt32Property* UInt32Property, uint8* PointerToValue);
static bool RenderFloat(FCogEngineInspectorHost& Host, const FFloatProperty* FloatProperty, uint8* PointerToValue);
static bool RenderDouble(FCogEngineInspectorHost& Host, const FDoubleProperty* DoubleProperty, uint8* PointerToValue);
static bool RenderEnum(FCogEngineInspectorHost& Host, const FEnumProperty* EnumProperty, uint8* PointerToValue);
static bool RenderString(FCogEngineInspectorHost& Host, const FStrProperty* StrProperty, uint8* PointerToValue);
static bool RenderName(FCogEngineInspectorHost& Host, const FNameProperty* NameProperty, uint8* PointerToValue);
static bool RenderText(FCogEngineInspectorHost& Host, const FTextProperty* TextProperty, uint8* PointerToValue);
static bool RenderClass(FCogEngineInspectorHost& Host, const FClassProperty* ClassProperty);
static bool RenderInterface(FCogEngineInspectorHost& Host, const FInterfaceProperty* InterfaceProperty);
static bool RenderStruct(FCogEngineInspectorHost& Host, const FStructProperty* StructProperty, uint8* PointerToValue, bool ShowChildren, ECogEngineInspectorFlags Flags);
static bool RenderObject(FCogEngineInspectorHost& Host, UObject* Object, bool ShowChildren, ECogEngineInspectorFlags Flags);
static bool RenderArray(FCogEngineInspectorHost& Host, const FArrayProperty* ArrayProperty, uint8* PointerToValue, bool ShowChildren, ECogEngineInspectorFlags Flags);
static FString GetPropertyName(const FProperty& Property, ECogEngineInspectorFlags Flags);
virtual void SetInspectedObject(UObject* Object);
virtual void AddFavorite(UObject* Object);
virtual void AddFavorite(UObject* Object, FCogEngineInspectorApplyFunction ApplyFunction);
UPROPERTY(Config)
bool bSyncWithSelection = true;
UPROPERTY(Config)
bool bShowDisplayName = true;
UPROPERTY(Config)
bool bShowRowBackground = true;
UPROPERTY(Config)
bool bShowBorders = false;
UPROPERTY(Config)
bool bShowCategories = true;
UPROPERTY(Config)
bool bSortByName = true;
protected:
virtual FString GetTitle() const override;
virtual void RenderHelp() override;
virtual void RenderContent() override;
TWeakObjectPtr<const UObject> InspectedObject = nullptr;
ImGuiTextFilter PropertyFilter;
virtual void RenderMenu();
UPROPERTY(Config)
int32 PropertyGridFlags = 0;
virtual bool RenderInspector();
virtual bool RenderBegin();
virtual void RenderEnd();
virtual bool HasPropertyAnyChildren(const FProperty* Property, uint8* PointerToValue);
virtual bool RenderPropertyList(TArray<const FProperty*>& Properties, uint8* PointerToValue);
virtual bool RenderProperty(const FProperty* Property, uint8* PointerToValue, int IndexInArray);
virtual bool RenderBool(const FBoolProperty* BoolProperty, uint8* PointerToValue);
virtual bool RenderByte(const FByteProperty* ByteProperty, uint8* PointerToValue);
virtual bool RenderInt8(const FInt8Property* Int8Property, uint8* PointerToValue);
virtual bool RenderInt(const FIntProperty* IntProperty, uint8* PointerToValue);
virtual bool RenderInt64(const FInt64Property* Int64Property, uint8* PointerToValue);
virtual bool RenderUInt32(const FUInt32Property* UInt32Property, uint8* PointerToValue);
virtual bool RenderFloat(const FFloatProperty* FloatProperty, uint8* PointerToValue);
virtual bool RenderDouble(const FDoubleProperty* DoubleProperty, uint8* PointerToValue);
virtual bool RenderEnum(const FEnumProperty* EnumProperty, uint8* PointerToValue);
virtual bool RenderString(const FStrProperty* StrProperty, uint8* PointerToValue);
virtual bool RenderName(const FNameProperty* NameProperty, uint8* PointerToValue);
virtual bool RenderText(const FTextProperty* TextProperty, uint8* PointerToValue);
virtual bool RenderClass(const FClassProperty* ClassProperty);
virtual bool RenderInterface(const FInterfaceProperty* InterfaceProperty);
virtual bool RenderStruct(const FStructProperty* StructProperty, uint8* PointerToValue, bool ShowChildren);
virtual bool RenderObject(UObject* Object, bool ShowChildren);
virtual bool RenderArray(const FArrayProperty* ArrayProperty, uint8* PointerToValue, bool ShowChildren);
virtual FString GetPropertyName(const FProperty& Property);
FCogEngineInspectorApplyFunction FindObjectApplyFunction(const UObject* Object) const;
struct Favorite
{
TWeakObjectPtr<UObject> Object = nullptr;
FCogEngineInspectorApplyFunction ApplyFunction = nullptr;
};
TWeakObjectPtr<UObject> InspectedObject = nullptr;
ImGuiTextFilter Filter;
bool bExpandAllCategories = false;
bool bCollapseAllCategories = false;
TArray<Favorite> Favorites;
TArray<TWeakObjectPtr<UObject>> History;
int32 HistoryIndex = INDEX_NONE;
};