1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 13:22:55 +08:00

Freeze select box buttons in place as long as they are hovered

This commit is contained in:
Marvin Schürz 2024-09-21 14:59:47 +02:00
parent ccf1acce56
commit 0077ba72ec
2 changed files with 35 additions and 0 deletions

View File

@ -6,6 +6,7 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
@ -284,8 +285,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
Action = action Action = action
}; };
button.OperationStarted += freezeButtonPosition;
button.HoverLost += unfreezeButtonPosition;
button.OperationStarted += operationStarted; button.OperationStarted += operationStarted;
button.OperationEnded += operationEnded; button.OperationEnded += operationEnded;
buttons.Add(button); buttons.Add(button);
return button; return button;
@ -357,8 +362,29 @@ namespace osu.Game.Screens.Edit.Compose.Components
OperationStarted?.Invoke(); OperationStarted?.Invoke();
} }
private Quad? frozenButtonsDrawQuad;
private void freezeButtonPosition()
{
frozenButtonsDrawQuad = buttons.ScreenSpaceDrawQuad;
}
private void unfreezeButtonPosition()
{
frozenButtonsDrawQuad = null;
}
private void ensureButtonsOnScreen() private void ensureButtonsOnScreen()
{ {
if (frozenButtonsDrawQuad != null)
{
buttons.Anchor = Anchor.TopLeft;
buttons.Origin = Anchor.TopLeft;
buttons.Position = ToLocalSpace(frozenButtonsDrawQuad.Value.TopLeft) - new Vector2(button_padding);
return;
}
buttons.Position = Vector2.Zero; buttons.Position = Vector2.Zero;
var thisQuad = ScreenSpaceDrawQuad; var thisQuad = ScreenSpaceDrawQuad;

View File

@ -21,6 +21,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
public Action? Action; public Action? Action;
public event Action? HoverLost;
public SelectionBoxButton(IconUsage iconUsage, string tooltip) public SelectionBoxButton(IconUsage iconUsage, string tooltip)
{ {
this.iconUsage = iconUsage; this.iconUsage = iconUsage;
@ -61,6 +63,13 @@ namespace osu.Game.Screens.Edit.Compose.Components
icon.FadeColour(!IsHeld && IsHovered ? Color4.White : Color4.Black, TRANSFORM_DURATION, Easing.OutQuint); icon.FadeColour(!IsHeld && IsHovered ? Color4.White : Color4.Black, TRANSFORM_DURATION, Easing.OutQuint);
} }
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
HoverLost?.Invoke();
}
public LocalisableString TooltipText { get; } public LocalisableString TooltipText { get; }
} }
} }