Esempio n. 1
0
        public override void OnGUI(Rect rect)
        {
            UpdateStyle();

            Event current = Event.current;

            HandleKeyboardEvents(current);

            bool repaintEvent = current.type == EventType.Repaint;

            if (repaintEvent && DataSource.CountValidItems(dataSource.items) == 0)
            {
                // If all GameObjects have been destroyed while the popup was open,
                // e.g. during scene change, the popup can be closed.
                ClosePopup();
                return;
            }

            // Account for the 1px gray border at the top of the window.
            rect.yMin += 1;

            if (GUILayout.Button("UpdateAnchors"))
            {
                AnchorToolsEditor.UpdateAnchors();
            }

            // compensate for update anchors button height
            rect.yMin += 20;

            rect = dataSource.DrawFilterModes(rect, RowHeight);
            rect = dataSource.SearchFieldGUI(rect, RowHeight);

            scroll = GUI.BeginScrollView(
                rect, scroll, contentRect, GUIStyle.none, GUI.skin.verticalScrollbar);

            DrawScrollViewContent(rect, current, repaintEvent);

            GUI.EndScrollView();

            if (current.type == EventType.MouseMove)
            {
                editorWindow.Repaint();
            }
        }
Esempio n. 2
0
        private void DrawScrollViewContent(Rect rect, Event current, bool repaintEvent)
        {
            rect.height = RowHeight;
            rect.xMin  += 2;
            rect.xMax  -= 2;

            IList <GameObject> items = dataSource.filteredItems;
            int count = DataSource.CountValidItems(dataSource.filteredItems);

            hoverTarget = null;

            using (new EditorGUIUtility.IconSizeScope(styles.iconSize))
            {
                for (int i = 0; i < count; i++)
                {
                    if (items[i] == null)
                    {
                        continue;
                    }

                    DrawRow(rect, current, items[i]);

                    if (i < count && repaintEvent)
                    {
                        DrawSplitter(rect);
                    }

                    rect.y += RowHeight;
                }
            }

            // Check for the currently hovered item in DrawRow,
            // then clear if nothing was hovered this frame.
            if (hoverTarget != null)
            {
                outlineManager.SetOutlineTarget(hoverTarget);
            }
            else
            {
                outlineManager.Clear();
            }
        }
Esempio n. 3
0
        public override Vector2 GetWindowSize()
        {
            float totalHeight = 0;

            if (UserPrefs.ShowSearchField)
            {
                totalHeight += RowHeight + 2;
            }

            // Filter mode row.
            if (UserPrefs.ShowFilterToolbar)
            {
                totalHeight += RowHeight + 2;
            }

            int itemCount = DataSource.CountValidItems(dataSource.filteredItems);

            totalHeight += RowHeight * itemCount;

            float   iconBeforeLabelWidth = 22;
            Vector2 windowSize           = new Vector2(iconBeforeLabelWidth + buttonAndIconsWidth, totalHeight);

            // Content refers to all item rows without the search field and is used by the scroll view.
            float yStartPosition = UserPrefs.ShowSearchField ? RowHeight + 2 : 0;

            // Filter mode row content size.
            if (UserPrefs.ShowFilterToolbar)
            {
                yStartPosition += RowHeight + 2;
            }

            Vector2 contentSize = new Vector2(windowSize.x, windowSize.y - yStartPosition);

            // Account for the offset by the search field and the border line at the top of the window.
            float contentYOffset = (UserPrefs.ShowSearchField ? RowHeight + 1 : 0) + 1;

            // Filter mode row offset.
            if (UserPrefs.ShowFilterToolbar)
            {
                contentYOffset += RowHeight + 1;
            }

            this.contentRect = new Rect(new Vector2(0, contentYOffset), contentSize);

            // The popup window has a 1px gray border that covers the top and bottom.
            // Make enough room for the content to fit perfectly within.
            totalHeight += 2;
            windowSize.y = totalHeight;

            int maxHeight = Mathf.Min(Screen.currentResolution.height, 700);

            if (totalHeight > maxHeight)
            {
                // Window is clamped and must show scroll bars for its content.
                windowSize.y = maxHeight;

                // Extra size to fit vertical scroll bar without clipping icons.
                windowSize.x += 14;
            }

            return(windowSize);
        }