diff --git a/osu.Game.Tests/Visual/SongSelectV2/TestSceneBeatmapCarousel.cs b/osu.Game.Tests/Visual/SongSelectV2/TestSceneBeatmapCarousel.cs index 05f38d2bc8..d9bb612a32 100644 --- a/osu.Game.Tests/Visual/SongSelectV2/TestSceneBeatmapCarousel.cs +++ b/osu.Game.Tests/Visual/SongSelectV2/TestSceneBeatmapCarousel.cs @@ -6,9 +6,11 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using NUnit.Framework; +using osu.Framework.Testing; using osu.Framework.Utils; using osu.Game.Beatmaps; using osu.Game.Screens.Select.Filter; +using osu.Game.Screens.SelectV2; using osu.Game.Tests.Resources; namespace osu.Game.Tests.Visual.SongSelectV2 @@ -116,5 +118,16 @@ namespace osu.Game.Tests.Visual.SongSelectV2 AddStep("add all beatmaps", () => BeatmapSets.AddRange(generated)); } + + [Test] + public void TestSingleItemDisplayed() + { + CreateCarousel(); + RemoveAllBeatmaps(); + + SortAndGroupBy(SortMode.Difficulty, GroupMode.None); + AddBeatmaps(1, fixedDifficultiesPerSet: 1); + AddUntilStep("single item is shown", () => this.ChildrenOfType().Count(), () => Is.EqualTo(1)); + } } } diff --git a/osu.Game/Graphics/Carousel/Carousel.cs b/osu.Game/Graphics/Carousel/Carousel.cs index 4910e5e257..18395dfa12 100644 --- a/osu.Game/Graphics/Carousel/Carousel.cs +++ b/osu.Game/Graphics/Carousel/Carousel.cs @@ -747,6 +747,9 @@ namespace osu.Game.Graphics.Carousel { Debug.Assert(carouselItems != null); + if (carouselItems.Count == 0) + return DisplayRange.EMPTY; + // Find index range of all items that should be on-screen carouselBoundsItem.CarouselYPosition = visibleUpperBound - DistanceOffscreenToPreload; int firstIndex = carouselItems.BinarySearch(carouselBoundsItem); @@ -766,7 +769,7 @@ namespace osu.Game.Graphics.Carousel { Debug.Assert(carouselItems != null); - List toDisplay = range.Last - range.First == 0 + List toDisplay = range == DisplayRange.EMPTY ? new List() : carouselItems.GetRange(range.First, range.Last - range.First + 1); @@ -885,7 +888,10 @@ namespace osu.Game.Graphics.Carousel /// The index of the selection as of the last run of . May be null if selection is not present as an item, or if has not been run yet. private record Selection(object? Model = null, CarouselItem? CarouselItem = null, double? YPosition = null, int? Index = null); - private record DisplayRange(int First, int Last); + private record DisplayRange(int First, int Last) + { + public static readonly DisplayRange EMPTY = new DisplayRange(-1, -1); + } /// /// Implementation of scroll container which handles very large vertical lists by internally using double precision