Пример #1
0
        private void DrawBreadcrumbs(bool isShowingPreviewSteps, Rect rect)
        {
            if (this.NumRenameOperations == 0)
            {
                var emptyBreadcrumbRect = new Rect(rect);
                emptyBreadcrumbRect.width = 20.0f;
                EditorGUI.BeginDisabledGroup(true);
                GUI.Toggle(emptyBreadcrumbRect, false, string.Empty, "GUIEditor.BreadcrumbLeft");
                EditorGUI.EndDisabledGroup();
            }
            else
            {
                if (isShowingPreviewSteps)
                {
                    var totalWidth = 0.0f;
                    for (int i = 0; i < this.NumRenameOperations; ++i)
                    {
                        var drawerAtBreadcrumb = this.RenameOperationsToApplyWithBindings[i].Drawer;
                        var breadcrumbOption   = new PreviewBreadcrumbOptions();
                        breadcrumbOption.Heading        = drawerAtBreadcrumb.HeadingLabel;
                        breadcrumbOption.HighlightColor = drawerAtBreadcrumb.HighlightColor;

                        breadcrumbOption.UseLeftStyle = i == 0;
                        breadcrumbOption.Enabled      = i == this.FocusedRenameOpIndex;

                        var breadcrumbPosition = new Vector2(rect.x + totalWidth, rect.y);

                        var nextBreadcrumbRect = new Rect(breadcrumbPosition, breadcrumbOption.SizeForContent);
                        nextBreadcrumbRect.position = new Vector2(rect.x + totalWidth, rect.y);

                        var selected = DrawPreviewBreadcrumb(nextBreadcrumbRect, breadcrumbOption);
                        if (selected && i != this.FocusedRenameOpIndex)
                        {
                            var renameOp = this.RenameOperationsToApplyWithBindings[i].Operation;
                            this.FocusRenameOperationDeferred(renameOp);
                        }

                        totalWidth += nextBreadcrumbRect.width;
                    }
                }
                else
                {
                    var breadcrumbeOptions =
                        new PreviewBreadcrumbOptions()
                    {
                        Heading = "Result", HighlightColor = Color.clear, Enabled = true, UseLeftStyle = true
                    };
                    var breadcrumbSize = breadcrumbeOptions.SizeForContent;
                    breadcrumbSize.y = rect.height;
                    DrawPreviewBreadcrumb(new Rect(rect.position, breadcrumbSize), breadcrumbeOptions);
                }
            }
        }
        private void DrawToolbar()
        {
            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);

            GUILayout.Label("Rename Operations", GUILayout.Width(340.0f));

            // The breadcrumb style spills to the left some so we need to leave extra space for it
            const float BreadcrumbLeftOffset = 5.0f;

            GUILayout.Space(BreadcrumbLeftOffset + 1.0f);

            // Show step previewing mode when only one operation is left because Results mode is pointless with one op only.
            // But don't actually change the mode preference so that adding ops restores whatever mode the user was in.
            this.IsShowingPreviewSteps = this.IsPreviewStepModePreference || this.RenameOperationsToApply.Count <= 1;
            if (this.IsShowingPreviewSteps)
            {
                var breadcrumbOptions = new PreviewBreadcrumbOptions[this.RenameOperationsToApply.Count];
                for (int i = 0; i < this.RenameOperationsToApply.Count; ++i)
                {
                    var operationAtBreadcrumb = this.RenameOperationsToApply[i];
                    breadcrumbOptions[i].Heading        = operationAtBreadcrumb.HeadingLabel;
                    breadcrumbOptions[i].HighlightColor = operationAtBreadcrumb.HighlightColor;
                }

                var selectedBreadcrumbIndex = DrawPreviewBreadcrumbs(this.FocusedRenameOpIndex, breadcrumbOptions);
                if (selectedBreadcrumbIndex != this.FocusedRenameOpIndex)
                {
                    var renameOp = this.RenameOperationsToApply[selectedBreadcrumbIndex];
                    this.FocusRenameOperationDeferred(renameOp);
                }
            }
            else
            {
                DrawPreviewBreadcrumbs(0, new PreviewBreadcrumbOptions()
                {
                    Heading = "Result", HighlightColor = Color.clear
                });
            }

            GUILayout.FlexibleSpace();

            EditorGUI.BeginDisabledGroup(this.RenameOperationsToApply.Count <= 1);
            var buttonText = "Preview Steps";

            this.IsPreviewStepModePreference = GUILayout.Toggle(this.IsPreviewStepModePreference, buttonText, "toolbarbutton");
            EditorGUI.EndDisabledGroup();

            EditorGUILayout.EndHorizontal();
        }
Пример #3
0
        private static bool DrawPreviewBreadcrumb(Rect rect, PreviewBreadcrumbOptions breacrumbConfig)
        {
            var  styleName = breacrumbConfig.StyleName;
            var  enabled   = breacrumbConfig.Enabled;
            bool selected  = GUI.Toggle(rect, enabled, breacrumbConfig.Heading, styleName);

            if (selected)
            {
                var coloredHighlightRect = new Rect(rect);
                coloredHighlightRect.height = 2;
                coloredHighlightRect.width += 1.0f;
                coloredHighlightRect.x     += breacrumbConfig.UseLeftStyle ? -5.0f : -4.0f;
                var oldColor = GUI.color;
                GUI.color = breacrumbConfig.HighlightColor;
                GUI.DrawTexture(coloredHighlightRect, Texture2D.whiteTexture);
                GUI.color = oldColor;
            }

            return(selected);
        }