How-To: Lists with Mixed Item Types
Goal: one list (or grid) whose items are different UObject types, each rendered by a different entry widget - without a switch statement.
IUserObjectListEntry as usual for list views.1. Use the Crimson list/tile view
In your screen's Designer, add a Crimson List View (UCrimsonListView) or Crimson Tile View (UCrimsonTileView). They are drop-in UCommonListView/UCommonTileView subclasses that add a factory pipeline for entry-class selection.
2. Add factory rules
Select the view; in Details -> Entry Creation -> FactoryRules, add one Crimson Widget Factory Class (UCrimsonWidgetFactory_Class) per item type: DataClass = the item's class (subclasses match too), WidgetClass = the entry widget. Factories are evaluated by their Priority property, highest first - give the most specific rule the highest priority.
UCrimsonWidgetFactory (Blueprintable) and override its FindWidgetClassForData BlueprintNativeEvent to return a widget class or null to fall through to the next rule.3. Feed it items
Build an Array of Objects mixing both item types, then call Set List Items on the Crimson List View. Each row spawns the widget class its factory rule selected.
See also
- How-To: Build an MVVM Screen - entry ViewModels with a FieldNotify row index.
- How-To: Drag & Drop - dragging entries between views.