Initialise warning text flow lazily as most items will not use it

This commit is contained in:
Dean Herbert 2021-05-05 16:19:06 +09:00
parent 1288f69fad
commit 19ffcd00c2
1 changed files with 16 additions and 13 deletions

View File

@ -36,12 +36,15 @@ public abstract class SettingsItem<T> : Container, IFilterable, ISettingsItem, I
private SpriteText labelText;
private readonly OsuTextFlowContainer warningText;
private OsuTextFlowContainer warningText;
public bool ShowsDefaultIndicator = true;
public string TooltipText { get; set; }
[Resolved]
private OsuColour colours { get; set; }
public virtual LocalisableString LabelText
{
get => labelText?.Text ?? string.Empty;
@ -67,6 +70,18 @@ public string WarningText
{
set
{
if (warningText == null)
{
// construct lazily for cases where the label is not needed (may be provided by the Control).
FlowContent.Add(warningText = new OsuTextFlowContainer
{
Colour = colours.Yellow,
Margin = new MarginPadding { Bottom = 5 },
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
});
}
warningText.Alpha = string.IsNullOrWhiteSpace(value) ? 0 : 1;
warningText.Text = value;
}
@ -110,12 +125,6 @@ protected SettingsItem()
Children = new[]
{
Control = CreateControl(),
warningText = new OsuTextFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Alpha = 0,
},
},
},
};
@ -132,12 +141,6 @@ protected SettingsItem()
}
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
warningText.Colour = colours.Yellow;
}
private void updateDisabled()
{
if (labelText != null)