Example #1
0
        public void Init(Rect buttonRect)
        {
            m_ButtonRectScreenPos = EditorGUIUtility.GUIToScreenRect(buttonRect);
            if (dataSource == null)
            {
                dataSource = new MultiLevelDataSource();
            }
            if (gui == null)
            {
                gui = new AdvancedDropdownGUI(dataSource);
            }
            selectionChanged += dataSource.UpdateSelectedId;

            // Has to be done before calling Show / ShowWithMode
            buttonRect = GUIUtility.GUIToScreenRect(buttonRect);

            OnDirtyList();

            m_CurrentlyRenderedTree = hasSearch ? dataSource.searchTree : dataSource.mainTree;
            ShowAsDropDown(buttonRect, CalculateWindowSize(buttonRect), GetLocationPriority());

            if (setInitialSelectionPosition)
            {
                m_InitialSelectionPosition = gui.GetSelectionHeight(dataSource, buttonRect);
            }
            wantsMouseMove = true;
        }
        public float GetSelectionHeight(AdvancedDropdownDataSource dataSource, Rect buttonRect)
        {
            if (dataSource.mainTree.selectedItem == -1)
            {
                return(0);
            }
            float heigth = 0;

            for (int i = 0; i < dataSource.mainTree.children.Count; i++)
            {
                var child   = dataSource.mainTree.children[i];
                var content = child.content;

                if (dataSource.mainTree.selectedItem == i)
                {
                    var diff = (lineStyle.CalcHeight(content, 0) - buttonRect.height) / 2f;
                    return(heigth + diff);
                }
                if (child.IsSeparator())
                {
                    heigth += Styles.lineSeparator.CalcHeight(content, 0) + Styles.lineSeparator.margin.vertical;
                }
                else
                {
                    heigth += lineStyle.CalcHeight(content, 0);
                }
            }
            return(heigth);
        }
        public Vector2 CalculateContentSize(AdvancedDropdownDataSource dataSource)
        {
            float maxWidth     = 0;
            float maxHeight    = 0;
            bool  includeArrow = false;
            float arrowWidth   = Styles.rightArrow.fixedWidth;

            foreach (var child in dataSource.mainTree.children)
            {
                var content = child.content;
                var a       = lineStyle.CalcSize(content);
                a.x += iconSize.x + 1;

                if (maxWidth < a.x)
                {
                    maxWidth      = a.x + 1;
                    includeArrow |= child.hasChildren;
                }
                if (child.IsSeparator())
                {
                    maxHeight += Styles.lineSeparator.CalcHeight(content, maxWidth) + Styles.lineSeparator.margin.vertical;
                }
                else
                {
                    maxHeight += lineStyle.CalcHeight(content, maxWidth);
                }
            }
            if (includeArrow)
            {
                maxWidth += arrowWidth;
            }
            return(new Vector2(maxWidth, maxHeight));
        }
Example #4
0
 public AddComponentGUI(AdvancedDropdownDataSource dataSource) : base(dataSource)
 {
 }
 public AdvancedDropdownGUI(AdvancedDropdownDataSource dataSource)
 {
     m_DataSource = dataSource;
 }