/// <summary>
        /// Populates and displays a custom popup.
        /// </summary>
        /// <example>
        /// <code language="csharp"><![CDATA[
        /// public static TValue MyCustomPopup<TValue>(
        ///     Rect position,
        ///     GUIContent valueLabel,
        ///     TValue value,
        ///     CustomPopupPopulateDelegate<TValue> populatePopupDelegate)
        /// {
        ///     int popupControlID = GUIUtility.GetControlID(FocusType.Passive);
        ///     if (EditorGUI.DropdownButton(position, valueLabel, FocusType.Keyboard)) {
        ///         CustomPopupGUI.DisplayPopup(position, popupControlID, value, populatePopupDelegate);
        ///     }
        ///     return CustomPopupGUI.HandlePopupValueSelection(popupControlID, value);
        /// }
        /// ]]></code>
        /// </example>
        /// <typeparam name="TValue">The type of value that is being selected.</typeparam>
        /// <param name="position">Absolute position of control on the GUI.</param>
        /// <param name="popupControlID">Control ID of the popup.</param>
        /// <param name="value">Current value selection.</param>
        /// <param name="populatePopupDelegate">Delegate that populates popup menu.</param>
        /// <seealso cref="HandlePopupValueSelection{TValue}(int, TValue)"/>
        public static void DisplayPopup <TValue>(Rect position, int popupControlID, TValue value, CustomPopupPopulateDelegate <TValue> populatePopupDelegate)
        {
            SetActivePopupControl(popupControlID, value);

            var popup   = new CustomPopup <TValue>();
            var context = new PopupContext <TValue>(popup, value);

            populatePopupDelegate.Invoke(context);

            popup.ShowAsDropdown(position);
        }
 public PopupContext(CustomPopup <TValue> popup, TValue currentValue)
 {
     this.Popup        = popup;
     this.CurrentValue = currentValue;
 }