// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using osu.Framework.Graphics; namespace osu.Framework.Layout { /// /// A member that represents the validation state of the layout of a . /// Can be invalidated according to state changes in a (via flags), and validated on-demand when the layout has been re-computed. /// public class LayoutValue : LayoutMember { /// /// Creates a new . /// /// The flags that will invalidate this . /// The source of the invalidation. /// Any extra conditions that must be satisfied before this is invalidated. public LayoutValue(Invalidation invalidation, InvalidationSource source = InvalidationSource.Default, InvalidationConditionDelegate conditions = null) : base(invalidation, source, conditions) { } /// /// Validates this . /// public new void Validate() => base.Validate(); } /// /// A member that represents the validation state of a value in the layout of a . /// Can be invalidated according to state changes in a (via flags), and validated when an up-to-date value is set. /// /// The type of value stored. public class LayoutValue : LayoutMember { /// /// Creates a new . /// /// The flags that will invalidate this . /// The source of the invalidation. /// Any extra conditions that must be satisfied before this is invalidated. public LayoutValue(Invalidation invalidation, InvalidationSource source = InvalidationSource.Default, InvalidationConditionDelegate conditions = null) : base(invalidation, source, conditions) { } private T value; /// /// Gets or sets the current value. /// /// If accessed while is false. public T Value { get { if (!IsValid) throw new InvalidOperationException($"May not query {nameof(Value)} of an invalid {nameof(LayoutValue)}."); return value; } set { this.value = value; Validate(); } } public static implicit operator T(LayoutValue layoutValue) => layoutValue.Value; } }