1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 17:43:05 +08:00

Merge pull request #10695 from peppy/fix-skinnable-test-scene

Fix SkinnableTestScene's autosize propagation
This commit is contained in:
Dean Herbert 2020-11-05 20:48:36 +09:00 committed by GitHub
commit 309b1d6334
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -65,17 +65,15 @@ namespace osu.Game.Tests.Visual
private Drawable createProvider(Skin skin, Func<Drawable> creationFunction, IBeatmap beatmap) private Drawable createProvider(Skin skin, Func<Drawable> creationFunction, IBeatmap beatmap)
{ {
var created = creationFunction(); var created = creationFunction();
createdDrawables.Add(created); createdDrawables.Add(created);
var autoSize = created.RelativeSizeAxes == Axes.None; SkinProvidingContainer mainProvider;
Container childContainer;
OutlineBox outlineBox;
SkinProvidingContainer skinProvider;
var mainProvider = new SkinProvidingContainer(skin) var children = new Container
{
RelativeSizeAxes = !autoSize ? Axes.Both : Axes.None,
AutoSizeAxes = autoSize ? Axes.Both : Axes.None,
};
return new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
BorderColour = Color4.White, BorderColour = Color4.White,
@ -96,27 +94,47 @@ namespace osu.Game.Tests.Visual
Scale = new Vector2(1.5f), Scale = new Vector2(1.5f),
Padding = new MarginPadding(5), Padding = new MarginPadding(5),
}, },
new Container childContainer = new Container
{ {
RelativeSizeAxes = !autoSize ? Axes.Both : Axes.None,
AutoSizeAxes = autoSize ? Axes.Both : Axes.None,
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Children = new Drawable[] Children = new Drawable[]
{ {
new OutlineBox { Alpha = autoSize ? 1 : 0 }, outlineBox = new OutlineBox(),
mainProvider.WithChild( (mainProvider = new SkinProvidingContainer(skin)).WithChild(
new SkinProvidingContainer(Ruleset.Value.CreateInstance().CreateLegacySkinProvider(mainProvider, beatmap)) skinProvider = new SkinProvidingContainer(Ruleset.Value.CreateInstance().CreateLegacySkinProvider(mainProvider, beatmap))
{ {
Child = created, Child = created,
RelativeSizeAxes = !autoSize ? Axes.Both : Axes.None,
AutoSizeAxes = autoSize ? Axes.Both : Axes.None,
} }
) )
} }
}, },
} }
}; };
// run this once initially to bring things into a sane state as early as possible.
updateSizing();
// run this once after construction to handle the case the changes are made in a BDL/LoadComplete call.
Schedule(updateSizing);
return children;
void updateSizing()
{
var autoSize = created.RelativeSizeAxes == Axes.None;
foreach (var c in new[] { mainProvider, childContainer, skinProvider })
{
c.RelativeSizeAxes = Axes.None;
c.AutoSizeAxes = Axes.None;
c.RelativeSizeAxes = !autoSize ? Axes.Both : Axes.None;
c.AutoSizeAxes = autoSize ? Axes.Both : Axes.None;
}
outlineBox.Alpha = autoSize ? 1 : 0;
}
} }
/// <summary> /// <summary>