<commit_before>﻿// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;

namespace osu.Framework.Graphics.Containers
{
    /// <summary>
    /// A <see cref="Container"/> that will apply negative <see cref="Container.Padding"/> to snap the edges to
    /// the nearest cached <see cref="ISnapTargetContainer"/>.
    /// Individual <see cref="Edges"/> may be snapped by setting the <see cref="SnappedEdges"/> property.
    /// Note that children within the negative padding will not be drawn if a parent <see cref="Drawable"/>
    /// has <see cref="CompositeDrawable.Masking"/> set to true.
    /// </summary>
    public class EdgeSnappingContainer : Container<Drawable>
    {
        [Resolved(CanBeNull = true)]
        private ISnapTargetContainer snapTargetContainer { get; set; }

        public virtual ISnapTargetContainer SnapTarget => snapTargetContainer;

        /// <summary>
        /// The <see cref="Edges"/> that should be snapped to the nearest <see cref="ISnapTargetContainer"/>.
        /// Defaults to <see cref="Edges.None"/>.
        /// </summary>
        public Edges SnappedEdges { get; set; } = Edges.None;

        protected override void UpdateAfterChildren()
        {
            base.UpdateAfterChildren();
            UpdatePadding();
        }

        protected void UpdatePadding() => Padding = SnappedPadding();

        protected virtual MarginPadding SnappedPadding()
        {
            if (SnapTarget == null)
                return new MarginPadding();

            var rect = SnapTarget.SnapRectangleToSpaceOfOtherDrawable(this);
            var left = SnappedEdges.HasFlag(Edges.Left) ? rect.TopLeft.X : 0;
            var top = SnappedEdges.HasFlag(Edges.Top) ? rect.TopLeft.Y : 0;
            var right = SnappedEdges.HasFlag(Edges.Right) ? DrawRectangle.BottomRight.X - rect.BottomRight.X : 0;
            var bottom = SnappedEdges.HasFlag(Edges.Bottom) ? DrawRectangle.BottomRight.Y - rect.BottomRight.Y : 0;

            return new MarginPadding { Left = left, Right = right, Top = top, Bottom = bottom };
        }
    }
}
<commit_msg>Update padding before child subtrees to ensure they are laid out correctly<commit_after>﻿// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;

namespace osu.Framework.Graphics.Containers
{
    /// <summary>
    /// A <see cref="Container"/> that will apply negative <see cref="Container.Padding"/> to snap the edges to
    /// the nearest cached <see cref="ISnapTargetContainer"/>.
    /// Individual <see cref="Edges"/> may be snapped by setting the <see cref="SnappedEdges"/> property.
    /// Note that children within the negative padding will not be drawn if a parent <see cref="Drawable"/>
    /// has <see cref="CompositeDrawable.Masking"/> set to true.
    /// </summary>
    public class EdgeSnappingContainer : Container<Drawable>
    {
        [Resolved(CanBeNull = true)]
        private ISnapTargetContainer snapTargetContainer { get; set; }

        public virtual ISnapTargetContainer SnapTarget => snapTargetContainer;

        /// <summary>
        /// The <see cref="Edges"/> that should be snapped to the nearest <see cref="ISnapTargetContainer"/>.
        /// Defaults to <see cref="Edges.None"/>.
        /// </summary>
        public Edges SnappedEdges { get; set; } = Edges.None;

        protected override void UpdateAfterChildrenLife()
        {
            base.UpdateAfterChildrenLife();
            UpdatePadding();
        }

        protected void UpdatePadding() => Padding = SnappedPadding();

        protected virtual MarginPadding SnappedPadding()
        {
            if (SnapTarget == null)
                return new MarginPadding();

            var rect = SnapTarget.SnapRectangleToSpaceOfOtherDrawable(this);
            var left = SnappedEdges.HasFlag(Edges.Left) ? rect.TopLeft.X : 0;
            var top = SnappedEdges.HasFlag(Edges.Top) ? rect.TopLeft.Y : 0;
            var right = SnappedEdges.HasFlag(Edges.Right) ? DrawRectangle.BottomRight.X - rect.BottomRight.X : 0;
            var bottom = SnappedEdges.HasFlag(Edges.Bottom) ? DrawRectangle.BottomRight.Y - rect.BottomRight.Y : 0;

            return new MarginPadding { Left = left, Right = right, Top = top, Bottom = bottom };
        }
    }
}

{'fraction_non_alphanumeric': 0.1120785889707524, 'fraction_numerical': 0.0017861129716454567, 'mean_word_length': 2.607085346215781, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3312681', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1206, 'n_words': 371}