<commit_before>using Microsoft.Xna.Framework;

namespace MonoVarmint.Widgets
{
    //--------------------------------------------------------------------------------------
    /// <summary>
    /// VarmintWidgetScrollView 
    /// 
    /// You place the objects where you want using their offsets.  The view will 
    /// automatically set the bounds based on the objects you add and their margins
    /// 
    /// </summary>
    //--------------------------------------------------------------------------------------
    [VarmintWidgetShortName("ScrollView")]
    public class VarmintWidgetScrollView : VarmintWidget
    {
        /// <summary>
        /// Upper left corner of the scroll view in virtual space
        /// </summary>
        public Vector2 ScrollOffset { get { return _innerContent.Offset; } set { _innerContent.Offset = value; } }

        /// <summary>
        /// AbsoluteOffset
        /// </summary>
        public override Vector2 AbsoluteOffset
        {
            get
            {
                if (Parent == null) return Offset;
                else return Parent.AbsoluteOffset + Offset;
            }
        }

        PlainFormatter _innerContent;

        //--------------------------------------------------------------------------------------
        /// <summary>
        /// ctor
        /// </summary>
        //--------------------------------------------------------------------------------------
        public VarmintWidgetScrollView()
        {
            ClipToBounds = true;
            this.SetCustomRender((gt, w) => {
                ScrollBy(_momentum);
                _momentum *= .9f;
                Renderer.DrawBox(AbsoluteOffset, Size, RenderBackgroundColor);
            });
            this.OnDrag += VarmintWidgetScrollView_OnDrag;
            this.OnFlick += VarmintWidgetScrollView_OnFlick;

            _innerContent = new PlainFormatter();
            _innerContent.Renderer = new NullRenderer();
            base.AddChild(_innerContent);
        }

        Vector2 _momentum;
        //--------------------------------------------------------------------------------------
        //
        //--------------------------------------------------------------------------------------
        private EventHandledState VarmintWidgetScrollView_OnFlick(VarmintWidget widget, Vector2 location, Vector2 delta)
        {
            _momentum = delta * .2f;
            return EventHandledState.Handled;
        }

        //--------------------------------------------------------------------------------------
        //
        //--------------------------------------------------------------------------------------
        protected override void UpdateChildFormatting_Internal(Vector2? updatedSize)
        {
            // child formatting is static - the scrollview does not update it
            _innerContent.RecalculateExtremes();
        }

        //--------------------------------------------------------------------------------------
        //
        //--------------------------------------------------------------------------------------
        public override void AddChild(VarmintWidget widget, bool suppressChildUpdate = false)
        {
            _innerContent.AddChild(widget, suppressChildUpdate);
        }

        //--------------------------------------------------------------------------------------<commit_msg>Setting inner frame on scroll view<commit_after>using Microsoft.Xna.Framework;

namespace MonoVarmint.Widgets
{
    //--------------------------------------------------------------------------------------
    /// <summary>
    /// VarmintWidgetScrollView 
    /// 
    /// You place the objects where you want using their offsets.  The view will 
    /// automatically set the bounds based on the objects you add and their margins
    /// 
    /// </summary>
    //--------------------------------------------------------------------------------------
    [VarmintWidgetShortName("ScrollView")]
    public class VarmintWidgetScrollView : VarmintWidget
    {
        /// <summary>
        /// Upper left corner of the scroll view in virtual space
        /// </summary>
        public Vector2 ScrollOffset { get { return _innerContent.Offset; } set { _innerContent.Offset = value; } }

        /// <summary>
        /// AbsoluteOffset
        /// </summary>
        public override Vector2 AbsoluteOffset
        {
            get
            {
                if (Parent == null) return Offset;
                else return Parent.AbsoluteOffset + Offset;
            }
        }

        PlainFormatter _innerContent;
        
        //--------------------------------------------------------------------------------------
        /// <summary>
        /// ctor
        /// </summary>
        //--------------------------------------------------------------------------------------
        public VarmintWidgetScrollView()
        {
            ClipToBounds = true;
            this.SetCustomRender((gt, w) => {
                ScrollBy(_momentum);
                _momentum *= .9f;
                Renderer.DrawBox(AbsoluteOffset, Size, RenderBackgroundColor);
            });
            this.OnDrag += VarmintWidgetScrollView_OnDrag;
            this.OnFlick += VarmintWidgetScrollView_OnFlick;

            _innerContent = new PlainFormatter();
            _innerContent.Renderer = new NullRenderer();
            _innerContent.Name = "InnerFrame_" + this.Name;
            base.AddChild(_innerContent);
        }

        Vector2 _momentum;
        //--------------------------------------------------------------------------------------
        //
        //--------------------------------------------------------------------------------------
        private EventHandledState VarmintWidgetScrollView_OnFlick(VarmintWidget widget, Vector2 location, Vector2 delta)
        {
            _momentum = delta * .2f;
            return EventHandledState.Handled;
        }

        //--------------------------------------------------------------------------------------
        //
        //--------------------------------------------------------------------------------------
        protected override void UpdateChildFormatting_Internal(Vector2? updatedSize)
        {
            // child formatting is static - the scrollview does not update it
            _innerContent.RecalculateExtremes();
        }

        //--------------------------------------------------------------------------------------
        //
        //--------------------------------------------------------------------------------------
        public override void AddChild(VarmintWidget widget, bool suppressChildUpdate = false)
        {
            _innerContent.AddChild(widget, suppressChildUpdate);
        }

        //--------------------------------------------------------------------------------------
{'fraction_non_alphanumeric': 0.3399971027089671, 'fraction_numerical': 0.0023178328263074024, 'mean_word_length': 0.7965131407754359, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, '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': '240305', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1262, 'n_words': 298}