osu/osu.Game/Overlays/OverlayStreamControl.cs

59 lines
1.7 KiB
C#
Raw Normal View History

2019-05-22 10:51:16 +00:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2022-06-17 07:37:17 +00:00
#nullable disable
2019-05-22 10:51:16 +00:00
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Graphics.UserInterface;
using JetBrains.Annotations;
2019-05-22 10:51:16 +00:00
namespace osu.Game.Overlays
2019-05-22 10:51:16 +00:00
{
2022-11-24 05:32:20 +00:00
public abstract partial class OverlayStreamControl<T> : TabControl<T>
2019-05-22 10:51:16 +00:00
{
2020-03-04 20:08:58 +00:00
protected OverlayStreamControl()
2019-05-22 10:51:16 +00:00
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
}
public void Populate(List<T> streams) => streams.ForEach(AddItem);
protected override Dropdown<T> CreateDropdown() => null;
protected override TabItem<T> CreateTabItem(T value) => CreateStreamItem(value).With(item =>
2019-05-22 10:51:16 +00:00
{
item.SelectedItem.BindTo(Current);
});
[NotNull]
2020-03-04 20:08:58 +00:00
protected abstract OverlayStreamItem<T> CreateStreamItem(T value);
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
AllowMultiline = true,
};
2019-05-22 10:51:16 +00:00
protected override bool OnHover(HoverEvent e)
{
2020-03-04 20:08:58 +00:00
foreach (var streamBadge in TabContainer.Children.OfType<OverlayStreamItem<T>>())
streamBadge.UserHoveringArea = true;
2019-05-22 10:51:16 +00:00
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
2020-03-04 20:08:58 +00:00
foreach (var streamBadge in TabContainer.Children.OfType<OverlayStreamItem<T>>())
streamBadge.UserHoveringArea = false;
2019-05-22 10:51:16 +00:00
base.OnHoverLost(e);
}
}
}