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.
Prerequisites
Item data as UObjects (list views bind UObjects to entry widgets) and one entry widget Blueprint per item type, each implementing
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.
Screenshot pending
Images/CrimsonUI/howto-listview-factories.pngCustom matching logic
For matching beyond 'is a subclass of X' (by interface, by property), subclass
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
Screenshot pending
Images/CrimsonUI/howto-listview-setitems-bp.pngVerify
A mixed array renders each item with its own entry widget class. An item matching no rule falls back to the view's normal Entry Widget Class.
See also
- How-To: Build an MVVM Screen - entry ViewModels with a FieldNotify row index.
- How-To: Drag & Drop - dragging entries between views.