TSharedRef<SWidget> UComboBoxString::RebuildWidget() { int32 InitialIndex = FindOptionIndex(SelectedOption); if ( InitialIndex != -1 ) { CurrentOptionPtr = Options[InitialIndex]; } MyComboBox = SNew(SComboBox< TSharedPtr<FString> >) .ComboBoxStyle(&WidgetStyle) .OptionsSource(&Options) .InitiallySelectedItem(CurrentOptionPtr) .ContentPadding(ContentPadding) .MaxListHeight(MaxListHeight) .HasDownArrow(HasDownArrow) .OnGenerateWidget(BIND_UOBJECT_DELEGATE(SComboBox< TSharedPtr<FString> >::FOnGenerateWidget, HandleGenerateWidget)) .OnSelectionChanged(BIND_UOBJECT_DELEGATE(SComboBox< TSharedPtr<FString> >::FOnSelectionChanged, HandleSelectionChanged)) .OnComboBoxOpening(BIND_UOBJECT_DELEGATE(FOnComboBoxOpening, HandleOpening)) [ SAssignNew(ComoboBoxContent, SBox) ]; if ( InitialIndex != -1 ) { // Generate the widget for the initially selected widget if needed ComoboBoxContent->SetContent(HandleGenerateWidget(CurrentOptionPtr)); } return MyComboBox.ToSharedRef(); }
void UComboBoxString::HandleSelectionChanged(TSharedPtr<FString> Item, ESelectInfo::Type SelectionType) { CurrentOptionPtr = Item; if ( !IsDesignTime() ) { OnSelectionChanged.Broadcast(Item.IsValid() ? *Item : FString(), SelectionType); } // When the selection changes we always generate another widget to represent the content area of the comobox. ComoboBoxContent->SetContent( HandleGenerateWidget(Item) ); }
void UComboBoxString::SetSelectedOption(FString Option) { int32 InitialIndex = FindOptionIndex(Option); if (InitialIndex != -1) { CurrentOptionPtr = Options[InitialIndex]; if ( ComoboBoxContent.IsValid() ) { MyComboBox->SetSelectedItem(CurrentOptionPtr); ComoboBoxContent->SetContent(HandleGenerateWidget(CurrentOptionPtr)); } else { SelectedOption = Option; } } }