Avoid multiple synchronous overheads in SettingsItem

This commit is contained in:
Dean Herbert
2021-08-16 19:16:48 +09:00
parent 237d3e656b
commit 8d051d9fa0

View File

@ -93,15 +93,13 @@ namespace osu.Game.Overlays.Settings
public bool MatchingFilter public bool MatchingFilter
{ {
set => this.FadeTo(value ? 1 : 0); set => Alpha = value ? 1 : 0;
} }
public bool FilteringActive { get; set; } public bool FilteringActive { get; set; }
public event Action SettingChanged; public event Action SettingChanged;
private readonly RestoreDefaultValueButton<T> restoreDefaultButton;
protected SettingsItem() protected SettingsItem()
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
@ -110,7 +108,6 @@ namespace osu.Game.Overlays.Settings
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
restoreDefaultButton = new RestoreDefaultValueButton<T>(),
FlowContent = new FillFlowContainer FlowContent = new FillFlowContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
@ -122,7 +119,11 @@ namespace osu.Game.Overlays.Settings
}, },
}, },
}; };
}
[BackgroundDependencyLoader]
private void load()
{
// all bindable logic is in constructor intentionally to support "CreateSettingsControls" being used in a context it is // all bindable logic is in constructor intentionally to support "CreateSettingsControls" being used in a context it is
// never loaded, but requires bindable storage. // never loaded, but requires bindable storage.
if (controlWithCurrent == null) if (controlWithCurrent == null)
@ -130,14 +131,15 @@ namespace osu.Game.Overlays.Settings
controlWithCurrent.Current.ValueChanged += _ => SettingChanged?.Invoke(); controlWithCurrent.Current.ValueChanged += _ => SettingChanged?.Invoke();
controlWithCurrent.Current.DisabledChanged += _ => updateDisabled(); controlWithCurrent.Current.DisabledChanged += _ => updateDisabled();
}
protected override void LoadComplete()
{
base.LoadComplete();
// intentionally done before LoadComplete to avoid overhead.
if (ShowsDefaultIndicator) if (ShowsDefaultIndicator)
restoreDefaultButton.Current = controlWithCurrent.Current; {
AddInternal(new RestoreDefaultValueButton<T>
{
Current = controlWithCurrent.Current,
});
}
} }
private void updateDisabled() private void updateDisabled()