1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 19:04:06 +08:00

Centralise hover state handling (and fix back-to-front conditionals)

This commit is contained in:
Dean Herbert 2021-12-15 16:44:58 +09:00
parent 6a1f535257
commit ad430a6277

View File

@ -56,7 +56,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
CornerRadius = BeatmapCard.CORNER_RADIUS, CornerRadius = BeatmapCard.CORNER_RADIUS,
Masking = true, Masking = true,
Unhovered = _ => collapseIfNotHovered(), Unhovered = _ => updateFromHoverChange(),
Children = new Drawable[] Children = new Drawable[]
{ {
background = new Box background = new Box
@ -78,10 +78,10 @@ namespace osu.Game.Beatmaps.Drawables.Cards
Alpha = 0, Alpha = 0,
Hovered = _ => Hovered = _ =>
{ {
queueExpandedStateChange(true); updateFromHoverChange();
return true; return true;
}, },
Unhovered = _ => collapseIfNotHovered(), Unhovered = _ => updateFromHoverChange(),
Child = dropdownScroll = new ExpandedContentScrollContainer Child = dropdownScroll = new ExpandedContentScrollContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
@ -125,11 +125,8 @@ namespace osu.Game.Beatmaps.Drawables.Cards
public void CancelExpand() => scheduledExpandedChange?.Cancel(); public void CancelExpand() => scheduledExpandedChange?.Cancel();
private void collapseIfNotHovered() private void updateFromHoverChange() =>
{ queueExpandedStateChange(content.IsHovered || dropdownContent.IsHovered, 100);
if (!content.IsHovered && !dropdownContent.IsHovered)
queueExpandedStateChange(false);
}
private void queueExpandedStateChange(bool newState, int delay = 0) private void queueExpandedStateChange(bool newState, int delay = 0)
{ {