public void OpenPopup()
{
if( popup != null || items.Length == 0 )
return;
var popupSize = calculatePopupSize();
// Create the popup list and set all necessary properties
popup = GetManager().AddControl<dfListbox>();
popup.name = this.name + " - Dropdown List";
popup.gameObject.hideFlags = HideFlags.DontSave;
popup.Atlas = this.Atlas;
popup.Anchor = dfAnchorStyle.Left | dfAnchorStyle.Top;
popup.Color = this.Color;
popup.Font = this.Font;
popup.Pivot = dfPivotPoint.TopLeft;
popup.Size = popupSize;
popup.Font = this.Font;
popup.ItemHeight = this.ItemHeight;
popup.ItemHighlight = this.ItemHighlight;
popup.ItemHover = this.ItemHover;
popup.ItemPadding = this.TextFieldPadding;
popup.ItemTextColor = this.TextColor;
popup.ItemTextScale = this.TextScale;
popup.Items = this.Items;
popup.ListPadding = this.ListPadding;
popup.BackgroundSprite = this.ListBackground;
popup.Shadow = this.Shadow;
popup.ShadowColor = this.ShadowColor;
popup.ShadowOffset = this.ShadowOffset;
popup.BringToFront();
// If there is a modal control/window up that displays this dropdown,
// need to ensure that it is able to receive input
if( dfGUIManager.GetModalControl() != null )
{
dfGUIManager.PushModal( popup );
}
if( popupSize.y >= MaxListHeight && listScrollbar != null )
{
var scrollGO = GameObject.Instantiate( listScrollbar.gameObject ) as GameObject;
var activeScrollbar = scrollGO.GetComponent<dfScrollbar>();
var p2u = PixelsToUnits();
var right = popup.transform.TransformDirection( Vector3.right );
var scrollbarPosition = popup.transform.position + right * ( popupSize.x - activeScrollbar.Width ) * p2u;
popup.AddControl( activeScrollbar );
popup.Width -= activeScrollbar.Width;
popup.Scrollbar = activeScrollbar;
popup.SizeChanged += ( control, size ) =>
{
activeScrollbar.Height = control.Height;
};
activeScrollbar.transform.parent = popup.transform;
activeScrollbar.transform.position = scrollbarPosition;
activeScrollbar.Anchor = dfAnchorStyle.Top | dfAnchorStyle.Bottom;
activeScrollbar.Height = popup.Height;
}
// Position the dropdown and set its rotation to the same world rotation
// as this control
var popupPosition = calculatePopupPosition( (int)popup.Size.y );
popup.transform.position = popupPosition;
popup.transform.rotation = this.transform.rotation;
// Attach important events
popup.SelectedIndexChanged += popup_SelectedIndexChanged;
popup.LeaveFocus += popup_LostFocus;
popup.ItemClicked += popup_ItemClicked;
popup.KeyDown += popup_KeyDown;
// Make sure that the selected item is visible
popup.SelectedIndex = Mathf.Max( 0, this.SelectedIndex );
popup.EnsureVisible( popup.SelectedIndex );
// Make sure that the popup has input focus
popup.Focus();
// Notify any listeners that the popup has been displayed
if( DropdownOpen != null )
{
bool overridden = false;
DropdownOpen( this, popup, ref overridden );
}
Signal( "OnDropdownOpen", this, popup );
}