// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osu.Framework.Graphics; using osu.Framework.Statistics; namespace osu.Framework.Layout { /// /// A member that represents a part of the layout of a . /// Can be invalidated according to state changes in a (via flags). /// public abstract class LayoutMember { /// /// The flags this responds to. /// public readonly Invalidation Invalidation; /// /// Any extra conditions that must be satisfied before this is invalidated. /// public readonly InvalidationConditionDelegate Conditions; /// /// The source of this responds to. /// public readonly InvalidationSource Source; /// /// The containing this . /// internal Drawable Parent; /// /// 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. protected LayoutMember(Invalidation invalidation, InvalidationSource source = InvalidationSource.Default, InvalidationConditionDelegate conditions = null) { Invalidation = invalidation; Conditions = conditions; Source = source; } /// /// Whether this is valid. /// public bool IsValid { get; private set; } /// /// Invalidates this . /// /// Whether any invalidation occurred. public bool Invalidate() { if (!IsValid) return false; IsValid = false; FrameStatistics.Increment(StatisticsCounterType.Invalidations); return true; } /// /// Validates this . /// protected void Validate() { if (IsValid) return; IsValid = true; Parent?.ValidateSuperTree(Invalidation); FrameStatistics.Increment(StatisticsCounterType.Refreshes); } } /// /// The delegate that provides extra conditions for an invalidation to occur. /// /// The to be invalidated. /// The flags. public delegate bool InvalidationConditionDelegate(Drawable source, Invalidation invalidation); }