mirror of https://github.com/ppy/osu
Apply nullability to `SkinnableDrawable`
This commit is contained in:
parent
bf26dbffc2
commit
d4251271d8
|
@ -1,8 +1,6 @@
|
|||
// 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.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using osu.Framework.Caching;
|
||||
using osu.Framework.Graphics;
|
||||
|
@ -19,7 +17,7 @@ public class SkinnableDrawable : SkinReloadableDrawable
|
|||
/// <summary>
|
||||
/// The displayed component.
|
||||
/// </summary>
|
||||
public Drawable Drawable { get; private set; }
|
||||
public Drawable Drawable { get; private set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the drawable component should be centered in available space.
|
||||
|
@ -43,7 +41,7 @@ public class SkinnableDrawable : SkinReloadableDrawable
|
|||
/// <param name="component">The namespace-complete resource name for this skinnable element.</param>
|
||||
/// <param name="defaultImplementation">A function to create the default skin implementation of this element.</param>
|
||||
/// <param name="confineMode">How (if at all) the <see cref="Drawable"/> should be resize to fit within our own bounds.</param>
|
||||
public SkinnableDrawable(ISkinComponent component, Func<ISkinComponent, Drawable> defaultImplementation = null, ConfineMode confineMode = ConfineMode.NoScaling)
|
||||
public SkinnableDrawable(ISkinComponent component, Func<ISkinComponent, Drawable>? defaultImplementation = null, ConfineMode confineMode = ConfineMode.NoScaling)
|
||||
: this(component, confineMode)
|
||||
{
|
||||
createDefault = defaultImplementation;
|
||||
|
@ -62,7 +60,7 @@ protected SkinnableDrawable(ISkinComponent component, ConfineMode confineMode =
|
|||
/// </summary>
|
||||
public void ResetAnimation() => (Drawable as IFramedAnimation)?.GotoFrame(0);
|
||||
|
||||
private readonly Func<ISkinComponent, Drawable> createDefault;
|
||||
private readonly Func<ISkinComponent, Drawable>? createDefault;
|
||||
|
||||
private readonly Cached scaling = new Cached();
|
||||
|
||||
|
@ -77,30 +75,28 @@ protected SkinnableDrawable(ISkinComponent component, ConfineMode confineMode =
|
|||
|
||||
protected override void SkinChanged(ISkinSource skin)
|
||||
{
|
||||
Drawable = skin.GetDrawableComponent(Component);
|
||||
var retrieved = skin.GetDrawableComponent(Component);
|
||||
|
||||
isDefault = false;
|
||||
|
||||
if (Drawable == null)
|
||||
if (retrieved == null)
|
||||
{
|
||||
Drawable = CreateDefault(Component);
|
||||
isDefault = true;
|
||||
}
|
||||
|
||||
if (Drawable != null)
|
||||
{
|
||||
scaling.Invalidate();
|
||||
|
||||
if (CentreComponent)
|
||||
{
|
||||
Drawable.Origin = Anchor.Centre;
|
||||
Drawable.Anchor = Anchor.Centre;
|
||||
}
|
||||
|
||||
InternalChild = Drawable;
|
||||
}
|
||||
else
|
||||
ClearInternal();
|
||||
{
|
||||
Drawable = retrieved;
|
||||
isDefault = false;
|
||||
}
|
||||
|
||||
scaling.Invalidate();
|
||||
|
||||
if (CentreComponent)
|
||||
{
|
||||
Drawable.Origin = Anchor.Centre;
|
||||
Drawable.Anchor = Anchor.Centre;
|
||||
}
|
||||
|
||||
InternalChild = Drawable;
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
|
@ -111,7 +107,7 @@ protected override void Update()
|
|||
{
|
||||
try
|
||||
{
|
||||
if (Drawable == null || (isDefault && !ApplySizeRestrictionsToDefault)) return;
|
||||
if (isDefault && !ApplySizeRestrictionsToDefault) return;
|
||||
|
||||
switch (confineMode)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue