// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; namespace osu.Framework.Bindables { /// /// A bindable which holds a reference to a bound target, allowing switching between targets and handling unbind/rebind. /// /// The type of our stored . public class BindableNumberWithCurrent : BindableNumber, IBindableWithCurrent where T : struct, IComparable, IConvertible, IEquatable { private BindableNumber currentBound; public Bindable Current { get => this; set { if (value == null) throw new ArgumentNullException(nameof(value)); if (currentBound != null) UnbindFrom(currentBound); BindTo(currentBound = (BindableNumber)value); } } public BindableNumberWithCurrent(T defaultValue = default) : base(defaultValue) { } protected override Bindable CreateInstance() => new BindableNumberWithCurrent(); } }