// 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.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics.Primitives; using osu.Framework.Platform; namespace osu.Framework.Graphics.Containers { /// /// A that is automatically cached and provides a representing /// the desired safe area margins. Should be used in conjunction with child s. /// The root of the scenegraph contains an instance of this container, with automatically bound /// to the host 's . /// [Cached(typeof(ISafeArea))] public class SafeAreaDefiningContainer : Container, ISafeArea { private readonly bool usesCustomBinding; private readonly BindableSafeArea safeArea = new BindableSafeArea(); /// /// Initialises a by optionally providing a custom . /// If no such binding is provided, the container will default to . /// /// The custom to bind to, if required. public SafeAreaDefiningContainer(BindableSafeArea safeArea = null) { if (safeArea != null) { usesCustomBinding = true; this.safeArea.BindTo(safeArea); } } [BackgroundDependencyLoader] private void load(GameHost host) { if (!usesCustomBinding && host.Window != null) safeArea.BindTo(host.Window.SafeAreaPadding); } #region ISafeArea Implementation RectangleF ISafeArea.AvailableNonSafeSpace => DrawRectangle; Quad ISafeArea.ExpandRectangleToSpaceOfOtherDrawable(IDrawable other) => ToSpaceOfOtherDrawable(DrawRectangle, other); BindableSafeArea ISafeArea.SafeAreaPadding => safeArea; #endregion } }