EnsureVisible() public méthode

Ensures that the list item at the specified index will be visible to the user
public EnsureVisible ( int index ) : void
index int The index of the list item to make visible
Résultat void
Exemple #1
0
	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 );

	}
Exemple #2
0
    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);
    }
Exemple #3
0
    private void openPopup()
    {
        if( popup != null || items.Length == 0 )
            return;

        // Find the top-level parent of this control to attach the popup list to.
        // This is done under the assumption that the top-level control will either be
        // a panel that does not move or a window that does, and that if the parent
        // is moved, the dropdown list will remain in the proper position relative
        // to this control.
        var root = this.GetRootContainer();

        var popupSize = calculatePopupSize();

        // Create the popup list and set all necessary properties
        popup = root.AddControl<dfListbox>();
        popup.name = this.name + " - Dropdown List";
        popup.gameObject.hideFlags = HideFlags.DontSave;
        popup.Atlas = this.Atlas;
        popup.Anchor = dfAnchorStyle.None;
        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.ZOrder = int.MaxValue; // Make sure the popup list is the top control

        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;

            activeScrollbar.transform.parent = popup.transform;
            activeScrollbar.transform.position = scrollbarPosition;

            activeScrollbar.Anchor = dfAnchorStyle.Top | dfAnchorStyle.Bottom;
            activeScrollbar.Height = popup.Height;

            //popup.AddControl( activeScrollbar );
            popup.Width -= activeScrollbar.Width;
            popup.Scrollbar = activeScrollbar;
            //popup.ResetLayout();

            popup.SizeChanged += ( control, size ) =>
            {
                activeScrollbar.Height = control.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.LostFocus += 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 );
    }