Esempio n. 1
0
        public void ScrollIntoView(GuiWidget widget, ScrollAmount scrollAmount = ScrollAmount.Minimum)
        {
            if (this.Descendants().Contains(widget))
            {
                var clippedBounds = widget.ClippedOnScreenBounds();
                var screenBounds  = widget.TransformToScreenSpace(widget.LocalBounds);

                if (clippedBounds.Height != screenBounds.Height)
                {
                    if (scrollAmount == ScrollAmount.Center)
                    {
                        var widgetScrollBounds = this.TransformFromScreenSpace(screenBounds.Center);
                        this.ScrollPosition = new Vector2(0, -widgetScrollBounds.Y);
                    }
                    else
                    {
                        // do the minimum scroll that will put the widget on screen
                        var bounds      = this.LocalBounds;
                        var scrollSpace = widget.TransformToParentSpace(this, widget.LocalBounds);
                        // are we above or below
                        if (scrollSpace.Top >= bounds.Top)
                        {
                            // the widget is clipped on the top
                            // lower it
                            this.ScrollPosition = new Vector2(0, this.ScrollPosition.Y + bounds.Top - scrollSpace.Top);
                        }
                        else if (scrollSpace.Bottom <= bounds.Bottom)
                        {
                            // the widget is clipped on the top
                            // lower it
                            this.ScrollPosition = new Vector2(0, this.ScrollPosition.Y + bounds.Bottom - scrollSpace.Bottom);
                        }
                    }
                }
            }
        }