Exemple #1
0
        Rect DrawIndent(Rect rect, ThreadTreeViewItem item, ref RowGUIArgs args)
        {
            // The rect is assumed indented and sized after the content when pinging
            float indent = GetContentIndent(item) + extraSpaceBeforeIconAndLabel;

            rect.xMin += indent;

            int iconRectWidth            = 16;
            int kSpaceBetweenIconAndText = 2;

            // Draw icon
            Rect iconRect = rect;

            iconRect.width = iconRectWidth;
            // iconRect.x += 7f;

            Texture icon = args.item.icon;

            if (icon != null)
            {
                GUI.DrawTexture(iconRect, icon, ScaleMode.ScaleToFit);
            }

            rect.xMin += icon == null ? 0 : iconRectWidth + kSpaceBetweenIconAndText;

            return(rect);
        }
Exemple #2
0
        string GetItemDisplayText(ThreadTreeViewItem item)
        {
            int selectedChildren;
            int childCount = GetChildCount(item.threadIdentifier, out selectedChildren);

            string fullThreadName = item.threadIdentifier.name;
            string groupName;
            string threadName = ProfileData.GetThreadNameWithoutGroup(fullThreadName, out groupName);

            string displayThreadName = multiColumnHeader.IsColumnVisible((int)MyColumns.GroupName) ? threadName : fullThreadName;

            string text;

            if (childCount <= 1)
            {
                text = item.displayName;
            }
            else if (selectedChildren != childCount)
            {
                text = string.Format("{0} ({1} of {2})", displayThreadName, selectedChildren, childCount);
            }
            else
            {
                text = string.Format("{0} (All)", displayThreadName);
            }

            return(text);
        }
Exemple #3
0
        string GetStateSort(ThreadTreeViewItem item)
        {
            ThreadSelected threadSelected = GetThreadSelectedState(item.threadIdentifier);

            string sortString = ((int)threadSelected).ToString() + GetItemDisplayText(item);

            return(sortString);
        }
        protected override void RowGUI(RowGUIArgs args)
        {
            ThreadTreeViewItem item = (ThreadTreeViewItem)args.item;

            for (int i = 0; i < args.GetNumVisibleColumns(); ++i)
            {
                CellGUI(args.GetCellRect(i), item, (MyColumns)args.GetColumn(i), ref args);
            }
        }
        string GetItemGroupName(ThreadTreeViewItem item)
        {
            string groupName;
            string threadName = item.threadIdentifier.name;

            threadName = ProfileData.GetThreadNameWithoutGroup(item.threadIdentifier.name, out groupName);

            return(groupName);
        }
        protected override TreeViewItem BuildRoot()
        {
            int idForHiddenRoot      = -1;
            int depthForHiddenRoot   = -1;
            ProfileTreeViewItem root = new ProfileTreeViewItem(idForHiddenRoot, depthForHiddenRoot, "root", null);

            int depth = 0;

            var top = new ThreadTreeViewItem(-1, depth, m_AllThreadIdentifier.name, m_AllThreadIdentifier);

            root.AddChild(top);

            var expandList = new List <int>()
            {
                -1
            };
            string       lastThreadName = "";
            TreeViewItem node           = root;

            for (int index = 0; index < m_ThreadNames.Count; ++index)
            {
                var threadNameWithIndex = m_ThreadNames[index];
                if (threadNameWithIndex == m_AllThreadIdentifier.threadNameWithIndex)
                {
                    continue;
                }

                var threadIdentifier = new ThreadIdentifier(threadNameWithIndex);
                var item             = new ThreadTreeViewItem(index, depth, m_ThreadUINames[index], threadIdentifier);

                if (threadIdentifier.name != lastThreadName)
                {
                    // New threads at root
                    node  = top;
                    depth = 0;
                }

                node.AddChild(item);


                if (threadIdentifier.name != lastThreadName)
                {
                    // Extra instances hang of the parent
                    lastThreadName = threadIdentifier.name;
                    node           = item;
                    depth          = 1;
                }
            }

            SetExpanded(expandList);

            SetupDepthsFromParentsAndChildren(root);

            return(root);
        }
