// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using osu.Framework.Input.Events; using osuTK; namespace osu.Framework.Graphics.Containers { /// /// An item of a . /// /// public abstract class RearrangeableListItem : CompositeDrawable { /// /// Invoked on drag start, if an arrangement should be started. /// internal Action, DragStartEvent> StartArrangement; /// /// Invoked on drag, if this item is being arranged. /// internal Action, DragEvent> Arrange; /// /// Invoked on drag end, if this item is being arranged. /// internal Action, DragEndEvent> EndArrangement; /// /// The item this represents. /// public readonly TModel Model; /// /// Creates a new . /// /// The item to represent. protected RearrangeableListItem(TModel item) { Model = item; } /// /// Whether the item is able to be dragged at the given screen-space position. /// protected virtual bool IsDraggableAt(Vector2 screenSpacePos) => true; protected override bool OnDragStart(DragStartEvent e) { if (IsDraggableAt(e.ScreenSpaceMouseDownPosition)) { StartArrangement?.Invoke(this, e); return true; } return false; } protected override void OnDrag(DragEvent e) => Arrange?.Invoke(this, e); protected override void OnDragEnd(DragEndEvent e) => EndArrangement?.Invoke(this, e); } }