mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 14:46:38 +09:00
Allow skinnable drawables to be of non-restricted size
This commit is contained in:
@ -3,13 +3,14 @@
|
||||
|
||||
using System;
|
||||
using osu.Framework.Graphics;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Skinning
|
||||
{
|
||||
public class SkinnableDrawable : SkinnableDrawable<Drawable>
|
||||
{
|
||||
public SkinnableDrawable(string name, Func<string, Drawable> defaultImplementation, bool fallback = true)
|
||||
: base(name, defaultImplementation, fallback)
|
||||
public SkinnableDrawable(string name, Func<string, Drawable> defaultImplementation, bool fallback = true, bool restrictSize = true)
|
||||
: base(name, defaultImplementation, fallback, restrictSize)
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -21,10 +22,16 @@ namespace osu.Game.Skinning
|
||||
|
||||
private readonly string componentName;
|
||||
|
||||
public SkinnableDrawable(string name, Func<string, T> defaultImplementation, bool fallback = true) : base(fallback)
|
||||
/// <summary>
|
||||
/// Whether a user-skin drawable should be limited to the size of our parent.
|
||||
/// </summary>
|
||||
public readonly bool RestrictSize;
|
||||
|
||||
public SkinnableDrawable(string name, Func<string, T> defaultImplementation, bool fallback = true, bool restrictSize = true) : base(fallback)
|
||||
{
|
||||
componentName = name;
|
||||
createDefault = defaultImplementation;
|
||||
RestrictSize = restrictSize;
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
}
|
||||
@ -32,11 +39,25 @@ namespace osu.Game.Skinning
|
||||
protected override void SkinChanged(Skin skin, bool allowFallback)
|
||||
{
|
||||
var drawable = skin.GetDrawableComponent(componentName);
|
||||
if (drawable == null && allowFallback)
|
||||
if (drawable != null)
|
||||
{
|
||||
if (RestrictSize)
|
||||
{
|
||||
drawable.RelativeSizeAxes = Axes.Both;
|
||||
drawable.Size = Vector2.One;
|
||||
drawable.FillMode = FillMode.Fit;
|
||||
}
|
||||
}
|
||||
else if (allowFallback)
|
||||
drawable = createDefault(componentName);
|
||||
|
||||
if (drawable != null)
|
||||
{
|
||||
drawable.Origin = Anchor.Centre;
|
||||
drawable.Anchor = Anchor.Centre;
|
||||
|
||||
InternalChild = drawable;
|
||||
}
|
||||
else
|
||||
ClearInternal();
|
||||
}
|
||||
|
Reference in New Issue
Block a user