FairyGUI.ScrollPane.HandleSizeChanged C# (CSharp) Method

HandleSizeChanged() static private method

static private HandleSizeChanged ( bool onScrolling = false ) : void
onScrolling bool
return void
        void HandleSizeChanged(bool onScrolling = false)
        {
            if (_displayInDemand)
            {
                if (_vtScrollBar != null)
                {
                    if (_contentHeight <= _viewHeight)
                    {
                        if (!_vScrollNone)
                        {
                            _vScrollNone = true;
                            _viewWidth += _vtScrollBar.width;
                        }
                    }
                    else
                    {
                        if (_vScrollNone)
                        {
                            _vScrollNone = false;
                            _viewWidth -= _vtScrollBar.width;
                        }
                    }
                }
                if (_hzScrollBar != null)
                {
                    if (_contentWidth <= _viewWidth)
                    {
                        if (!_hScrollNone)
                        {
                            _hScrollNone = true;
                            _viewHeight += _hzScrollBar.height;
                        }
                    }
                    else
                    {
                        if (_hScrollNone)
                        {
                            _hScrollNone = false;
                            _viewHeight -= _hzScrollBar.height;
                        }
                    }
                }
            }

            if (_vtScrollBar != null)
            {
                if (_viewHeight < _vtScrollBar.minSize)
                    _vtScrollBar.displayObject.visible = false;
                else
                {
                    _vtScrollBar.displayObject.visible = _scrollBarVisible && !_vScrollNone;
                    if (_contentHeight == 0)
                        _vtScrollBar.displayPerc = 0;
                    else
                        _vtScrollBar.displayPerc = Math.Min(1, _viewHeight / _contentHeight);
                }
            }
            if (_hzScrollBar != null)
            {
                if (_viewWidth < _hzScrollBar.minSize)
                    _hzScrollBar.displayObject.visible = false;
                else
                {
                    _hzScrollBar.displayObject.visible = _scrollBarVisible && !_hScrollNone;
                    if (_contentWidth == 0)
                        _hzScrollBar.displayPerc = 0;
                    else
                        _hzScrollBar.displayPerc = Math.Min(1, _viewWidth / _contentWidth);
                }
            }

            if (!_maskDisabled)
                _maskContainer.clipRect = new Rect(-owner._alignOffset.x, -owner._alignOffset.y, _viewWidth, _viewHeight);

            if (_scrollType == ScrollType.Horizontal || _scrollType == ScrollType.Both)
                _xOverlap = Mathf.CeilToInt(Math.Max(0, _contentWidth - _viewWidth));
            else
                _xOverlap = 0;
            if (_scrollType == ScrollType.Vertical || _scrollType == ScrollType.Both)
                _yOverlap = Mathf.CeilToInt(Math.Max(0, _contentHeight - _viewHeight));
            else
                _yOverlap = 0;

            if (_tweening == 0 && onScrolling)
            {
                //如果原来是在边缘,且不在缓动状态,那么尝试继续贴边。(如果在缓动状态,需要修改tween的终值,暂时未支持)
                if (_xPerc == 0 || _xPerc == 1)
                {
                    _xPos = _xPerc * _xOverlap;
                    _container.x = -_xPos;
                }
                if (_yPerc == 0 || _yPerc == 1)
                {
                    _yPos = _yPerc * _yOverlap;
                    _container.y = -_yPos;
                }
            }
            else
            {
                //边界检查
                _xPos = Mathf.Clamp(_xPos, 0, _xOverlap);
                _xPerc = _xOverlap > 0 ? _xPos / _xOverlap : 0;

                _yPos = Mathf.Clamp(_yPos, 0, _yOverlap);
                _yPerc = _yOverlap > 0 ? _yPos / _yOverlap : 0;
            }

            ValidateHolderPos();

            if (_vtScrollBar != null)
                _vtScrollBar.scrollPerc = _yPerc;
            if (_hzScrollBar != null)
                _hzScrollBar.scrollPerc = _xPerc;

            UpdateClipSoft();
        }