<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.Drawables;
using osu.Framework.Graphics.Transformations;
using osu.Framework.Input;
using OpenTK;
using OpenTK.Graphics;

namespace osu.Framework.Graphics.Containers
{
    public class ScrollContainer : LargeContainer
    {
        /// <summary>
        /// Determines whether the scroll dragger appears on the left side. If not, then it always appears on the right side.
        /// </summary>
        public bool ScrollDraggerOnLeft
        {
            get { return scrollbar.Anchor == Anchor.TopLeft; }

            set
            {
                scrollbar.Anchor = value ? Anchor.TopLeft : Anchor.TopRight;
                scrollbar.Origin = value ? Anchor.TopLeft : Anchor.TopRight;
            }
        }

        private AutoSizeContainer content = new AutoSizeContainer { SizeMode = InheritMode.X };
        private ScrollBar scrollbar;

        /// <summary>
        /// Vertical size of available content (content.Size)
        /// </summary>
        private float availableContent;

        private float displayableContent => ActualSize.Y;

        private float current;

        private float currentClamped => MathHelper.Clamp(current, 0, availableContent - displayableContent);

        protected override Container AddTarget => content;

        public override void Load()
        {
            base.Load();

            Masking = true;

            Add(content);
            AddTopLevel(scrollbar = new ScrollBar(offset));

            content.OnAutoSize += contentAutoSize;
        }

        public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)
        {
            if (!base.Invalidate(invalidation, source, shallPropagate))
                return false;

            if ((invalidation & Invalidation.SizeInParentSpace) > 0)
                updateSize();

            return true;
        }

        private void contentAutoSize()
        {
            if (availableContent == content.Size.Y)
                return;<commit_msg>Fix ScrollContainer not correctly updating scrollbar when conatainer is empty.<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.Drawables;
using osu.Framework.Graphics.Transformations;
using osu.Framework.Input;
using OpenTK;
using OpenTK.Graphics;

namespace osu.Framework.Graphics.Containers
{
    public class ScrollContainer : LargeContainer
    {
        /// <summary>
        /// Determines whether the scroll dragger appears on the left side. If not, then it always appears on the right side.
        /// </summary>
        public bool ScrollDraggerOnLeft
        {
            get { return scrollbar.Anchor == Anchor.TopLeft; }

            set
            {
                scrollbar.Anchor = value ? Anchor.TopLeft : Anchor.TopRight;
                scrollbar.Origin = value ? Anchor.TopLeft : Anchor.TopRight;
            }
        }

        private AutoSizeContainer content = new AutoSizeContainer { SizeMode = InheritMode.X };
        private ScrollBar scrollbar;

        /// <summary>
        /// Vertical size of available content (content.Size)
        /// </summary>
        private float availableContent = -1;

        private float displayableContent => ActualSize.Y;

        private float current;

        private float currentClamped => MathHelper.Clamp(current, 0, availableContent - displayableContent);

        protected override Container AddTarget => content;

        public override void Load()
        {
            base.Load();

            Masking = true;

            Add(content);
            AddTopLevel(scrollbar = new ScrollBar(offset));
            content.OnAutoSize += contentAutoSize;
        }

        public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)
        {
            if (!base.Invalidate(invalidation, source, shallPropagate))
                return false;

            if ((invalidation & Invalidation.SizeInParentSpace) > 0)
                updateSize();

            return true;
        }

        private void contentAutoSize()
        {
            if (availableContent == content.Size.Y)
                return;
{'fraction_non_alphanumeric': 0.0861275476660092, 'fraction_numerical': 0.0046022353714661405, 'mean_word_length': 2.1281699794379714, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, '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': '5521745', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1119, 'n_words': 319}