From c383b67b2832fa7666a6f20fcf0e5fa33bf65b13 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Fri, 15 Nov 2024 17:50:28 +0900 Subject: [PATCH] Enable NRT for `RearrangeableListContainer<>` --- .../Containers/RearrangeableListContainer.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/osu.Framework/Graphics/Containers/RearrangeableListContainer.cs b/osu.Framework/Graphics/Containers/RearrangeableListContainer.cs index 83a07b6ebd..ebef10929e 100644 --- a/osu.Framework/Graphics/Containers/RearrangeableListContainer.cs +++ b/osu.Framework/Graphics/Containers/RearrangeableListContainer.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Collections.Generic; using System.Collections.Specialized; @@ -21,6 +19,7 @@ namespace osu.Framework.Graphics.Containers /// /// The type of rearrangeable item. public abstract partial class RearrangeableListContainer : CompositeDrawable + where TModel : notnull { private const float exp_base = 1.05f; @@ -50,7 +49,7 @@ public abstract partial class RearrangeableListContainer : CompositeDraw protected IReadOnlyDictionary> ItemMap => itemMap; private readonly Dictionary> itemMap = new Dictionary>(); - private RearrangeableListItem currentlyDraggedItem; + private RearrangeableListItem? currentlyDraggedItem; private Vector2 screenSpaceDragPosition; /// @@ -81,7 +80,7 @@ protected virtual void OnItemsChanged() { } - private void collectionChanged(object sender, NotifyCollectionChangedEventArgs e) + private void collectionChanged(object? sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { @@ -193,7 +192,7 @@ private void sortItems() if (drawable.Parent != ListContainer) continue; - ListContainer!.SetLayoutPosition(drawable, i); + ListContainer.SetLayoutPosition(drawable, i); } } @@ -218,9 +217,7 @@ protected override void Update() protected override void UpdateAfterChildren() { base.UpdateAfterChildren(); - - if (currentlyDraggedItem != null) - updateArrangement(); + updateArrangement(); } private void updateScrollPosition() @@ -245,6 +242,9 @@ private void updateScrollPosition() private void updateArrangement() { + if (currentlyDraggedItem == null) + return; + var localPos = ListContainer.ToLocalSpace(screenSpaceDragPosition); int srcIndex = Items.IndexOf(currentlyDraggedItem.Model);