Exemple #7
0
        void GetThreadTreeViewItemInfo(ThreadTreeViewItem item, out string text, out string tooltip)
        {
            text = GetItemDisplayText(item);
            int selectedChildren;
            int childCount = GetChildCount(item.threadIdentifier, out selectedChildren);

            string groupName = GetItemGroupName(item);

            if (childCount <= 1)
            {
                tooltip = (groupName == "") ? text : string.Format("{0}\n{1}", text, groupName);
            }
            else if (selectedChildren != childCount)
            {
                tooltip = (groupName == "") ? text : string.Format("{0}\n{1}", text, groupName);
            }
            else
            {
                tooltip = (groupName == "") ? text : string.Format("{0}\n{1}", text, groupName);
            }
        }
        void CellGUI(Rect cellRect, ThreadTreeViewItem item, MyColumns column, ref RowGUIArgs args)
        {
            // Center cell rect vertically (makes it easier to place controls, icons etc in the cells)
            CenterRectUsingSingleLineHeight(ref cellRect);

            switch (column)
            {
            case MyColumns.ThreadName:
            {
                args.rowRect = cellRect;
                // base.RowGUI(args);    // Required to show tree indenting

                // Draw manually to keep indenting by add a tooltip
                Rect rect = cellRect;
                if (Event.current.rawType == EventType.Repaint)
                {
                    int selectedChildren;
                    int childCount = GetChildCount(item.threadIdentifier, out selectedChildren);

                    string text;
                    string tooltip;
                    string fullThreadName = item.threadIdentifier.name;
                    string groupName      = GetItemGroupName(item);
                    // string threadName = ProfileData.GetThreadNameWithoutGroup(fullThreadName, out groupName);

                    if (childCount <= 1)
                    {
                        text    = item.displayName;
                        tooltip = (groupName == "") ? text : string.Format("{0}\n{1}", text, groupName);
                    }
                    else if (selectedChildren != childCount)
                    {
                        text    = string.Format("{0} ({1} of {2})", fullThreadName, selectedChildren, childCount);
                        tooltip = (groupName == "") ? text : string.Format("{0}\n{1}", text, groupName);
                    }
                    else
                    {
                        text    = string.Format("{0} (All)", fullThreadName);
                        tooltip = (groupName == "") ? text : string.Format("{0}\n{1}", text, groupName);
                    }
                    var content = new GUIContent(text, tooltip);

                    if (activeLineStyle == null)
                    {
                        // activeLineStyle = DefaultStyles.boldLabel;
                        activeLineStyle = new GUIStyle(DefaultStyles.label);
                        activeLineStyle.normal.textColor = DefaultStyles.boldLabel.onActive.textColor;
                    }

                    // The rect is assumed indented and sized after the content when pinging
                    float indent = GetContentIndent(item) + extraSpaceBeforeIconAndLabel;
                    rect.xMin += indent;

                    int iconRectWidth            = 16;
                    int kSpaceBetweenIconAndText = 2;

                    // Draw icon
                    Rect iconRect = rect;
                    iconRect.width = iconRectWidth;
                    // iconRect.x += 7f;

                    Texture icon = args.item.icon;
                    if (icon != null)
                    {
                        GUI.DrawTexture(iconRect, icon, ScaleMode.ScaleToFit);
                    }

                    rect.xMin += icon == null ? 0 : iconRectWidth + kSpaceBetweenIconAndText;

                    //bool mouseOver = rect.Contains(Event.current.mousePosition);
                    //DefaultStyles.label.Draw(rect, content, mouseOver, false, args.selected, args.focused);

                    // Must use this call to draw tooltip
                    EditorGUI.LabelField(rect, content, args.selected ? activeLineStyle : DefaultStyles.label);
                }
            }
            break;

            case MyColumns.GroupName:
            {
                string groupName = GetItemGroupName(item);
                var    content   = new GUIContent(groupName, groupName);
                EditorGUI.LabelField(cellRect, content);
            }
            break;

            case MyColumns.State:
                bool oldState = ThreadSelected(item.threadIdentifier);
                bool newState = EditorGUI.Toggle(cellRect, oldState);
                if (newState != oldState)
                {
                    if (item.threadIdentifier.threadNameWithIndex == m_AllThreadIdentifier.threadNameWithIndex)
                    {
                        // Record active groups
                        m_ThreadSelection.groups.Clear();
                        if (newState)
                        {
                            if (!m_ThreadSelection.groups.Contains(item.threadIdentifier.threadNameWithIndex))
                            {
                                m_ThreadSelection.groups.Add(item.threadIdentifier.threadNameWithIndex);
                            }
                        }

                        // Update selection
                        m_ThreadSelection.selection.Clear();
                        if (newState)
                        {
                            foreach (string threadNameWithIndex in m_ThreadNames)
                            {
                                if (threadNameWithIndex != m_AllThreadIdentifier.threadNameWithIndex)
                                {
                                    var threadIdentifier = new ThreadIdentifier(threadNameWithIndex);
                                    if (threadIdentifier.index != ThreadIdentifier.kAll)
                                    {
                                        m_ThreadSelection.selection.Add(threadNameWithIndex);
                                    }
                                }
                            }
                        }
                    }
                    else if (item.threadIdentifier.index == ThreadIdentifier.kAll)
                    {
                        // Record active groups
                        if (newState)
                        {
                            if (!m_ThreadSelection.groups.Contains(item.threadIdentifier.threadNameWithIndex))
                            {
                                m_ThreadSelection.groups.Add(item.threadIdentifier.threadNameWithIndex);
                            }
                        }
                        else
                        {
                            m_ThreadSelection.groups.Remove(item.threadIdentifier.threadNameWithIndex);
                            // When turning off a sub group, turn of the 'all' group too
                            m_ThreadSelection.groups.Remove(m_AllThreadIdentifier.threadNameWithIndex);
                        }

                        // Update selection
                        if (newState)
                        {
                            foreach (string threadNameWithIndex in m_ThreadNames)
                            {
                                var threadIdentifier = new ThreadIdentifier(threadNameWithIndex);
                                if (threadIdentifier.name == item.threadIdentifier.name &&
                                    threadIdentifier.index != ThreadIdentifier.kAll)
                                {
                                    if (!m_ThreadSelection.selection.Contains(threadNameWithIndex))
                                    {
                                        m_ThreadSelection.selection.Add(threadNameWithIndex);
                                    }
                                }
                            }
                        }
                        else
                        {
                            var removeSelection = new List <string>();
                            foreach (string threadNameWithIndex in m_ThreadSelection.selection)
                            {
                                var threadIdentifier = new ThreadIdentifier(threadNameWithIndex);
                                if (threadIdentifier.name == item.threadIdentifier.name &&
                                    threadIdentifier.index != ThreadIdentifier.kAll)
                                {
                                    removeSelection.Add(threadNameWithIndex);
                                }
                            }
                            foreach (string threadNameWithIndex in removeSelection)
                            {
                                m_ThreadSelection.selection.Remove(threadNameWithIndex);
                            }
                        }
                    }
                    else
                    {
                        if (newState)
                        {
                            m_ThreadSelection.selection.Add(item.threadIdentifier.threadNameWithIndex);
                        }
                        else
                        {
                            m_ThreadSelection.selection.Remove(item.threadIdentifier.threadNameWithIndex);

                            // Turn off any group its in too
                            var groupIdentifier = new ThreadIdentifier(item.threadIdentifier);
                            groupIdentifier.SetAll();
                            m_ThreadSelection.groups.Remove(groupIdentifier.threadNameWithIndex);

                            // Turn of the 'all' group too
                            m_ThreadSelection.groups.Remove(m_AllThreadIdentifier.threadNameWithIndex);
                        }
                    }
                }
                break;
            }
        }
