2021-05-11 12:12:24 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System ;
2021-05-13 12:16:20 +08:00
using Newtonsoft.Json ;
2021-05-11 12:12:24 +08:00
using osu.Framework.Graphics ;
using osu.Framework.Graphics.Containers ;
namespace osu.Game.Skinning
{
/// <summary>
2021-05-11 16:48:08 +08:00
/// A container which is serialised and can encapsulate multiple skinnable elements into a single return type (for consumption via <see cref="ISkin.GetDrawableComponent"/>.
2021-05-11 12:12:24 +08:00
/// Will also optionally apply default cross-element layout dependencies when initialised from a non-deserialised source.
/// </summary>
2021-05-13 12:16:20 +08:00
[Serializable]
2021-05-13 16:03:17 +08:00
public class SkinnableTargetWrapper : Container , ISkinnableComponent
2021-05-11 12:12:24 +08:00
{
2021-05-13 16:03:17 +08:00
public bool IsEditable = > false ;
2021-05-11 12:12:24 +08:00
private readonly Action < Container > applyDefaults ;
/// <summary>
/// Construct a wrapper with defaults that should be applied once.
/// </summary>
2021-05-13 15:43:42 +08:00
/// <param name="applyDefaults">A function to apply the default layout.</param>
2021-05-11 12:12:24 +08:00
public SkinnableTargetWrapper ( Action < Container > applyDefaults )
: this ( )
{
this . applyDefaults = applyDefaults ;
}
2021-05-13 12:16:20 +08:00
[JsonConstructor]
2021-05-11 12:12:24 +08:00
public SkinnableTargetWrapper ( )
{
RelativeSizeAxes = Axes . Both ;
}
protected override void LoadComplete ( )
{
base . LoadComplete ( ) ;
// schedule is required to allow children to run their LoadComplete and take on their correct sizes.
Schedule ( ( ) = > applyDefaults ? . Invoke ( this ) ) ;
}
}
}