From 68504e96391ae8cb7dcd04c81cd8ffcfd4976717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 30 May 2025 11:06:44 +0200 Subject: [PATCH 1/2] Add failing test case --- .../Visual/SongSelectV2/TestSceneBeatmapCarousel.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/osu.Game.Tests/Visual/SongSelectV2/TestSceneBeatmapCarousel.cs b/osu.Game.Tests/Visual/SongSelectV2/TestSceneBeatmapCarousel.cs index 56351eed97..616748a9d5 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.NoGrouping); + AddBeatmaps(1, fixedDifficultiesPerSet: 1); + AddUntilStep("single item is shown", () => this.ChildrenOfType().Count(), () => Is.EqualTo(1)); + } } } From 2d900c55cfbd3ac99f5c21ce2b0b509ed6e3e20d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 30 May 2025 11:15:15 +0200 Subject: [PATCH 2/2] SongSelectV2: Fix carousel not displaying anything if there is only one panel to display If there is only one panel to display, a `DisplayRange` of (0, 0) is *very much* valid. --- osu.Game/Graphics/Carousel/Carousel.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/Carousel/Carousel.cs b/osu.Game/Graphics/Carousel/Carousel.cs index 9da4d0e187..9646c86dd6 100644 --- a/osu.Game/Graphics/Carousel/Carousel.cs +++ b/osu.Game/Graphics/Carousel/Carousel.cs @@ -743,6 +743,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); @@ -762,7 +765,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); @@ -881,7 +884,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