Exemple #9
0
        void CellGUI(Rect cellRect, ThreadTreeViewItem item, MyColumns column, ref RowGUIArgs args)
        {
            // Center cell rect vertically (makes it easier to place controls, icons etc in the cells)
            CenterRectUsingSingleLineHeight(ref cellRect);

            switch (column)
            {
            case MyColumns.ThreadName:
            {
                args.rowRect = cellRect;
                // base.RowGUI(args);    // Required to show tree indenting

                // Draw manually to keep indenting while add a tooltip
                Rect rect = cellRect;
                if (Event.current.rawType == EventType.Repaint)
                {
                    string text;
                    string tooltip;
                    GetThreadTreeViewItemInfo(item, out text, out tooltip);
                    var content = new GUIContent(text, tooltip);

                    if (activeLineStyle == null)
                    {
                        // activeLineStyle = DefaultStyles.boldLabel;
                        activeLineStyle = new GUIStyle(DefaultStyles.label);
                        activeLineStyle.normal.textColor = DefaultStyles.boldLabel.onActive.textColor;
                    }

                    // rect = DrawIndent(rect, item, ref args);

                    //bool mouseOver = rect.Contains(Event.current.mousePosition);
                    //DefaultStyles.label.Draw(rect, content, mouseOver, false, args.selected, args.focused);

                    // Must use this call to draw tooltip
                    EditorGUI.LabelField(rect, content, args.selected ? activeLineStyle : DefaultStyles.label);
                }
            }
            break;

            case MyColumns.GroupName:
            {
                Rect rect = cellRect;
                if (Event.current.rawType == EventType.Repaint)
                {
                    rect = DrawIndent(rect, item, ref args);

                    string groupName = GetItemGroupName(item);
                    var    content   = new GUIContent(groupName, groupName);
                    EditorGUI.LabelField(rect, content);
                }
            }
            break;

            case MyColumns.State:
                bool oldState = GetThreadSelectedState(item.threadIdentifier) == ThreadSelected.Selected;
                bool newState = EditorGUI.Toggle(cellRect, oldState);
                if (newState != oldState)
                {
                    if (item.threadIdentifier.threadNameWithIndex == m_AllThreadIdentifier.threadNameWithIndex)
                    {
                        // Record active groups
                        m_ThreadSelection.groups.Clear();
                        if (newState)
                        {
                            if (!m_ThreadSelection.groups.Contains(item.threadIdentifier.threadNameWithIndex))
                            {
                                m_ThreadSelection.groups.Add(item.threadIdentifier.threadNameWithIndex);
                            }
                        }

                        // Update selection
                        m_ThreadSelection.selection.Clear();
                        if (newState)
                        {
                            foreach (string threadNameWithIndex in m_ThreadNames)
                            {
                                if (threadNameWithIndex != m_AllThreadIdentifier.threadNameWithIndex)
                                {
                                    var threadIdentifier = new ThreadIdentifier(threadNameWithIndex);
                                    if (threadIdentifier.index != ThreadIdentifier.kAll)
                                    {
                                        m_ThreadSelection.selection.Add(threadNameWithIndex);
                                    }
                                }
                            }
                        }
                    }
                    else if (item.threadIdentifier.index == ThreadIdentifier.kAll)
                    {
                        // Record active groups
                        if (newState)
                        {
                            if (!m_ThreadSelection.groups.Contains(item.threadIdentifier.threadNameWithIndex))
                            {
                                m_ThreadSelection.groups.Add(item.threadIdentifier.threadNameWithIndex);
                            }
                        }
                        else
                        {
                            m_ThreadSelection.groups.Remove(item.threadIdentifier.threadNameWithIndex);
                            // When turning off a sub group, turn of the 'all' group too
                            m_ThreadSelection.groups.Remove(m_AllThreadIdentifier.threadNameWithIndex);
                        }

                        // Update selection
                        if (newState)
                        {
                            foreach (string threadNameWithIndex in m_ThreadNames)
                            {
                                var threadIdentifier = new ThreadIdentifier(threadNameWithIndex);
                                if (threadIdentifier.name == item.threadIdentifier.name &&
                                    threadIdentifier.index != ThreadIdentifier.kAll)
                                {
                                    if (!m_ThreadSelection.selection.Contains(threadNameWithIndex))
                                    {
                                        m_ThreadSelection.selection.Add(threadNameWithIndex);
                                    }
                                }
                            }
                        }
                        else
                        {
                            var removeSelection = new List <string>();
                            foreach (string threadNameWithIndex in m_ThreadSelection.selection)
                            {
                                var threadIdentifier = new ThreadIdentifier(threadNameWithIndex);
                                if (threadIdentifier.name == item.threadIdentifier.name &&
                                    threadIdentifier.index != ThreadIdentifier.kAll)
                                {
                                    removeSelection.Add(threadNameWithIndex);
                                }
                            }
                            foreach (string threadNameWithIndex in removeSelection)
                            {
                                m_ThreadSelection.selection.Remove(threadNameWithIndex);
                            }
                        }
                    }
                    else
                    {
                        if (newState)
                        {
                            m_ThreadSelection.selection.Add(item.threadIdentifier.threadNameWithIndex);
                        }
                        else
                        {
                            m_ThreadSelection.selection.Remove(item.threadIdentifier.threadNameWithIndex);

                            // Turn off any group its in too
                            var groupIdentifier = new ThreadIdentifier(item.threadIdentifier);
                            groupIdentifier.SetAll();
                            m_ThreadSelection.groups.Remove(groupIdentifier.threadNameWithIndex);

                            // Turn of the 'all' group too
                            m_ThreadSelection.groups.Remove(m_AllThreadIdentifier.threadNameWithIndex);
                        }
                    }

                    StateChanged = true;

                    // Re-sort
                    SortIfNeeded(GetRows());
                }
                break;
            }
        }