private void DrawLoadingScreen(Rect bounds, string message)
        {
            var size = PlatformDrawer.CalculateImageSize("Spinner");

            var imageRect = new Rect(bounds)
            {
                x      = bounds.x + (bounds.width - size.x) / 2,
                y      = bounds.y + (bounds.height - size.y) / 2,
                width  = size.x,
                height = size.y
            };

            var textRect = new Rect(imageRect)
            {
                width  = bounds.width,
                height = 15,
                y      = imageRect.y + imageRect.height + 5,
                x      = bounds.x
            };

            var rotPivot = new Vector2(imageRect.x + size.x / 2, imageRect.y + size.y / 2);
            var mat      = GUI.matrix;

            GUIUtility.RotateAroundPivot(rot, rotPivot);
            PlatformDrawer.DrawImage(imageRect, "Spinner", true);
            //Draw code
            rot       += 0.4f;
            GUI.matrix = mat;
            GUI.Label(textRect, message, MessageStyle);
        }
Beispiel #2
0
    public void DrawTreeView(Rect bounds, TreeViewModel viewModel, Action <Vector2, IItem> itemClicked,
                             Action <Vector2, IItem> itemRightClicked = null)
    {
        var boundY = bounds.height;

        if (Event.current != null && Event.current.isKey && Event.current.rawType == EventType.KeyUp)
        {
            switch (Event.current.keyCode)
            {
            case KeyCode.UpArrow:
                viewModel.MoveUp();
                break;

            case KeyCode.DownArrow:
                viewModel.MoveDown();
                break;

            case KeyCode.RightArrow:
            {
                var selectedContainer = viewModel.SelectedData as ITreeItem;
                if (selectedContainer != null)
                {
                    selectedContainer.Expanded = true;
                    viewModel.IsDirty          = true;
                }
            }
            break;

            case KeyCode.LeftArrow:
            {
                var selectedContainer = viewModel.SelectedData as ITreeItem;
                if (selectedContainer != null)
                {
                    selectedContainer.Expanded = false;
                    viewModel.IsDirty          = true;
                }
            }
            break;

            case KeyCode.Return:
                if (viewModel != null)
                {
                    viewModel.InvokeSubmit();
                }
                break;

            default:
                break;
            }
        }
        //   PlatformDrawer.DrawLabel(new Rect().WithSize(100,100).InnerAlignWithBottomRight(bounds),"Total height: {0}, Total Items: {1}");
        var dirty    = false;
        var position = bounds;
        var usedRect = position.WithWidth(Math.Max(bounds.width, PlatformDrawer.CalculateTextSize(viewModel.LargestString, CachedStyles.ListItemTitleStyle).x + 5 * viewModel.MaxIdentLevel)).Pad(0, 0, 15, 0).WithHeight(ItemHeight * viewModel.TreeData.Count(s => s.Visible));

        PlatformDrawer.DrawStretchBox(position.PadSides(-1), CachedStyles.WizardListItemBoxStyle, 10);



        viewModel.Scroll = GUI.BeginScrollView(position, viewModel.Scroll, usedRect);

        var  itemTemplateRect = bounds.WithHeight(ItemHeight);
        bool hasItems         = false;

        foreach (var treeViewItem in viewModel.TreeData)
        {
            if (!treeViewItem.Visible)
            {
                continue;
            }
            hasItems = true;
            var data = treeViewItem.Data;

            var treeData = data as ITreeItem;

            var itemRect = itemTemplateRect.Pad(5 * treeViewItem.Indent, 0, 5 * treeViewItem.Indent, 0);

            var localItemY = itemRect.Translate(0, -position.yMin).y;
            if (localItemY > (viewModel.Scroll.y + position.height))
            {
                break;
            }
            var imageRect = new Rect().WithSize(12, 12)
                            .Align(itemRect)
                            .AlignHorisonallyByCenter(itemRect)
                            .Translate(5, 0);

            var labelRect =
                itemRect.WithWidth(
                    PlatformDrawer.CalculateTextSize(treeViewItem.Data.Title, CachedStyles.BreadcrumbTitleStyle).x)
                .Translate(25, 0);

            if (treeViewItem == viewModel.ScrollTarget)
            {
                viewModel.Scroll = new Vector2(0, localItemY - ItemHeight * 5);
                viewModel.ScrollToItem(null);
            }

            if (treeViewItem.Selected)
            {
                PlatformDrawer.DrawStretchBox(itemRect, CachedStyles.WizardSubBoxStyle, 14);
            }

            PlatformDrawer.DrawLabel(labelRect, treeViewItem.Data.Title, CachedStyles.ListItemTitleStyle);
            PlatformDrawer.DrawImage(imageRect, treeViewItem.Icon, true);
            if (treeViewItem.ColorMark.HasValue)
            {
                var colorMarkRect = new Rect().WithSize(8, 8).InnerAlignWithCenterRight(itemRect).Translate(-24, 0);
                PlatformDrawer.DrawRect(colorMarkRect, treeViewItem.ColorMark.Value);
            }

            if (viewModel.ShowToggle)
            {
                EditorGUI.BeginChangeCheck();
                var toggleRect = new Rect().WithSize(16, 16).InnerAlignWithUpperRight(itemRect).Translate(-50, 0);
                GUI.enabled = viewModel.AllowManualToggle;
                var toggle = GUI.Toggle(toggleRect, treeViewItem.IsChecked, "");
                GUI.enabled = true;

                if (treeViewItem.IsChecked != toggle)
                {
                    viewModel.ToggleItem(treeViewItem, toggle);
                    return;
                }
            }

            var item1 = treeViewItem;
            PlatformDrawer.DoButton(itemRect.Translate(25, 0), "", CachedStyles.ClearItemStyle,
                                    m =>
            {
                viewModel.SelectedIndex = item1.Index;
                //TODO PUBLISH EVENT
                if (itemClicked != null)
                {
                    itemClicked(m, item1.Data);
                }
            }, m => { if (itemRightClicked != null)
                      {
                          itemRightClicked(m, item1.Data);
                      }
                });



            if (treeData != null)
            {
                PlatformDrawer.DoButton(imageRect, "", CachedStyles.ClearItemStyle,
                                        () =>
                {
                    treeData.Expanded = !treeData.Expanded;
                    dirty             = true;
                });
            }

            if (treeViewItem.Highlighted)
            {
                PlatformDrawer.DrawLine(new[]
                {
                    new Vector3(labelRect.x, itemRect.yMax - 1, 0),
                    new Vector3(labelRect.x + 75, itemRect.yMax - 1, 0)
                }, Color.cyan);
            }

            itemTemplateRect = itemTemplateRect.Below(itemTemplateRect);
        }



        GUI.EndScrollView();

        if (!hasItems)
        {
            var textRect   = bounds;
            var cacheColor = GUI.color;
            GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, 0.4f);
            PlatformDrawer.DrawLabel(textRect, "No Items Found", CachedStyles.WizardSubBoxTitleStyle, DrawingAlignment.MiddleCenter);
            GUI.color = cacheColor;
            return;
        }

        if (dirty)
        {
            viewModel.IsDirty = true;
        }
    }
        public void DrawGraphExplorer(Rect r)
        {
            var result = EditorGUILayout.Popup(CurrentViewIndex, ExplorerViewsStrings);

            if (result != CurrentViewIndex)
            {
                CurrentViewIndex = result;
                TreeModel.Data   = CurrentViewProvider.GetItems(Container.Resolve <IRepository>());
            }
            if (_hardDirty)
            {
                if (TreeModel == null)
                {
                    return;
                }
                if (WorkspaceService == null || WorkspaceService.CurrentWorkspace == null)
                {
                    TreeModel.Data = new List <IItem>();
                }
                else
                {
                    TreeModel.Data    = CurrentViewProvider.GetItems(Container.Resolve <IRepository>());
                    TreeModel.IsDirty = true;
                }
                _hardDirty = false;
            }
            if (TreeModel == null)
            {
                return;
            }

            if (TreeModel.IsDirty)
            {
                TreeModel.Refresh();
            }
            Rect window = r;

            var searcbarRect   = window.WithHeight(32).Pad(5, 22, 5, 5);
            var listRect       = window.Below(searcbarRect).Clip(window).PadSides(5);
            var searchIconRect = new Rect().WithSize(32, 32).InnerAlignWithBottomRight(searcbarRect).AlignHorisonallyByCenter(searcbarRect).PadSides(10);

            PlatformDrawer.DrawImage(searchIconRect, "SearchIcon", true);

            GUI.SetNextControlName("GraphTreeSearch");
            EditorGUI.BeginChangeCheck();
            SearchCriteria = GUI.TextField(searcbarRect, SearchCriteria ?? "", ElementDesignerStyles.SearchBarTextStyle);
            PlatformDrawer.DrawImage(searchIconRect, "SearchIcon", true);
            if (EditorGUI.EndChangeCheck())
            {
                if (string.IsNullOrEmpty(SearchCriteria))
                {
                    TreeModel.Predicate = null;
                }
                else
                {
                    var sc = SearchCriteria.ToLower();
                    TreeModel.Predicate = i =>
                    {
                        if (string.IsNullOrEmpty(i.Title))
                        {
                            return(false);
                        }

                        if (
                            CultureInfo.CurrentCulture.CompareInfo.IndexOf(i.Title, SearchCriteria,
                                                                           CompareOptions.IgnoreCase) != -1)
                        {
                            return(true);
                        }

                        if (!string.IsNullOrEmpty(i.SearchTag) &&
                            CultureInfo.CurrentCulture.CompareInfo.IndexOf(i.SearchTag, SearchCriteria,
                                                                           CompareOptions.IgnoreCase) != -1)
                        {
                            return(true);
                        }

                        return(false);
                    };
                }
                TreeModel.IsDirty = true;
            }


            //            PlatformDrawer.DrawTextbox("GraphTreeWindow_Search",searcbarRect,_searchCriterial,GUI.skin.textField.WithFont("Verdana",15),
            //                (val,submit) =>
            //                {
            //                    _searchCriterial = val;
            //                });


            InvertApplication.SignalEvent <IDrawTreeView>(_ =>
            {
                _.DrawTreeView(listRect, TreeModel, (m, i) =>
                {
                    TryNavigateToItem(i);
                });
            });

            GUI.FocusControl("GraphTreeSearch");
        }