// Virtual so clients can override header behavior and rendering entirely public virtual void OnGUI(Rect rect, float xScroll) { Event evt = Event.current; if (m_GUIView == null) { m_GUIView = GUIView.current; } DetectSizeChanges(rect); if (m_ResizeToFit && evt.type == EventType.Repaint) { m_ResizeToFit = false; ResizeColumnsWidthsProportionally(rect.width - GUI.skin.verticalScrollbar.fixedWidth - state.widthOfAllVisibleColumns); } // We create a guiclip to let the header be able to scroll horizontally according to the tree view's horizontal scroll // If the tree view is inside a UI Toolkit scroll view, however, we don't need the x scroll offset. Vector2 scrollOffset = Vector2.zero; var container = UIElementsUtility.GetCurrentIMGUIContainer(); var uiScrollView = container?.GetFirstAncestorOfType <ScrollView>(); if (uiScrollView == null) { scrollOffset = new Vector2(-xScroll, 0f); } GUIClip.Push(rect, scrollOffset, Vector2.zero, false); { Rect localRect = new Rect(0, 0, rect.width, rect.height); m_TotalHeaderRect = localRect; // Background ( We always add the width of the vertical scrollbar to accommodate if this is being shown below e.g by a tree view) float widthOfAllColumns = state.widthOfAllVisibleColumns; float backgroundWidth = (localRect.width > widthOfAllColumns ? localRect.width : widthOfAllColumns) + GUI.skin.verticalScrollbar.fixedWidth; Rect backgroundRect = new Rect(0, 0, backgroundWidth, localRect.height); GUI.Label(backgroundRect, GUIContent.none, DefaultStyles.background); // Update column rects (cached for clients to have fast access to column rects by using GetCellRect) UpdateColumnHeaderRects(localRect); // Columns for (int v = 0; v < state.visibleColumns.Length; v++) { currentColumnIndex = state.visibleColumns[v]; MultiColumnHeaderState.Column column = state.columns[currentColumnIndex]; Rect headerRect = m_ColumnRects[v]; const float limitHeightOfDivider = 4f; Rect dividerRect = new Rect(headerRect.xMax - 1, headerRect.y + limitHeightOfDivider, 1f, headerRect.height - 2 * limitHeightOfDivider); // Context menu if (evt.type == EventType.ContextClick && headerRect.Contains(evt.mousePosition)) { evt.Use(); DoContextMenu(); } // Resize columns logic Rect dragRect = new Rect(dividerRect.x - m_DividerWidth * 0.5f, localRect.y, m_DividerWidth, localRect.height); bool hasControl; var newColumnWidth = EditorGUI.WidthResizer(dragRect, column.width, column.minWidth, column.maxWidth, out hasControl); if (column.width != newColumnWidth) { column.width = newColumnWidth; columnSettingsChanged?.Invoke(currentColumnIndex); } if (hasControl && evt.type == EventType.Repaint) { DrawColumnResizing(headerRect, column); } // Draw divider (can be overridden) DrawDivider(dividerRect, column); // Draw header (can be overridden) ColumnHeaderGUI(column, headerRect, currentColumnIndex); } currentColumnIndex = -1; // Context menu when clicked outside of a column header if (evt.type == EventType.ContextClick && backgroundRect.Contains(evt.mousePosition)) { evt.Use(); DoContextMenu(); } } GUIClip.Pop(); }