Add padding and avoid using invalidation (triggers too often when toolbar is being toggled)

This commit is contained in:
Dean Herbert 2022-06-06 18:27:41 +09:00
parent 003a3de270
commit a8764b67e1
1 changed files with 19 additions and 3 deletions

View File

@ -15,6 +15,7 @@
using osu.Game.Input.Bindings;
using osu.Game.Screens;
using osu.Game.Screens.Edit.Components;
using osuTK;
namespace osu.Game.Skinning.Editor
{
@ -36,6 +37,8 @@ public class SkinEditorOverlay : OverlayContainer, IKeyBindingHandler<GlobalActi
private OsuScreen lastTargetScreen;
private Vector2 lastDrawSize;
public SkinEditorOverlay(ScalingContainer scalingContainer)
{
this.scalingContainer = scalingContainer;
@ -92,18 +95,31 @@ protected override bool OnInvalidate(Invalidation invalidation, InvalidationSour
return base.OnInvalidate(invalidation, source);
}
protected override void Update()
{
base.Update();
if (game.DrawSize != lastDrawSize)
{
lastDrawSize = game.DrawSize;
updateScreenSizing();
}
}
private void updateScreenSizing()
{
if (skinEditor?.State.Value != Visibility.Visible) return;
float relativeSidebarWidth = EditorSidebar.WIDTH / DrawWidth;
float relativeToolbarHeight = (SkinEditorSceneLibrary.HEIGHT + SkinEditor.MENU_HEIGHT) / DrawHeight;
const float padding = 10;
float relativeSidebarWidth = (EditorSidebar.WIDTH + padding) / DrawWidth;
float relativeToolbarHeight = (SkinEditorSceneLibrary.HEIGHT + SkinEditor.MENU_HEIGHT + padding) / DrawHeight;
var rect = new RectangleF(
relativeSidebarWidth,
relativeToolbarHeight,
1 - relativeSidebarWidth * 2,
1f - relativeToolbarHeight);
1f - relativeToolbarHeight - padding / DrawHeight);
scalingContainer.SetCustomRect(rect, true);
}