public static ListViewShared.ListViewElementsEnumerator ListView(ListViewState state, ListViewOptions lvOptions, int[] colWidths, string dragTitle, GUIStyle style, params GUILayoutOption[] options) { GUILayout.BeginHorizontal(style, new GUILayoutOption[0]); state.scrollPos = EditorGUILayout.BeginScrollView(state.scrollPos, options); ilvState.beganHorizontal = true; state.draggedFrom = -1; state.draggedTo = -1; state.fileNames = null; if ((lvOptions & ListViewOptions.WantsReordering) != (ListViewOptions)0) { ilvState.wantsReordering = true; } if ((lvOptions & ListViewOptions.WantsExternalFiles) != (ListViewOptions)0) { ilvState.wantsExternalFiles = true; } if ((lvOptions & ListViewOptions.WantsToStartCustomDrag) != (ListViewOptions)0) { ilvState.wantsToStartCustomDrag = true; } if ((lvOptions & ListViewOptions.WantsToAcceptCustomDrag) != (ListViewOptions)0) { ilvState.wantsToAcceptCustomDrag = true; } return(DoListView(GUILayoutUtility.GetRect(1f, (float)(state.totalRows * state.rowHeight + 3)), state, colWidths, string.Empty)); }
public static ListViewShared.ListViewElementsEnumerator DoListView(Rect pos, ListViewState state, int[] colWidths, string dragTitle) { int controlID = GUIUtility.GetControlID(listViewHash, FocusType.Passive); state.ID = controlID; state.selectionChanged = false; Rect rect; if (GUIClipHelper.VisibleRect.x < 0f || GUIClipHelper.VisibleRect.y < 0f) { rect = pos; } else { rect = ((pos.y >= 0f) ? new Rect(0f, state.scrollPos.y, GUIClipHelper.VisibleRect.width, GUIClipHelper.VisibleRect.height) : new Rect(0f, 0f, GUIClipHelper.VisibleRect.width, GUIClipHelper.VisibleRect.height)); } if (rect.width <= 0f) { rect.width = 1f; } if (rect.height <= 0f) { rect.height = 1f; } ilvState.rect = rect; int num = (int)((-pos.y + rect.yMin) / (float)state.rowHeight); int num2 = num + (int)Math.Ceiling((double)(((rect.yMin - pos.y) % (float)state.rowHeight + rect.height) / (float)state.rowHeight)) - 1; if (colWidths == null) { dummyWidths[0] = (int)rect.width; colWidths = dummyWidths; } ilvState.invisibleRows = num; ilvState.endRow = num2; ilvState.rectHeight = (int)rect.height; ilvState.state = state; if (num < 0) { num = 0; } if (num2 >= state.totalRows) { num2 = state.totalRows - 1; } return(new ListViewShared.ListViewElementsEnumerator(ilvState, colWidths, num, num2, dragTitle, new Rect(0f, (float)(num * state.rowHeight), pos.width, (float)state.rowHeight))); }
static bool SendKey(InternalListViewState ilvState, KeyCode keyCode, int totalCols) { ListViewState state = ilvState.state; bool result; switch (keyCode) { case KeyCode.UpArrow: if (state.currentRow > 0) { state.currentRow--; } goto IL_14C; case KeyCode.DownArrow: if (state.currentRow < state.totalRows - 1) { state.currentRow++; } goto IL_14C; case KeyCode.RightArrow: if (state.column < totalCols - 1) { state.column++; } goto IL_14C; case KeyCode.LeftArrow: if (state.column > 0) { state.column--; } goto IL_14C; case KeyCode.Home: state.currentRow = 0; goto IL_14C; case KeyCode.End: state.currentRow = state.totalRows - 1; goto IL_14C; case KeyCode.PageUp: if (!DoLVPageUpDown(ilvState, ref state.currentRow, ref state.scrollPos, true)) { Event.current.Use(); result = false; return(result); } goto IL_14C; case KeyCode.PageDown: if (!DoLVPageUpDown(ilvState, ref state.currentRow, ref state.scrollPos, false)) { Event.current.Use(); result = false; return(result); } goto IL_14C; } result = false; return(result); IL_14C: state.scrollPos = ListViewScrollToRow(ilvState, state.scrollPos, state.currentRow); Event.current.Use(); result = true; return(result); }
static void SendKey(ListViewState state, KeyCode keyCode) { SendKey(state.ilvState, keyCode, 1); }
public bool MoveNext() { try { if (xPos > -1) { if (HasMouseDown(ilvState, rect)) { ilvState.state.selectionChanged = true; ilvState.state.currentRow = yPos; ilvState.state.column = xPos; ilvState.state.scrollPos = ListViewScrollToRow(ilvState, yPos); if ((ilvState.wantsReordering || ilvState.wantsToStartCustomDrag) && GUIUtility.hotControl == ilvState.state.ID) { DragAndDropDelay dragAndDropDelay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), ilvState.state.ID); dragAndDropDelay.mouseDownPosition = Event.current.mousePosition; ilvState.dragItem = yPos; dragControlID = ilvState.state.ID; } } Rect visibleRect = GUIClipHelper.VisibleRect; if (!isDragging && (ilvState.wantsReordering || ilvState.wantsToAcceptCustomDrag) && GUIUtility.hotControl == ilvState.state.ID && Event.current.type == EventType.MouseDrag && visibleRect.Contains(Event.current.mousePosition)) { DragAndDropDelay dragAndDropDelay2 = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), ilvState.state.ID); if (dragAndDropDelay2.CanStartDrag()) { DragAndDrop.PrepareStartDrag(); DragAndDrop.objectReferences = new UnityEngine.Object[0]; DragAndDrop.paths = null; if (ilvState.wantsReordering) { ilvState.state.dropHereRect = new Rect(ilvState.rect.x, 0f, ilvState.rect.width, (float)(ilvState.state.rowHeight * 2)); DragAndDrop.StartDrag(dragTitle); } else if (ilvState.wantsToStartCustomDrag) { DragAndDrop.SetGenericData("CustomDragID", ilvState.state.ID); DragAndDrop.StartDrag(dragTitle); } isDragging = true; } Event.current.Use(); } } xPos++; if (xPos > xTo) { xPos = 0; yPos++; rect.x = firstRect.x; rect.width = (float)colWidths[0]; if (yPos > yTo) { quiting = true; } else { rect.y = rect.y + rect.height; } } else { if (xPos >= 1) { rect.x = rect.x + (float)colWidths[xPos - 1]; } rect.width = (float)colWidths[xPos]; } element.row = yPos; element.column = xPos; element.position = rect; if (element.row >= ilvState.state.totalRows) { quiting = true; } if (isLayouted && Event.current.type == EventType.Layout) { if (yFrom + 1 == yPos) { quiting = true; } } if (isLayouted && yPos != yFrom) { GUILayout.EndHorizontal(); } if (quiting) { if (ilvState.state.drawDropHere && Event.current.GetTypeForControl(ilvState.state.ID) == EventType.Repaint) { GUIStyle gUIStyle = "PR Insertion"; gUIStyle.Draw(gUIStyle.margin.Remove(ilvState.state.dropHereRect), false, false, false, false); } if (ListViewKeyboard(ilvState, colWidths.Length)) { ilvState.state.selectionChanged = true; } if (Event.current.GetTypeForControl(ilvState.state.ID) == EventType.MouseUp) { GUIUtility.hotControl = 0; } if (ilvState.wantsReordering && GUIUtility.hotControl == ilvState.state.ID) { ListViewState state = ilvState.state; EventType type = Event.current.type; if (type != EventType.DragUpdated) { if (type != EventType.DragPerform) { if (type == EventType.DragExited) { ilvState.wantsReordering = false; ilvState.state.drawDropHere = false; GUIUtility.hotControl = 0; } } else { if (GUIClipHelper.VisibleRect.Contains(Event.current.mousePosition)) { ilvState.state.draggedFrom = ilvState.dragItem; ilvState.state.draggedTo = Mathf.RoundToInt(Event.current.mousePosition.y / (float)state.rowHeight); if (ilvState.state.draggedTo > ilvState.state.totalRows) { ilvState.state.draggedTo = ilvState.state.totalRows; } if (ilvState.state.draggedTo > ilvState.state.draggedFrom) { ilvState.state.currentRow = ilvState.state.draggedTo - 1; } else { ilvState.state.currentRow = ilvState.state.draggedTo; } ilvState.state.selectionChanged = true; DragAndDrop.AcceptDrag(); Event.current.Use(); ilvState.wantsReordering = false; ilvState.state.drawDropHere = false; } GUIUtility.hotControl = 0; } } else { DragAndDrop.visualMode = ((!ilvState.rect.Contains(Event.current.mousePosition)) ? DragAndDropVisualMode.None : DragAndDropVisualMode.Move); Event.current.Use(); if (DragAndDrop.visualMode != DragAndDropVisualMode.None) { state.dropHereRect.y = (float)((Mathf.RoundToInt(Event.current.mousePosition.y / (float)state.rowHeight) - 1) * state.rowHeight); if (state.dropHereRect.y >= (float)(state.rowHeight * state.totalRows)) { state.dropHereRect.y = (float)(state.rowHeight * (state.totalRows - 1)); } state.drawDropHere = true; } } } else if (ilvState.wantsExternalFiles) { EventType type2 = Event.current.type; if (type2 != EventType.DragUpdated) { if (type2 != EventType.DragPerform) { if (type2 == EventType.DragExited) { ilvState.wantsExternalFiles = false; ilvState.state.drawDropHere = false; GUIUtility.hotControl = 0; } } else { if (GUIClipHelper.VisibleRect.Contains(Event.current.mousePosition)) { ilvState.state.fileNames = DragAndDrop.paths; DragAndDrop.AcceptDrag(); Event.current.Use(); ilvState.wantsExternalFiles = false; ilvState.state.drawDropHere = false; ilvState.state.draggedTo = Mathf.RoundToInt(Event.current.mousePosition.y / (float)ilvState.state.rowHeight); if (ilvState.state.draggedTo > ilvState.state.totalRows) { ilvState.state.draggedTo = ilvState.state.totalRows; } ilvState.state.currentRow = ilvState.state.draggedTo; } GUIUtility.hotControl = 0; } } else if (GUIClipHelper.VisibleRect.Contains(Event.current.mousePosition) && DragAndDrop.paths != null && DragAndDrop.paths.Length != 0) { DragAndDrop.visualMode = ((!ilvState.rect.Contains(Event.current.mousePosition)) ? DragAndDropVisualMode.None : DragAndDropVisualMode.Copy); Event.current.Use(); if (DragAndDrop.visualMode != DragAndDropVisualMode.None) { ilvState.state.dropHereRect = new Rect(ilvState.rect.x, (float)((Mathf.RoundToInt(Event.current.mousePosition.y / (float)ilvState.state.rowHeight) - 1) * ilvState.state.rowHeight), ilvState.rect.width, (float)ilvState.state.rowHeight); if (ilvState.state.dropHereRect.y >= (float)(ilvState.state.rowHeight * ilvState.state.totalRows)) { ilvState.state.dropHereRect.y = (float)(ilvState.state.rowHeight * (ilvState.state.totalRows - 1)); } ilvState.state.drawDropHere = true; } } } else if (ilvState.wantsToAcceptCustomDrag && dragControlID != ilvState.state.ID) { EventType type3 = Event.current.type; if (type3 != EventType.DragUpdated) { if (type3 != EventType.DragPerform) { if (type3 == EventType.DragExited) { GUIUtility.hotControl = 0; } } else { object genericData = DragAndDrop.GetGenericData("CustomDragID"); if (GUIClipHelper.VisibleRect.Contains(Event.current.mousePosition) && genericData != null) { ilvState.state.customDraggedFromID = (int)genericData; DragAndDrop.AcceptDrag(); Event.current.Use(); } GUIUtility.hotControl = 0; } } else { object genericData2 = DragAndDrop.GetGenericData("CustomDragID"); if (GUIClipHelper.VisibleRect.Contains(Event.current.mousePosition) && genericData2 != null) { DragAndDrop.visualMode = ((!ilvState.rect.Contains(Event.current.mousePosition)) ? DragAndDropVisualMode.None : DragAndDropVisualMode.Move); Event.current.Use(); } } } if (ilvState.beganHorizontal) { EditorGUILayout.EndScrollView(); GUILayout.EndHorizontal(); ilvState.beganHorizontal = false; } if (isLayouted) { typeof(GUILayoutUtility).GetMethod("EndLayoutGroup", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, new object[0]); //GUILayoutUtility.EndLayoutGroup(); EditorGUILayout.EndScrollView(); } ilvState.wantsReordering = false; ilvState.wantsExternalFiles = false; } else if (isLayouted) { if (yPos != yFrom) { ilvStateL.group.ResetCursor(); ilvStateL.group.AddY(); } else { ilvStateL.group.AddY((float)(ilvState.invisibleRows * ilvState.state.rowHeight)); } } if (isLayouted) { if (!quiting) { GUILayout.BeginHorizontal(GUIStyle.none, new GUILayoutOption[0]); } else { GUILayout.EndHorizontal(); } } return(!quiting); } catch (Exception e) { Debug.LogException(e); return(false); } }
public static ListViewShared.ListViewElementsEnumerator ListView(ListViewState state, ListViewOptions lvOptions, string dragTitle, GUIStyle style, params GUILayoutOption[] options) { return(ListView(state, lvOptions, null, dragTitle, style, options)); }
public static ListViewShared.ListViewElementsEnumerator ListView(ListViewState state, int[] colWidths, GUIStyle style, params GUILayoutOption[] options) { return(ListView(state, (ListViewOptions)0, colWidths, string.Empty, style, options)); }
public static ListViewShared.ListViewElementsEnumerator ListView(Rect pos, ListViewState state) { return(DoListView(pos, state, null, string.Empty)); }