mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 03:02:54 +08:00
Added GrowToFitContent Parameter.
This commit is contained in:
parent
43f2ba6596
commit
cda7faecf7
@ -24,6 +24,27 @@ namespace osu.Game.Graphics.Containers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public ScaleMode Scaling { get; set; } = ScaleMode.Vertical;
|
public ScaleMode Scaling { get; set; } = ScaleMode.Vertical;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If this is true, all wrapper containers will be set to grow with their content
|
||||||
|
/// and not shrink back, this is used to fix the position of children that change
|
||||||
|
/// in size when using AutoSizeAxes.
|
||||||
|
/// </summary>
|
||||||
|
public bool GrowToFitContent
|
||||||
|
{
|
||||||
|
get => growToFitContent;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (growToFitContent != value)
|
||||||
|
{
|
||||||
|
foreach (GrowToFitContainer c in Children)
|
||||||
|
c.GrowToFitContentUpdated = true;
|
||||||
|
growToFitContent = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool growToFitContent = true;
|
||||||
|
|
||||||
private readonly LayoutValue layout = new LayoutValue(Invalidation.DrawInfo, InvalidationSource.Parent);
|
private readonly LayoutValue layout = new LayoutValue(Invalidation.DrawInfo, InvalidationSource.Parent);
|
||||||
|
|
||||||
public UprightAspectMaintainingContainer()
|
public UprightAspectMaintainingContainer()
|
||||||
@ -44,10 +65,11 @@ namespace osu.Game.Graphics.Containers
|
|||||||
|
|
||||||
public override void Add(Drawable drawable)
|
public override void Add(Drawable drawable)
|
||||||
{
|
{
|
||||||
base.Add(new GrowToFitContainer
|
var wrapper = new GrowToFitContainer();
|
||||||
{
|
wrapper.Wrap(drawable);
|
||||||
Child = drawable
|
wrapper.AutoSizeAxes = Axes.None;
|
||||||
});
|
drawable.Origin = drawable.Anchor = Anchor.Centre;
|
||||||
|
base.Add(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -58,7 +80,7 @@ namespace osu.Game.Graphics.Containers
|
|||||||
// Decomposes the inverse of the parent DrawInfo.Matrix into rotation, shear and scale.
|
// Decomposes the inverse of the parent DrawInfo.Matrix into rotation, shear and scale.
|
||||||
var parentMatrix = Parent.DrawInfo.Matrix;
|
var parentMatrix = Parent.DrawInfo.Matrix;
|
||||||
|
|
||||||
// Remove Translation.
|
// Remove Translation.>
|
||||||
parentMatrix.M31 = 0.0f;
|
parentMatrix.M31 = 0.0f;
|
||||||
parentMatrix.M32 = 0.0f;
|
parentMatrix.M32 = 0.0f;
|
||||||
|
|
||||||
@ -108,17 +130,55 @@ namespace osu.Game.Graphics.Containers
|
|||||||
|
|
||||||
public class GrowToFitContainer : Container
|
public class GrowToFitContainer : Container
|
||||||
{
|
{
|
||||||
|
private readonly LayoutValue layout = new LayoutValue(Invalidation.RequiredParentSizeToFit, InvalidationSource.Child);
|
||||||
|
|
||||||
|
private Vector2 maxChildSize;
|
||||||
|
|
||||||
|
public bool GrowToFitContentUpdated { get; set; }
|
||||||
|
|
||||||
|
public GrowToFitContainer()
|
||||||
|
{
|
||||||
|
AddLayout(layout);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
if ((Child.RelativeSizeAxes & Axes.X) != 0)
|
UprightAspectMaintainingContainer parent = (UprightAspectMaintainingContainer)Parent;
|
||||||
RelativeSizeAxes |= Axes.X;
|
|
||||||
else
|
|
||||||
Width = Math.Max(Child.Width, Width);
|
|
||||||
|
|
||||||
if ((Child.RelativeSizeAxes & Axes.Y) != 0)
|
if (!layout.IsValid || GrowToFitContentUpdated)
|
||||||
RelativeSizeAxes |= Axes.Y;
|
{
|
||||||
else
|
if ((Child.RelativeSizeAxes & Axes.X) != 0)
|
||||||
Height = Math.Max(Child.Height, Height);
|
RelativeSizeAxes |= Axes.X;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (parent.GrowToFitContent)
|
||||||
|
Width = Math.Max(Child.Width * Child.Scale.X, maxChildSize.X);
|
||||||
|
else
|
||||||
|
Width = Child.Width * Child.Scale.X;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((Child.RelativeSizeAxes & Axes.Y) != 0)
|
||||||
|
RelativeSizeAxes |= Axes.Y;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (parent.GrowToFitContent)
|
||||||
|
Height = Math.Max(Child.Height * Child.Scale.Y, maxChildSize.Y);
|
||||||
|
else
|
||||||
|
Height = Child.Height * Child.Scale.Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset max_child_size or update it
|
||||||
|
if (!parent.GrowToFitContent)
|
||||||
|
maxChildSize = Child.Size;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
maxChildSize.X = MathF.Max(maxChildSize.X, Child.Size.X);
|
||||||
|
maxChildSize.Y = MathF.Max(maxChildSize.Y, Child.Size.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
GrowToFitContentUpdated = false;
|
||||||
|
layout.Validate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user