Change carousel terminology to not use Children / InternalChildren

This commit is contained in:
Dean Herbert
2022-07-21 16:06:06 +09:00
parent 55bde4eeb0
commit a05d7f4d8c
6 changed files with 44 additions and 42 deletions

View File

@ -13,9 +13,9 @@ namespace osu.Game.Screens.Select.Carousel
{
public override DrawableCarouselItem? CreateDrawableRepresentation() => null;
public IReadOnlyList<CarouselItem> Children => InternalChildren;
public IReadOnlyList<CarouselItem> Items => items;
protected List<CarouselItem> InternalChildren = new List<CarouselItem>();
private List<CarouselItem> items = new List<CarouselItem>();
/// <summary>
/// Used to assign a monotonically increasing ID to children as they are added. This member is
@ -27,16 +27,18 @@ namespace osu.Game.Screens.Select.Carousel
private FilterCriteria? lastCriteria;
public virtual void RemoveChild(CarouselItem i)
protected int GetIndexOfItem(CarouselItem lastSelected) => items.IndexOf(lastSelected);
public virtual void RemoveItem(CarouselItem i)
{
InternalChildren.Remove(i);
items.Remove(i);
// it's important we do the deselection after removing, so any further actions based on
// State.ValueChanged make decisions post-removal.
i.State.Value = CarouselItemState.Collapsed;
}
public virtual void AddChild(CarouselItem i)
public virtual void AddItem(CarouselItem i)
{
i.State.ValueChanged += state => ChildItemStateChanged(i, state.NewValue);
i.ChildID = ++currentChildID;
@ -45,21 +47,21 @@ namespace osu.Game.Screens.Select.Carousel
{
i.Filter(lastCriteria);
int index = InternalChildren.BinarySearch(i, criteriaComparer);
int index = items.BinarySearch(i, criteriaComparer);
if (index < 0) index = ~index; // BinarySearch hacks multiple return values with 2's complement.
InternalChildren.Insert(index, i);
items.Insert(index, i);
}
else
{
// criteria may be null for initial population. the filtering will be applied post-add.
InternalChildren.Add(i);
items.Add(i);
}
}
public CarouselGroup(List<CarouselItem>? items = null)
{
if (items != null) InternalChildren = items;
if (items != null) this.items = items;
State.ValueChanged += state =>
{
@ -67,11 +69,11 @@ namespace osu.Game.Screens.Select.Carousel
{
case CarouselItemState.Collapsed:
case CarouselItemState.NotSelected:
InternalChildren.ForEach(c => c.State.Value = CarouselItemState.Collapsed);
this.items.ForEach(c => c.State.Value = CarouselItemState.Collapsed);
break;
case CarouselItemState.Selected:
InternalChildren.ForEach(c =>
this.items.ForEach(c =>
{
if (c.State.Value == CarouselItemState.Collapsed) c.State.Value = CarouselItemState.NotSelected;
});
@ -84,11 +86,11 @@ namespace osu.Game.Screens.Select.Carousel
{
base.Filter(criteria);
InternalChildren.ForEach(c => c.Filter(criteria));
items.ForEach(c => c.Filter(criteria));
// IEnumerable<T>.OrderBy() is used instead of List<T>.Sort() to ensure sorting stability
criteriaComparer = Comparer<CarouselItem>.Create((x, y) => x.CompareTo(criteria, y));
InternalChildren = InternalChildren.OrderBy(c => c, criteriaComparer).ToList();
items = items.OrderBy(c => c, criteriaComparer).ToList();
lastCriteria = criteria;
}
@ -98,7 +100,7 @@ namespace osu.Game.Screens.Select.Carousel
// ensure we are the only item selected
if (value == CarouselItemState.Selected)
{
foreach (var b in InternalChildren)
foreach (var b in items)
{
if (item == b) continue;