// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved. #pragma once /** A delegate type invoked when a selection changes somewhere. */ DECLARE_DELEGATE_RetVal_OneParam(FString, FGetComboItemDisplayString, int32); //Class implementation to create combo box class GRAPHEDITOR_API SPinComboBox : public SCompoundWidget { public: typedef SListView< TSharedPtr > SComboList; typedef TSlateDelegates< TSharedPtr >::FOnSelectionChanged FOnSelectionChanged; SLATE_BEGIN_ARGS( SPinComboBox ){} SLATE_ATTRIBUTE( TArray< TSharedPtr >, ComboItemList ) SLATE_ATTRIBUTE( FString, VisibleText ) SLATE_EVENT( FOnSelectionChanged, OnSelectionChanged ) SLATE_EVENT( FGetComboItemDisplayString, OnGetDisplayName ) SLATE_END_ARGS() //Construct combo box using combo button and combo list void Construct( const FArguments& InArgs ); //Function to return currently selected string const TSharedPtr GetSelectedItem() { return CurrentSelection.Pin(); } private: //Function to set the newly selected item void OnSelectionChangedInternal( TSharedPtr NewSelection, ESelectInfo::Type SelectInfo ); //Get string to display FText OnGetVisibleTextInternal() const { return FText::FromString(VisibleText.Get()); } // Function to create each row of the combo widget TSharedRef OnGenerateComboWidget( TSharedPtr InComboIndex, const TSharedRef& OwnerTable ); FText GetRowString(int32 RowIndex) const { return FText::FromString(OnGetDisplayName.Execute(RowIndex)); } private: /** List of items in our combo box. Only generated once as combo items dont change at runtime */ TArray< TSharedPtr > ComboItemList; TAttribute< FString > VisibleText; TSharedPtr< SComboButton > ComboButton; TSharedPtr< SComboList > ComboList; FOnSelectionChanged OnSelectionChanged; TWeakPtr CurrentSelection; FGetComboItemDisplayString OnGetDisplayName; };