private Vector2 DrawPreviewPanelContentsWithItems( PreviewPanelLayout scrollLayout, PreviewPanelContentsLayout contentsLayout, Vector2 previewPanelScrollPosition, PreviewPanelContents previewContents, int renameStep, bool shouldShowSecondColumn, bool shouldShowThirdColumn) { // WORKAROUND FOR 5.5.5: Somehow you could "scroll" the preview area, even // when there was nothing to scroll. Force it to not think it's scrolled because // that was screwing up the Header. if (scrollLayout.ContentsFitWithoutScrollingHorizontally(contentsLayout)) { previewPanelScrollPosition.x = 0; } string originalNameColumnHeader = renameStep < 1 ? "Original" : "Before"; string newNameColumnHeader = "After"; this.DrawPreviewHeader( scrollLayout.HeaderRect, -previewPanelScrollPosition.x, originalNameColumnHeader, newNameColumnHeader, contentsLayout.FirstColumnWidth, contentsLayout.SecondColumnWidth, contentsLayout.ThirdColumnWidth); var newScrollPosition = GUI.BeginScrollView( scrollLayout.ScrollRect, previewPanelScrollPosition, contentsLayout.Rect); var rowRect = new Rect(scrollLayout.ScrollRect); rowRect.width = Mathf.Max(contentsLayout.Rect.width, scrollLayout.ScrollRect.width); this.DrawPreviewRows(rowRect, previewContents, shouldShowSecondColumn, shouldShowThirdColumn); // Add the hint into the scroll view if there's room if (scrollLayout.ContentsFitWithoutAnyScrolling(contentsLayout)) { EditorGUI.LabelField(scrollLayout.HintRect, this.guiContents.DropPromptHintInsideScroll, this.guiStyles.DropPromptHintInsideScroll); } GUI.EndScrollView(); this.DrawDividers(newScrollPosition, scrollLayout, contentsLayout, shouldShowThirdColumn); GUI.EndGroup(); return(newScrollPosition); }
private void DrawDividers( Vector2 newScrollPosition, PreviewPanelLayout scrollLayout, PreviewPanelContentsLayout contentsLayout, bool shouldShowThirdColumn) { // Put dividers in group so that they scroll (horizontally) var dividerGroup = new Rect(scrollLayout.ScrollRect); dividerGroup.y -= scrollLayout.HeaderRect.height; dividerGroup.height += scrollLayout.HeaderRect.height; GUI.BeginGroup(dividerGroup); var oldColor = GUI.color; if (EditorGUIUtility.isProSkin) { GUI.color = new Color(0.3f, 0.3f, 0.3f, 1.0f); } else { GUI.color = new Color(0.6f, 0.6f, 0.6f, 1.0f); } // Add 1 into y for the position so that it doesn't render on the panel's border var dividerHeight = dividerGroup.height; // Unity scroll view bars overlap the scroll rect when they render, so we have to shorten the dividers if (!scrollLayout.ContentsFitWithoutScrollingHorizontally(contentsLayout)) { var scrollbarHeight = 14.0f; dividerHeight -= scrollbarHeight; } var firstDividerRect = new Rect( -newScrollPosition.x + contentsLayout.FirstColumnWidth + contentsLayout.IconSize, 0.0f, 1.0f, dividerHeight - 1.0f); GUI.DrawTexture(firstDividerRect, Texture2D.whiteTexture); if (shouldShowThirdColumn) { var secondDividerRect = new Rect(firstDividerRect); secondDividerRect.x += contentsLayout.SecondColumnWidth; GUI.DrawTexture(secondDividerRect, Texture2D.whiteTexture); } GUI.color = oldColor; }
private Vector2 DrawPreviewPanelContentsWithItems( PreviewPanelLayout scrollLayout, PreviewPanelContentsLayout contentsLayout, Vector2 previewPanelScrollPosition, PreviewPanelContents previewContents, int renameStep, bool shouldShowSecondColumn, bool shouldShowThirdColumn) { // WORKAROUND FOR 5.5.5: Somehow you could "scroll" the preview area, even // when there was nothing to scroll. Force it to not think it's scrolled because // that was screwing up the Header. if (scrollLayout.ContentsFitWithoutScrollingHorizontally(contentsLayout)) { previewPanelScrollPosition.x = 0; } string originalNameColumnHeader = renameStep < 1 ? "Original" : "Before"; string newNameColumnHeader = "After"; this.DrawPreviewHeader( scrollLayout.HeaderRect, -previewPanelScrollPosition.x, originalNameColumnHeader, newNameColumnHeader, contentsLayout.FirstColumnWidth, contentsLayout.SecondColumnWidth, contentsLayout.ThirdColumnWidth); var newScrollPosition = GUI.BeginScrollView( scrollLayout.ScrollRect, previewPanelScrollPosition, contentsLayout.Rect); var rowRect = new Rect(scrollLayout.ScrollRect); rowRect.width = Mathf.Max(contentsLayout.Rect.width, scrollLayout.ScrollRect.width); this.DrawPreviewRows(rowRect, previewContents, shouldShowSecondColumn, shouldShowThirdColumn); // Add the hint into the scroll view if there's room if (scrollLayout.ContentsFitWithoutAnyScrolling(contentsLayout)) { EditorGUI.LabelField(scrollLayout.HintRect, this.guiContents.DropPromptHintInsideScroll, this.guiStyles.DropPromptHintInsideScroll); } GUI.EndScrollView(); // Put dividers in group so that they scroll (horizontally) GUI.BeginGroup(scrollLayout.ScrollRect); var oldColor = GUI.color; if (EditorGUIUtility.isProSkin) { GUI.color = new Color(0.3f, 0.3f, 0.3f, 1.0f); } else { GUI.color = new Color(0.6f, 0.6f, 0.6f, 1.0f); } // Add 1 into y for the position so that it doesn't render on the panel's border var dividerHeight = scrollLayout.ScrollRect.height - 1.0f; // Unity scroll view bars overlap the scroll rect when they render, so we have to shorten the dividers if (!scrollLayout.ContentsFitWithoutScrollingHorizontally(contentsLayout)) { var scrollbarHeight = 14.0f; dividerHeight -= scrollbarHeight; } var firstDividerRect = new Rect( -newScrollPosition.x + contentsLayout.FirstColumnWidth + contentsLayout.IconSize, 1.0f, 1.0f, dividerHeight - 1.0f); GUI.DrawTexture(firstDividerRect, Texture2D.whiteTexture); if (shouldShowThirdColumn) { var secondDividerRect = new Rect(firstDividerRect); secondDividerRect.x += contentsLayout.SecondColumnWidth; GUI.DrawTexture(secondDividerRect, Texture2D.whiteTexture); } GUI.color = oldColor; GUI.EndGroup(); return(newScrollPosition); }
/// <summary> /// Draw the specified BulkRenamePreview in the given rect, and returns the new scroll position. /// </summary> /// <returns>The new scroll position.</returns> /// <param name="previewPanelRect">Preview panel rect.</param> /// <param name="previewPanelScrollPosition">Preview panel scroll position.</param> /// <param name="preview">Preview to draw.</param> public Vector2 Draw(Rect previewPanelRect, Vector2 previewPanelScrollPosition, BulkRenamePreview preview) { var spaceBetweenFooterAndScrollview = 2.0f; var panelFooterToolbar = new Rect(previewPanelRect); panelFooterToolbar.height = EditorGUIUtility.singleLineHeight; panelFooterToolbar.y += (previewPanelRect.height + spaceBetweenFooterAndScrollview) - panelFooterToolbar.height; var scrollViewRect = new Rect(previewPanelRect); scrollViewRect.height -= (panelFooterToolbar.height + spaceBetweenFooterAndScrollview); GUI.Box(scrollViewRect, "", this.guiStyles.PreviewScroll); var newScrollPosition = previewPanelScrollPosition; if (preview.NumObjects == 0) { this.DrawPreviewPanelContentsEmpty(scrollViewRect); } else { var scrollLayout = new PreviewPanelLayout(scrollViewRect); // Show the one that doesn't quite fit by subtracting one var firstItemIndex = Mathf.Max(Mathf.FloorToInt(previewPanelScrollPosition.y / PreviewRowHeight) - 1, 0); // Add one for the one that's off screen above, and one for the one below. I think? var numItems = Mathf.CeilToInt(scrollLayout.ScrollRect.height / PreviewRowHeight) + 2; var previewContents = PreviewPanelContents.CreatePreviewContentsForObjects( preview, firstItemIndex, numItems, this.PreviewStepIndexToShow, this.guiStyles.DeletionTextColor, this.guiStyles.InsertionTextColor); bool shouldShowSecondColumn = this.ColumnsToShow != ColumnStyle.OriginalAndFinalOnly; bool shouldShowThirdColumn = this.ColumnsToShow != ColumnStyle.StepwiseHideFinal; var contentsLayout = new PreviewPanelContentsLayout( scrollLayout.ScrollRect, previewContents, shouldShowSecondColumn, shouldShowThirdColumn); newScrollPosition = this.DrawPreviewPanelContentsWithItems( scrollLayout, contentsLayout, previewPanelScrollPosition, previewContents, this.PreviewStepIndexToShow, shouldShowSecondColumn, shouldShowThirdColumn); var buttonSpacing = 2.0f; var rightPadding = 2.0f; var addSelectedObjectsButtonRect = new Rect(panelFooterToolbar); addSelectedObjectsButtonRect.width = 150.0f; addSelectedObjectsButtonRect.x = panelFooterToolbar.xMax - rightPadding - addSelectedObjectsButtonRect.width; var removeAllButtonRect = new Rect(addSelectedObjectsButtonRect); removeAllButtonRect.width = 100.0f; removeAllButtonRect.x -= (removeAllButtonRect.width + buttonSpacing); if (GUI.Button(removeAllButtonRect, "Remove All")) { if (this.RemoveAllClicked != null) { this.RemoveAllClicked.Invoke(); } } this.DrawAddSelectedObjectsButton(addSelectedObjectsButtonRect); if (!scrollLayout.ContentsFitWithoutAnyScrolling(contentsLayout)) { var hintRect = new Rect(scrollViewRect); hintRect.height = EditorGUIUtility.singleLineHeight * 2.0f; hintRect.y += scrollViewRect.height; hintRect.width = scrollViewRect.width - addSelectedObjectsButtonRect.width - removeAllButtonRect.width - buttonSpacing; EditorGUI.LabelField(hintRect, this.guiContents.DropPromptHint, this.guiStyles.DropPromptHint); } } var draggedObjects = this.GetDraggedObjectsOverRect(scrollViewRect); if (draggedObjects.Count > 0) { if (this.ObjectsDropped != null) { this.ObjectsDropped.Invoke(draggedObjects.ToArray()); } } return(newScrollPosition); }