Skip to content

Commit

Permalink
Merge pull request #1476 from Tom94/fix-wrapping
Browse files Browse the repository at this point in the history
Fix Incorrect Behaviour of ContainerExtensions.Wrap in Certain Cases
  • Loading branch information
smoogipoo committed Mar 22, 2018
2 parents 241133f + 7c30de2 commit 45bc04a
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
90 changes: 90 additions & 0 deletions osu.Framework.Tests/Visual/TestCaseEffects.cs
Expand Up @@ -141,6 +141,96 @@ public TestCaseEffects()
}),
}
},
new Container
{
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = Color4.White,
Size = new Vector2(150, 40),
}.WithEffect(new GlowEffect
{
BlurSigma = new Vector2(3f),
Strength = 3f,
Colour = ColourInfo.GradientHorizontal(new Color4(1.2f, 0, 0, 1f), new Color4(0, 1f, 0, 1f)),
PadExtent = true,
}),
new SpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "Absolute Size",
TextSize = 32f,
Colour = Color4.Red,
Shadow = true,
}
}
},
new Container
{
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = Color4.White,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(1.1f, 1.1f),
}.WithEffect(new GlowEffect
{
BlurSigma = new Vector2(3f),
Strength = 3f,
Colour = ColourInfo.GradientHorizontal(new Color4(1.2f, 0, 0, 1f), new Color4(0, 1f, 0, 1f)),
PadExtent = true,
}),
new SpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "Relative Size",
TextSize = 32f,
Colour = Color4.Red,
Shadow = true,
},
}
},
new Container
{
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = Color4.White,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(1.1f, 1.1f),
Rotation = 10,
}.WithEffect(new GlowEffect
{
BlurSigma = new Vector2(3f),
Strength = 3f,
Colour = ColourInfo.GradientHorizontal(new Color4(1.2f, 0, 0, 1f), new Color4(0, 1f, 0, 1f)),
PadExtent = true,
}),
new SpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "Rotation",
TextSize = 32f,
Colour = Color4.Red,
Shadow = true,
},
}
},
}
});
}
Expand Down
16 changes: 16 additions & 0 deletions osu.Framework/Graphics/Containers/ContainerExtensions.cs
Expand Up @@ -33,11 +33,27 @@ public static class ContainerExtensions
container.Anchor = drawable.Anchor;
container.Origin = drawable.Origin;
container.Position = drawable.Position;
container.Rotation = drawable.Rotation;

drawable.Position = Vector2.Zero;
drawable.Rotation = 0;
drawable.Anchor = Anchor.TopLeft;
drawable.Origin = Anchor.TopLeft;

// For anchor/origin positioning to be preserved correctly,
// relatively sized axes must be lifted to the wrapping container.
if ((container.RelativeSizeAxes & Axes.X) > 0)
{
container.Width = drawable.Width;
drawable.Width = 1;
}

if ((container.RelativeSizeAxes & Axes.Y) > 0)
{
container.Height = drawable.Height;
drawable.Height = 1;
}

container.Add(drawable);

return container;
Expand Down

0 comments on commit 45bc04a

Please sign in to comment.