private void MoveSoundClassUp() { int index = _soundClasses.IndexOf(_selectedSoundClass); IsChanged = true; _soundClasses.Move(index, index - 1); }
private void updateArrangement() { var localPos = ListContainer.ToLocalSpace(screenSpaceDragPosition); int srcIndex = Items.IndexOf(currentlyDraggedItem.Model); // Find the last item with position < mouse position. Note we can't directly use // the item positions as they are being transformed float heightAccumulator = 0; int dstIndex = 0; for (; dstIndex < Items.Count; dstIndex++) { var drawable = itemMap[Items[dstIndex]]; if (!drawable.IsLoaded) { continue; } // Using BoundingBox here takes care of scale, paddings, etc... float height = drawable.BoundingBox.Height; // Rearrangement should occur only after the mid-point of items is crossed heightAccumulator += height / 2; // Check if the midpoint has been crossed (i.e. cursor is located above the midpoint) if (heightAccumulator > localPos.Y) { if (dstIndex > srcIndex) { // Suppose an item is dragged just slightly below its own midpoint. The rearrangement condition (accumulator > pos) will be satisfied for the next immediate item // but not the currently-dragged item, which will invoke a rearrangement. This is an off-by-one condition. // Rearrangement should not occur until the midpoint of the next item is crossed, and so to fix this the next item's index is discarded. dstIndex--; } break; } // Add the remainder of the height of the current item heightAccumulator += height / 2 + ListContainer.Spacing.Y; } dstIndex = Math.Clamp(dstIndex, 0, Items.Count - 1); if (srcIndex == dstIndex) { return; } Items.Move(srcIndex, dstIndex); // Todo: this could be optimised, but it's a very simple iteration over all the items reSort(); }