I wanted to use SSearchableComboBox for the nice searchable ui but it was tied to TSharedPtr<FString>
I did not want to copy the entire thing but C++ came for the rescue, sharing the cursed knowledge.
// The struct. FString has to be first member
struct FMyItemStruct
{
FString DisplayString;
// ... other members ...
}
// The container for combobox populated with MakeShared<FMyItemStruct>(...)
TArray<TSharedPtr<FMyItemStruct>> ComboListItems;
// Combobox itself
SAssignNew(SSearchableComboBox)
.Content()
[
SNew(STextBlock).Font(Font).Text(MakeAttributeSP(this, &ThisClass::GetDisplayText))
]
.OptionsSource( reinterpret_cast<const TArray<TSharedPtr<FString>>*>(&ComboItemList) )
.OnGenerateWidget(this, &ThisClass::OnGenerateComboWidget)
.OnSelectionChanged(this, &ThisClass::OnSelectionChangedInternal)
.SearchVisibility(EVisibility::Visible)
// reinterpret_cast will give access to entire struct at element pointer
TSharedRef<SWidget> OnGenerateComboWidget(TSharedPtr<FString> InElement)
{
auto* TheItem = reinterpret_cast<const FMyItemStruct*>(InElement.Get());
}
void OnSelectionChangedInternal(TSharedPtr<FString> Selected, ESelectInfo::Type)
{
auto* TheItem = reinterpret_cast<const FMyItemStruct*>(InElement.Get());
}