// Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Linq; namespace osu.Game.Screens.Select.Carousel { /// /// A group which ensures at least one child is selected (if the group itself is selected). /// public class CarouselGroupEagerSelect : CarouselGroup { public CarouselGroupEagerSelect() { State.ValueChanged += v => { if (v == CarouselItemState.Selected) { foreach (var c in InternalChildren.Where(c => c.State.Value == CarouselItemState.Hidden)) c.State.Value = CarouselItemState.NotSelected; if (InternalChildren.Any(c => c.Visible) && InternalChildren.All(c => c.State != CarouselItemState.Selected)) InternalChildren.First(c => c.Visible).State.Value = CarouselItemState.Selected; } }; } protected override void ItemStateChanged(CarouselItem item, CarouselItemState value) { base.ItemStateChanged(item, value); if (value == CarouselItemState.NotSelected) { if (Children.All(i => i.State != CarouselItemState.Selected)) { var first = Children.FirstOrDefault(i => !i.Filtered); if (first != null) { first.State.Value = CarouselItemState.Selected; } } } } } }