// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "Components/Widget.h" #include "Framework/Views/TreeFilterHandler.h" #include "Misc/TextFilter.h" #include "Framework/SlateDelegates.h" #include "UObject/ObjectPtr.h" #include "WidgetBlueprint.h" #include "Widgets/SCompoundWidget.h" #include "SReadOnlyHierarchyView.generated.h" #define UE_API UMGEDITOR_API class ITableRow; class SSearchBox; class STableViewBase; template class STreeView; template class TreeFilterHandler; template class TTextFilter; UENUM() enum class ERootSelectionMode : uint8 { /** The Root Widget is not selectable */ Disabled, /** The Root Widget is selectable and will show it's name as the display text */ Enabled, /** The Root Widget is selectable and it will show Self as the display text */ Self }; class SReadOnlyHierarchyView : public SCompoundWidget { private: struct FItem { FItem(const UWidget* InWidget) : Widget(InWidget) {} FItem(const UWidgetBlueprint* InWidgetBlueprint) : WidgetBlueprint(InWidgetBlueprint) {} TWeakObjectPtr Widget; TWeakObjectPtr WidgetBlueprint; TArray> Children; }; public: using FOnSelectionChanged = typename TSlateDelegates::FOnSelectionChanged; SLATE_BEGIN_ARGS(SReadOnlyHierarchyView) {} SLATE_ARGUMENT_DEFAULT(bool, ShowSearch) = true; SLATE_ARGUMENT_DEFAULT(ERootSelectionMode, RootSelectionMode) = ERootSelectionMode::Enabled; SLATE_ARGUMENT_DEFAULT(ESelectionMode::Type, SelectionMode) = ESelectionMode::Single; SLATE_EVENT(FOnSelectionChanged, OnSelectionChanged) SLATE_ARGUMENT(TArray, ShowOnly) SLATE_ARGUMENT_DEFAULT(bool, ExpandAll) = true; SLATE_END_ARGS() UE_API virtual ~SReadOnlyHierarchyView(); UE_API void Construct(const FArguments& InArgs, const UWidgetBlueprint* WidgetBlueprint); UE_API void Refresh(); UE_API void SetSelectedWidget(FName WidgetName); UE_API void SetRawFilterText(const FText& Text); UE_API TArray GetSelectedWidgets() const; UE_API void ClearSelection(); private: UE_API TSharedRef GenerateRow(TSharedPtr Item, const TSharedRef& OwnerTable) const; UE_API void GetItemChildren(TSharedPtr Item, TArray>& OutChildren) const; UE_API FText GetItemText(TSharedPtr Item) const; UE_API const FSlateBrush* GetIconBrush(TSharedPtr Item) const; UE_API FText GetIconToolTipText(TSharedPtr Item) const; UE_API FText GetWidgetToolTipText(TSharedPtr Item) const; UE_API void GetFilterStringsForItem(TSharedPtr Item, TArray& OutStrings) const; UE_API TSharedPtr FindItem(const TArray>& RootItems, FName Name) const; UE_API void OnSelectionChanged(TSharedPtr Selected, ESelectInfo::Type SelectionType); UE_API void RebuildTree(); UE_API void BuildWidgetChildren(const UWidget* Widget, TSharedPtr Parent); UE_API void SetItemExpansionRecursive(TSharedPtr Item, bool bShouldBeExpanded); UE_API void ExpandAll(); UE_API FName GetItemName(const TSharedPtr& Item) const; private: TWeakObjectPtr WidgetBlueprint; TArray ShowOnly; TArray> RootWidgets; TArray> FilteredRootWidgets; ERootSelectionMode RootSelectionMode; FOnSelectionChanged OnSelectionChangedDelegate; TSharedPtr SearchBox; using FTextFilter = TTextFilter>; TSharedPtr SearchFilter; using FTreeFilterHandler = TreeFilterHandler>; TSharedPtr FilterHandler; TSharedPtr>> TreeView; bool bExpandAll; }; #undef UE_API