mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 17:52:56 +08:00
Ensure editor selection buttons remain on screen when selection is near edge
Addresses https://github.com/ppy/osu/discussions/23599.
This commit is contained in:
parent
9869e815ce
commit
3b9e1e8a94
@ -22,6 +22,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
{
|
||||
public const float BORDER_RADIUS = 3;
|
||||
|
||||
private const float button_padding = 5;
|
||||
|
||||
public Func<float, bool> OnRotation;
|
||||
public Func<Vector2, Anchor, bool> OnScale;
|
||||
public Func<Direction, bool, bool> OnFlip;
|
||||
@ -182,6 +184,13 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
return base.OnKeyDown(e);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
ensureButtonsOnScreen();
|
||||
}
|
||||
|
||||
private void recreate()
|
||||
{
|
||||
if (LoadState < LoadState.Loading)
|
||||
@ -234,11 +243,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
},
|
||||
buttons = new FillFlowContainer
|
||||
{
|
||||
Y = 20,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
AutoSizeAxes = Axes.X,
|
||||
Height = 30,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Margin = new MarginPadding(button_padding),
|
||||
Anchor = Anchor.BottomCentre,
|
||||
Origin = Anchor.Centre
|
||||
Origin = Anchor.TopCentre
|
||||
}
|
||||
};
|
||||
|
||||
@ -352,5 +362,29 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
if (activeOperations++ == 0)
|
||||
OperationStarted?.Invoke();
|
||||
}
|
||||
|
||||
private void ensureButtonsOnScreen()
|
||||
{
|
||||
buttons.Position = Vector2.Zero;
|
||||
|
||||
var buttonsQuad = buttons.ScreenSpaceDrawQuad;
|
||||
var thisQuad = ScreenSpaceDrawQuad;
|
||||
|
||||
// Shrink the parent quad to give a bit of padding so the buttons don't stick *right* on the border.
|
||||
// AABBFloat assumes no rotation. one would hope the whole editor is not being rotated.
|
||||
var parentQuad = Parent.ScreenSpaceDrawQuad.AABBFloat.Shrink(ToLocalSpace(thisQuad.TopLeft + new Vector2(button_padding * 2)));
|
||||
|
||||
float leftExcess = buttonsQuad.TopLeft.X - parentQuad.TopLeft.X;
|
||||
float rightExcess = parentQuad.TopRight.X - buttonsQuad.TopRight.X;
|
||||
float bottomExcess = thisQuad.BottomLeft.Y + buttonsQuad.Height - parentQuad.BottomLeft.Y;
|
||||
|
||||
if (leftExcess < 0)
|
||||
buttons.X += ToLocalSpace(thisQuad.TopLeft - new Vector2(leftExcess)).X;
|
||||
else if (rightExcess < 0)
|
||||
buttons.X -= ToLocalSpace(thisQuad.TopLeft - new Vector2(rightExcess)).X;
|
||||
|
||||
if (bottomExcess > 0)
|
||||
buttons.Y += ToLocalSpace(thisQuad.TopLeft - new Vector2(bottomExcess)).X;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user