<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.

#nullable disable

using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Transforms;
using osu.Framework.Input.Events;
using osu.Framework.Layout;
using osu.Framework.Timing;
using osu.Framework.Utils;
using osu.Game.Graphics.Containers;
using osuTK;

namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
    public class ZoomableScrollContainer : OsuScrollContainer
    {
        /// <summary>
        /// The time to zoom into/out of a point.
        /// All user scroll input will be overwritten during the zoom transform.
        /// </summary>
        public double ZoomDuration;

        /// <summary>
        /// The easing with which to transform the zoom.
        /// </summary>
        public Easing ZoomEasing;

        private readonly Container zoomedContent;
        protected override Container<Drawable> Content => zoomedContent;

        /// <summary>
        /// The current zoom level of <see cref="ZoomableScrollContainer"/>.
        /// It may differ from <see cref="Zoom"/> during transitions.
        /// </summary>
        public float CurrentZoom { get; private set; } = 1;

        private bool isZoomSetUp;

        [Resolved(canBeNull: true)]
        private IFrameBasedClock editorClock { get; set; }

        private readonly LayoutValue zoomedContentWidthCache = new LayoutValue(Invalidation.DrawSize);

        private float minZoom;
        private float maxZoom;

        /// <summary>
        /// Creates a <see cref="ZoomableScrollContainer"/> with no zoom range.
        /// Functionality will be disabled until zoom is set up via <see cref="SetupZoom"/>.
        /// </summary>
        public ZoomableScrollContainer()
            : base(Direction.Horizontal)
        {
            base.Content.Add(zoomedContent = new Container { RelativeSizeAxes = Axes.Y });

            AddLayout(zoomedContentWidthCache);
        }

        /// <summary>
        /// Creates a <see cref="ZoomableScrollContainer"/> with a defined zoom range.
        /// </summary>
        public ZoomableScrollContainer(float minimum, float maximum, float initial)
            : this()
        {
            SetupZoom(initial, minimum, maximum);
        }

        /// <summary>
        /// Sets up the minimum and maximum range of this zoomable scroll container, along with the initial zoom value.
        /// </summary>
        /// <param name="initial">The initial zoom value, applied immediately.</param>
        /// <param name="minimum">The minimum zoom value.</param>
        /// <param name="maximum">The maximum zoom value.</param>
        public void SetupZoom(float initial, float minimum, float maximum)
        {
            if (minimum < 1)
                throw new ArgumentException($"{nameof(minimum)} ({minimum}) must be >= 1.", nameof(maximum));

            if (maximum < 1)
                throw new ArgumentException($"{nameof(maximum)} ({maximum}) must be >= 1.", nameof(maximum));

            if (minimum > maximum)
                throw new ArgumentException($"{nameof(minimum)} ({minimum}) must be less than {nameof(maximum)} ({maximum})");

            minZoom = minimum;
            maxZoom = maximum;
            CurrentZoom = zoomTarget = initial;
            isZoomSetUp = true;
        }

        /// <summary>
        /// Gets or sets the content zoom level of this <see cref="ZoomableScrollContainer"/>.
        /// </summary>
        public float Zoom
        {
            get => zoomTarget;
            set => updateZoom(value);<commit_msg>Mark `SetupZoom` and parameterless `ZoomableScrollContainer` ctor as protected<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.

#nullable disable

using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Transforms;
using osu.Framework.Input.Events;
using osu.Framework.Layout;
using osu.Framework.Timing;
using osu.Framework.Utils;
using osu.Game.Graphics.Containers;
using osuTK;

namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
    public class ZoomableScrollContainer : OsuScrollContainer
    {
        /// <summary>
        /// The time to zoom into/out of a point.
        /// All user scroll input will be overwritten during the zoom transform.
        /// </summary>
        public double ZoomDuration;

        /// <summary>
        /// The easing with which to transform the zoom.
        /// </summary>
        public Easing ZoomEasing;

        private readonly Container zoomedContent;
        protected override Container<Drawable> Content => zoomedContent;

        /// <summary>
        /// The current zoom level of <see cref="ZoomableScrollContainer"/>.
        /// It may differ from <see cref="Zoom"/> during transitions.
        /// </summary>
        public float CurrentZoom { get; private set; } = 1;

        private bool isZoomSetUp;

        [Resolved(canBeNull: true)]
        private IFrameBasedClock editorClock { get; set; }

        private readonly LayoutValue zoomedContentWidthCache = new LayoutValue(Invalidation.DrawSize);

        private float minZoom;
        private float maxZoom;

        /// <summary>
        /// Creates a <see cref="ZoomableScrollContainer"/> with no zoom range.
        /// Functionality will be disabled until zoom is set up via <see cref="SetupZoom"/>.
        /// </summary>
        protected ZoomableScrollContainer()
            : base(Direction.Horizontal)
        {
            base.Content.Add(zoomedContent = new Container { RelativeSizeAxes = Axes.Y });

            AddLayout(zoomedContentWidthCache);
        }

        /// <summary>
        /// Creates a <see cref="ZoomableScrollContainer"/> with a defined zoom range.
        /// </summary>
        public ZoomableScrollContainer(float minimum, float maximum, float initial)
            : this()
        {
            SetupZoom(initial, minimum, maximum);
        }

        /// <summary>
        /// Sets up the minimum and maximum range of this zoomable scroll container, along with the initial zoom value.
        /// </summary>
        /// <param name="initial">The initial zoom value, applied immediately.</param>
        /// <param name="minimum">The minimum zoom value.</param>
        /// <param name="maximum">The maximum zoom value.</param>
        protected void SetupZoom(float initial, float minimum, float maximum)
        {
            if (minimum < 1)
                throw new ArgumentException($"{nameof(minimum)} ({minimum}) must be >= 1.", nameof(maximum));

            if (maximum < 1)
                throw new ArgumentException($"{nameof(maximum)} ({maximum}) must be >= 1.", nameof(maximum));

            if (minimum > maximum)
                throw new ArgumentException($"{nameof(minimum)} ({minimum}) must be less than {nameof(maximum)} ({maximum})");

            minZoom = minimum;
            maxZoom = maximum;
            CurrentZoom = zoomTarget = initial;
            isZoomSetUp = true;
        }

        /// <summary>
        /// Gets or sets the content zoom level of this <see cref="ZoomableScrollContainer"/>.
        /// </summary>
        public float Zoom
        {
            get => zoomTarget;
            set => updateZoom(value);
{'fraction_non_alphanumeric': 0.1096867979384168, 'fraction_numerical': 0.0013215276860050217, 'mean_word_length': 2.259259259259259, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 73, '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': '4266809', 'n_tokens_mistral': 1972, 'n_tokens_neox': 1889, 'n_words': 622}