/// <summary> /// Draws the table. /// </summary> public void DrawTable() { var e = Event.current.type; if (this.minTalbeSize.y == 0 || this.isDirty) { this.ReCalculateSizes(); } // If there are not auto-width columns it means that the table has a fixed width, and doesn't expand. // Otherwise it does expand. // Here we also make sure that we allocate atleast 10 pixels per auto-width column. GUILayoutOptions.GUILayoutOptionsInstance guiLayoutOptions; if (this.numOfAutoWidthColumns == 0) { guiLayoutOptions = GUILayoutOptions.ExpandWidth(false).Width(this.minTalbeSize.x); } else { guiLayoutOptions = GUILayoutOptions.ExpandWidth().MinWidth(this.minTalbeSize.x + this.numOfAutoWidthColumns * 10); } var newRect = GUILayoutUtility.GetRect(0, this.minTalbeSize.y > 0 ? this.minTalbeSize.y : 10, guiLayoutOptions); if (this.RespectIndentLevel) { newRect = UnityEditor.EditorGUI.IndentedRect(newRect); } // Recalcualte sizes if resized. if (e == EventType.Repaint) { if (this.tableRect.width != newRect.width || this.tableRect.x != newRect.x || this.tableRect.y != newRect.y) { this.tableRect = newRect; this.ReCalculateSizes(); } else { this.tableRect = newRect; } } // Handle resizing: for (int x = 0; x < this.ColumnCount - 1; x++) { if (x < this.ColumnCount - 1 && this.columnInfos[x + 1].Resizable == false) { continue; } if (this.columnInfos[x].Resizable == false) { continue; } GUITableCell resizeCell = null; for (int y = 0; y < this.RowCount; y++) { var candidate = this.cells[x, y]; if (candidate != null && candidate.SpanX == false) { resizeCell = candidate; break; } } if (resizeCell != null) { var rect = resizeCell.Rect; rect.x = rect.xMax - 5; rect.width = 10; var mouseDelta = SirenixEditorGUI.SlideRect(rect).x; if (mouseDelta != 0) { if (mouseDelta > 0) { var ci = this.columnInfos[x]; ColumnInfo nextResizableCol = null; for (int j = x + 1; j < this.ColumnCount; j++) { if (this.columnInfos[j].Resizable) { nextResizableCol = this.columnInfos[j]; break; } } if (nextResizableCol != null) { float remaining = nextResizableCol.ColumnWidth - nextResizableCol.ColumnMinWidth; if (nextResizableCol != null && remaining > 0) { mouseDelta = Mathf.Min(mouseDelta, remaining); ci.ResizeOffset += mouseDelta; nextResizableCol.ResizeOffset -= mouseDelta; } this.ReCalculateSizes(); } } else { var ci = this.columnInfos[x + 1]; mouseDelta *= -1; ColumnInfo prevResizableCol = null; for (int j = x; j >= 0; j--) { if (this.columnInfos[j].Resizable) { prevResizableCol = this.columnInfos[j]; break; } } if (prevResizableCol != null) { float remaining = prevResizableCol.ColumnWidth - prevResizableCol.ColumnMinWidth; if (prevResizableCol != null && remaining > mouseDelta) { mouseDelta = Mathf.Min(mouseDelta, remaining); ci.ResizeOffset += mouseDelta; prevResizableCol.ResizeOffset -= mouseDelta; } } this.ReCalculateSizes(); } } } } GUIHelper.PushIndentLevel(0); // Draw Cells: for (int x = 0; x < this.ColumnCount; x++) { for (int y = 0; y < this.RowCount; y++) { var cell = this.cells[x, y]; if (cell != null) { cell.Draw(); } } } GUIHelper.PopIndentLevel(); }