Last active
July 26, 2024 02:47
-
-
Save pedrohugorm/f9615e5772bd525b0f7441c41205e168 to your computer and use it in GitHub Desktop.
Unreal C++ ListView with Different Widgets per Row
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UCLASS() | |
class MESHDESIGNER_API UMultiWidgetListView : public UListView | |
{ | |
GENERATED_BODY() | |
public: | |
UPROPERTY(BlueprintReadWrite, EditAnywhere) | |
TMap<FName, TSubclassOf<UUserWidget>> WidgetClassByName; | |
protected: | |
virtual UUserWidget& OnGenerateEntryWidgetInternal( | |
UObject* Item, | |
TSubclassOf<UUserWidget> DesiredEntryClass, | |
const TSharedRef<STableViewBase>& OwnerTable | |
) override; | |
}; | |
//---------- | |
UUserWidget& UMultiWidgetListView::OnGenerateEntryWidgetInternal( | |
UObject* Item, | |
TSubclassOf<UUserWidget> DesiredEntryClass, | |
const TSharedRef<STableViewBase>& OwnerTable | |
) | |
{ | |
if (Item->Implements<UUIFieldsProviderInterface>()) | |
{ | |
const auto TemplateName = IUIFieldsProviderInterface::Execute_GetUITemplateName(Item); | |
if (WidgetClassByName.Contains(TemplateName)) | |
{ | |
return Super::OnGenerateEntryWidgetInternal(Item, WidgetClassByName[TemplateName], OwnerTable); | |
} | |
} | |
return Super::OnGenerateEntryWidgetInternal(Item, DesiredEntryClass, OwnerTable); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment