Skip to content

Instantly share code, notes, and snippets.

@pedrohugorm
Last active July 26, 2024 02:47
Show Gist options
  • Save pedrohugorm/f9615e5772bd525b0f7441c41205e168 to your computer and use it in GitHub Desktop.
Save pedrohugorm/f9615e5772bd525b0f7441c41205e168 to your computer and use it in GitHub Desktop.
Unreal C++ ListView with Different Widgets per Row
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