mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 14:03:01 +08:00
Add comment and reduce how often ChildrenOfType
is invoked in ExpandingButtonContainer
This commit is contained in:
parent
5aca2dd4ce
commit
f703c5f038
@ -65,7 +65,7 @@ namespace osu.Game.Overlays
|
|||||||
protected override void OnHoverLost(HoverLostEvent e)
|
protected override void OnHoverLost(HoverLostEvent e)
|
||||||
{
|
{
|
||||||
expandEvent?.Cancel();
|
expandEvent?.Cancel();
|
||||||
lastHoveredButton = null;
|
hoveredButton = null;
|
||||||
State = ExpandedState.Contracted;
|
State = ExpandedState.Contracted;
|
||||||
|
|
||||||
base.OnHoverLost(e);
|
base.OnHoverLost(e);
|
||||||
@ -112,22 +112,24 @@ namespace osu.Game.Overlays
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Drawable lastHoveredButton;
|
private Drawable hoveredButton;
|
||||||
|
|
||||||
private Drawable hoveredButton => FillFlow.ChildrenOfType<OsuButton>().FirstOrDefault(c => c.IsHovered);
|
|
||||||
|
|
||||||
private void queueExpandIfHovering()
|
private void queueExpandIfHovering()
|
||||||
{
|
{
|
||||||
// only expand when we hover a different button.
|
// if the same button is hovered, let the scheduled expand play out..
|
||||||
if (lastHoveredButton == hoveredButton) return;
|
if (hoveredButton?.IsHovered == true)
|
||||||
|
return;
|
||||||
|
|
||||||
if (State != ExpandedState.Expanded)
|
// ..otherwise check whether a new button is hovered, and if so, queue a new hover operation.
|
||||||
{
|
|
||||||
expandEvent?.Cancel();
|
// usually we wouldn't use ChildrenOfType in implementations, but this is the simplest way
|
||||||
|
// to handle cases like the editor where the buttons may be nested within a child hierarchy.
|
||||||
|
hoveredButton = FillFlow.ChildrenOfType<OsuButton>().FirstOrDefault(c => c.IsHovered);
|
||||||
|
|
||||||
|
expandEvent?.Cancel();
|
||||||
|
|
||||||
|
if (hoveredButton?.IsHovered == true && State != ExpandedState.Expanded)
|
||||||
expandEvent = Scheduler.AddDelayed(() => State = ExpandedState.Expanded, 750);
|
expandEvent = Scheduler.AddDelayed(() => State = ExpandedState.Expanded, 750);
|
||||||
}
|
|
||||||
|
|
||||||
lastHoveredButton = hoveredButton;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user