示例#1
0
        internal float GetSelectionHeight(AdvancedDropdownDataSource dataSource, Rect buttonRect)
        {
            if (State.GetSelectedIndex(dataSource.MainTree) == -1)
            {
                return(0);
            }

            float heigth = 0;

            for (int i = 0; i < dataSource.MainTree.Children.Count(); i++)
            {
                AdvancedDropdownItem child   = dataSource.MainTree.Children.ElementAt(i);
                GUIContent           content = new GUIContent(child.Name, child.Icon);
                if (State.GetSelectedIndex(dataSource.MainTree) == i)
                {
                    float 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);
        }
示例#2
0
        internal Vector2 CalculateContentSize(AdvancedDropdownDataSource dataSource)
        {
            float maxWidth     = 0;
            float maxHeight    = 0;
            bool  includeArrow = false;
            float arrowWidth   = 0;

            foreach (AdvancedDropdownItem child in dataSource.MainTree.Children)
            {
                GUIContent content = new GUIContent(child.Name, child.Icon);
                Vector2    a       = LineStyle.CalcSize(content);
                a.x += IconSize.x + 1;

                if (maxWidth < a.x)
                {
                    maxWidth      = a.x + 1;
                    includeArrow |= child.Children.Any();
                }

                if (child.IsSeparator())
                {
                    maxHeight += Styles.lineSeparator.CalcHeight(content, maxWidth) + Styles.lineSeparator.margin.vertical;
                }
                else
                {
                    maxHeight += LineStyle.CalcHeight(content, maxWidth);
                }

                if (arrowWidth == 0)
                {
                    LineStyle.CalcMinMaxWidth(Styles.arrowRightContent, out arrowWidth, out arrowWidth);
                }
            }

            if (includeArrow)
            {
                maxWidth += arrowWidth;
            }

            return(new Vector2(maxWidth, maxHeight));
        }