/// <summary> /// Ends the drag operations, and eventually applies the drag outcome. /// Returns TRUE if the position of the dragged item actually changed. /// Called automatically by Drag method. Use it only if you want to force the end of a drag operation. /// </summary> /// <param name="applyDrag">If TRUE applies the drag results, otherwise simply cancels the drag</param> public static DragResult EndDrag(bool applyDrag) { if (dragData == null) { return(new DragResult(DragResultType.NoDrag)); } int dragFrom = dragData.nDraggedItemIndex; int dragTo = dragData.nCurrDragIndex > dragData.nDraggedItemIndex ? dragData.nCurrDragIndex - 1 : dragData.nCurrDragIndex; if (applyDrag) { bool changed = dragData.nCurrDragIndex <dragData.nDraggedItemIndex || dragData.nCurrDragIndex> dragData.nDraggedItemIndex + 1; if (Event.current.type == EventType.Repaint) { Event.current.type = EventType.Used; } else if (Event.current.type == EventType.Used) { ApplyDrag(); } else { isWaitingToApplyDrag = true; } DragResultType resultType = changed ? DragResultType.Accepted : DragResultType.Ineffective; return(new DragResult(resultType, dragFrom, dragTo)); } Reset(); return(new DragResult(DragResultType.Canceled, dragFrom, dragTo)); }
public DragResult(DragResultType outcome, int movedFromIndex = -1, int movedToIndex = -1) { this.outcome = outcome; this.movedFromIndex = movedFromIndex; this.movedToIndex = movedToIndex; }