<commit_before>﻿//Copyright (c) 2007-2016 ppy Pty Ltd <<EMAIL>>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using System;
using osu.Framework.Graphics.Primitives;
using OpenTK;
using System.Diagnostics;

namespace osu.Framework.Graphics.Containers
{
    public class AutoSizeContainer : Container
    {
        protected bool RequireAutoSize => autoSizeUpdatePending && SizeMode != InheritMode.XY;

        internal event Action OnAutoSize;

        private bool autoSizeUpdatePending;

        public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)
        {
            if ((invalidation & Invalidation.SizeInParentSpace) > 0)
                autoSizeUpdatePending = true;

            bool alreadyInvalidated = base.Invalidate(invalidation, source, shallPropagate);

            return !alreadyInvalidated;
        }

        protected override Quad DrawQuadForBounds
        {
            get
            {
                if (SizeMode == InheritMode.XY) return base.DrawQuadForBounds;

                Vector2 size = Vector2.Zero;
                Vector2 maxInheritingSize = Vector2.One;

                // Find the maximum width/height of children
                foreach (Drawable c in CurrentChildren)
                {
                    if (!c.IsVisible)
                        continue;

                    Vector2 boundingSize = c.BoundingSize;
                    Vector2 inheritingSize = c.Size * c.Scale * ContentScale;

                    if ((c.SizeMode & InheritMode.X) == 0)
                        size.X = Math.Max(size.X, boundingSize.X);
                    else
                        maxInheritingSize.X = Math.Max(maxInheritingSize.X, inheritingSize.X);

                    if ((c.SizeMode & InheritMode.Y) == 0)
                        size.Y = Math.Max(size.Y, boundingSize.Y);
                    else
                        maxInheritingSize.Y = Math.Max(maxInheritingSize.Y, inheritingSize.Y);
                }

                if (size.X == 0) size.X = Parent?.ActualSize.X ?? 0;
                if (size.Y == 0) size.Y = Parent?.ActualSize.Y ?? 0;

                if ((SizeMode & InheritMode.X) > 0)
                    size.X = ActualSize.X;
                if ((SizeMode & InheritMode.Y) > 0)
                    size.Y = ActualSize.Y;

                return new Quad(0, 0, size.X * maxInheritingSize.X, size.Y * maxInheritingSize.Y);
            }
        }

        protected override bool UpdateChildrenLife()
        {
            bool childChangedStatus = base.UpdateChildrenLife();
            if (childChangedStatus)
                Invalidate(Invalidation.ScreenSpaceQuad);

            return childChangedStatus;
        }

        internal override void UpdateSubTree()
        {
            base.UpdateSubTree();

            if (RequireAutoSize)
            {
                Vector2 b = DrawQuadForBounds.BottomRight;

                size = new Vector2((SizeMode & InheritMode.X) > 0 ? Size.X : b.X, (SizeMode & InheritMode.Y) > 0 ? Size.Y : b.Y);

                // This triggers re-positioning of all children according.
                // It is required even if Size does coincidentally not change, since children
                // might still have moved.
                Invalidate(Invalidation.ScreenSpaceQuad);
<commit_msg>Simplify AutoSize further.<commit_after>﻿//Copyright (c) 2007-2016 ppy Pty Ltd <<EMAIL>>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using System;
using osu.Framework.Graphics.Primitives;
using OpenTK;
using System.Diagnostics;

namespace osu.Framework.Graphics.Containers
{
    public class AutoSizeContainer : Container
    {
        protected bool RequireAutoSize => autoSizeUpdatePending && SizeMode != InheritMode.XY;

        internal event Action OnAutoSize;

        private bool autoSizeUpdatePending;

        public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)
        {
            if ((invalidation & Invalidation.SizeInParentSpace) > 0)
                autoSizeUpdatePending = true;

            bool alreadyInvalidated = base.Invalidate(invalidation, source, shallPropagate);

            return !alreadyInvalidated;
        }

        protected override Quad DrawQuadForBounds
        {
            get
            {
                if (SizeMode == InheritMode.XY) return base.DrawQuadForBounds;

                Vector2 size = Vector2.Zero;
                Vector2 maxInheritingSize = Vector2.One;

                // Find the maximum width/height of children
                foreach (Drawable c in CurrentChildren)
                {
                    if (!c.IsVisible)
                        continue;

                    Vector2 boundingSize = c.BoundingSize;
                    Vector2 inheritingSize = c.Size * c.Scale * ContentScale;

                    if ((c.SizeMode & InheritMode.X) == 0)
                        size.X = Math.Max(size.X, boundingSize.X);
                    else
                        maxInheritingSize.X = Math.Max(maxInheritingSize.X, inheritingSize.X);

                    if ((c.SizeMode & InheritMode.Y) == 0)
                        size.Y = Math.Max(size.Y, boundingSize.Y);
                    else
                        maxInheritingSize.Y = Math.Max(maxInheritingSize.Y, inheritingSize.Y);
                }

                if (size.X == 0) size.X = Parent?.ActualSize.X ?? 0;
                if (size.Y == 0) size.Y = Parent?.ActualSize.Y ?? 0;

                if ((SizeMode & InheritMode.X) > 0)
                    size.X = ActualSize.X;
                if ((SizeMode & InheritMode.Y) > 0)
                    size.Y = ActualSize.Y;

                return new Quad(0, 0, size.X * maxInheritingSize.X, size.Y * maxInheritingSize.Y);
            }
        }

        protected override bool UpdateChildrenLife()
        {
            bool childChangedStatus = base.UpdateChildrenLife();
            if (childChangedStatus)
                Invalidate(Invalidation.ScreenSpaceQuad);

            return childChangedStatus;
        }

        internal override void UpdateSubTree()
        {
            base.UpdateSubTree();

            if (RequireAutoSize)
            {
                Vector2 b = DrawQuadForBounds.BottomRight;

                Size = new Vector2((SizeMode & InheritMode.X) > 0 ? Size.X : b.X, (SizeMode & InheritMode.Y) > 0 ? Size.Y : b.Y);

{'fraction_non_alphanumeric': 0.0881104033970276, 'fraction_numerical': 0.008795875037913254, 'mean_word_length': 1.6635702746365104, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 2, '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': '7387528', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1719, 'n_words': 408}