private void DrawLibrary(WindowComponentLibraryLinker lib, int xCount, float width, float height, GUIStyle itemBox, GUIStyle style, GUIStyle label, GUIStyle path)
        {
            var i = 0;

            foreach (var item in lib.items)
            {
                if (i % xCount == 0)
                {
                    if (i != 0)
                    {
                        GUILayout.EndHorizontal();
                    }
                    GUILayout.BeginHorizontal();
                }

                GUILayout.BeginVertical(itemBox, GUILayout.Width(width), GUILayout.Height(height));
                {
                    if (GUILayout.Button(item.title, style) == true)
                    {
                        if (this.onSelect != null)
                        {
                            this.onSelect(item);
                        }
                    }

                    var lastRect = GUILayoutUtility.GetLastRect();
                    lastRect.width  = width;
                    lastRect.height = height;

                    {
                        item.OnPreviewGUI(Color.white, lastRect, style);
                    }

                    GUILayout.BeginVertical();
                    {
                        GUILayout.Label(item.title, label);
                        GUILayout.Label(item.localDirectory, path);
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndVertical();

                ++i;
            }

            if (i % xCount != 0 && xCount > 0)
            {
                GUILayout.EndHorizontal();
            }
        }
Exemple #2
0
        private void OnGUI()
        {
            if (this.styles == null)
            {
                this.styles = new Styles();
            }

            GUI.skin = this.styles.skin;

            //var scrollWidth = 30f;

            var width  = 160f;
            var height = 100f;

            var panelWidth = 180f;

            var itemBox = new GUIStyle(this.styles.box2);

            itemBox.fixedWidth   = 0f;
            itemBox.stretchWidth = false;

            var label = new GUIStyle(GUI.skin.label);

            label.wordWrap = true;

            var path = new GUIStyle(EditorStyles.miniLabel);

            path.wordWrap = true;

            var style = this.styles.itemButton;

            var rect = this.position;

            rect.x = 0f;
            rect.y = 0f;
            GUI.Box(rect, string.Empty, this.styles.box1);

            this.scrollPos = GUILayout.BeginScrollView(this.scrollPos, false, false);
            {
                GUILayout.BeginHorizontal();
                {
                    GUILayout.BeginVertical(this.styles.box2, GUILayout.Width(panelWidth));
                    {
                        GUILayout.Label("Libraries:");

                        foreach (var library in this.libraries)
                        {
                            if (GUILayout.Button(library.name) == true)
                            {
                                this.selectedLibrary = library;
                            }
                        }
                    }
                    GUILayout.EndVertical();

                    GUILayout.BeginVertical();
                    {
                        if (this.selectedLibrary != null)
                        {
                            var sizeWidth   = this.position.width - panelWidth - width * 0.5f;
                            var xCount      = Mathf.FloorToInt(sizeWidth / width);
                            var widthOffset = (sizeWidth - xCount * width) / xCount;
                            if (xCount > 0)
                            {
                                style.fixedWidth    = width + widthOffset;
                                style.fixedHeight   = height + widthOffset;
                                style.stretchWidth  = false;
                                style.stretchHeight = false;

                                this.DrawLibrary(this.selectedLibrary, xCount, width + widthOffset, height + widthOffset, itemBox, style, label, path);
                            }
                        }
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();
        }
Exemple #3
0
        private void DrawLibrary(WindowComponentLibraryLinker lib, int xCount, float width, float height, GUIStyle itemBox, GUIStyle style, GUIStyle label, GUIStyle path)
        {
            const float offset = 5f;

            var drawing = false;

            var i = 0;

            foreach (var item in lib.items)
            {
                if (i % xCount == 0)
                {
                    if (i != 0)
                    {
                        GUILayout.EndHorizontal();
                    }
                    GUILayout.BeginHorizontal();
                }

                GUILayout.BeginVertical(itemBox, GUILayout.Width(width), GUILayout.Height(height));
                {
                    if (GUILayout.Button(item.title, style) == true)
                    {
                        if (this.onSelect != null)
                        {
                            this.onSelect(item);
                        }
                    }

                    var lastRect = GUILayoutUtility.GetLastRect();
                    lastRect.width  = width;
                    lastRect.height = height;

                    lastRect.x      += offset;
                    lastRect.y      += offset;
                    lastRect.width  -= offset * 2f;
                    lastRect.height -= offset * 2f;

                    drawing = new Rect(this.scrollPos.x, this.scrollPos.y, Screen.width, Screen.height).Overlaps(lastRect);
                    if (drawing == true)
                    {
                        item.OnPreviewGUI(Color.white, lastRect, style);
                    }

                    GUILayout.BeginVertical();
                    {
                        GUILayout.Label(item.title, label);
                        GUILayout.Label(item.localDirectory, path);
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndVertical();

                ++i;
            }

            if (i % xCount != 0 && xCount > 0)
            {
                GUILayout.EndHorizontal();
            }
        }
        private void OnGUI()
        {
            //var scrollWidth = 30f;

            var width  = 160f;
            var height = 160f;

            var itemBox = new GUIStyle(GUI.skin.box);

            itemBox.fixedWidth   = 0f;
            itemBox.stretchWidth = false;

            /*var box = new GUIStyle(GUI.skin.box);
             * box.fixedWidth = 0f;
             * box.stretchWidth = true;
             * box.margin = new RectOffset();*/

            var label = new GUIStyle(GUI.skin.label);

            label.wordWrap = true;

            var path = new GUIStyle(EditorStyles.miniLabel);

            path.wordWrap = true;

            var style = new GUIStyle(EditorStyles.toolbarButton);

            var rect = this.position;

            rect.x = 0f;
            rect.y = 0f;
            GUI.Box(rect, string.Empty);

            this.scrollPos = GUILayout.BeginScrollView(this.scrollPos, false, false);
            {
                GUILayout.BeginHorizontal();
                {
                    GUILayout.BeginVertical(GUILayout.Width(180f));
                    {
                        foreach (var library in this.libraries)
                        {
                            if (GUILayout.Button(library.name) == true)
                            {
                                this.selectedLibrary = library;
                            }
                        }
                    }
                    GUILayout.EndVertical();

                    GUILayout.BeginVertical();
                    {
                        if (this.selectedLibrary != null)
                        {
                            var xCount = Mathf.FloorToInt((this.position.width - 180f - width * 0.5f) / width);
                            if (xCount > 0)
                            {
                                style.fixedWidth    = width;
                                style.fixedHeight   = height;
                                style.stretchWidth  = false;
                                style.stretchHeight = false;

                                this.DrawLibrary(this.selectedLibrary, xCount, width, height, itemBox, style, label, path);
                            }
                        }
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();
        }