コード例 #1
0
ファイル: ScrollViewer.cs プロジェクト: xvwvx/Myra
        protected override Point InternalMeasure(Point availableSize)
        {
            if (InternalChild == null)
            {
                return(Point.Zero);
            }

            var measureSize = InternalChild.Measure(availableSize);

            var horizontalScrollbarVisible = ShowHorizontalScrollBar && measureSize.X > availableSize.X;
            var verticalScrollbarVisible   = ShowVerticalScrollBar && measureSize.Y > availableSize.Y;

            if (horizontalScrollbarVisible || verticalScrollbarVisible)
            {
                if (horizontalScrollbarVisible)
                {
                    measureSize.Y += HorizontalScrollbarHeight;
                }

                if (verticalScrollbarVisible)
                {
                    measureSize.X += VerticalScrollbarWidth;
                }
            }

            return(measureSize);
        }
コード例 #2
0
        protected override Point InternalMeasure(Point availableSize)
        {
            var result = Point.Zero;

            if (InternalChild != null)
            {
                result = InternalChild.Measure(availableSize);
            }

            return(result);
        }
コード例 #3
0
        public override void Arrange()
        {
            base.Arrange();

            var bounds        = ActualBounds;
            var availableSize = bounds.Size;
            var measureSize   = InternalChild.Measure(availableSize);

            bounds.Width  = measureSize.X;
            bounds.Height = measureSize.Y;
            InternalChild.Layout(bounds);
        }
コード例 #4
0
        protected override Point InternalMeasure(Point availableSize)
        {
            if (InternalChild == null)
            {
                return(Point.Zero);
            }

            if (Width != null)
            {
                availableSize.X = Width.Value;
            }

            if (Height != null)
            {
                availableSize.Y = Height.Value;
            }

            var measureSize = InternalChild.Measure(availableSize);

            var horizontalScrollbarVisible = ShowHorizontalScrollBar && measureSize.X > availableSize.X;
            var verticalScrollbarVisible   = ShowVerticalScrollBar && measureSize.Y > availableSize.Y;

            if (horizontalScrollbarVisible || verticalScrollbarVisible)
            {
                if (horizontalScrollbarVisible)
                {
                    measureSize.Y += VerticalScrollBackground.Size.X;
                }

                if (verticalScrollbarVisible)
                {
                    measureSize.X += VerticalScrollBackground.Size.Y;
                }
            }

            return(measureSize);
        }
コード例 #5
0
ファイル: ScrollViewer.cs プロジェクト: xvwvx/Myra
        public override void Arrange()
        {
            if (InternalChild == null)
            {
                return;
            }

            var bounds         = ActualBounds;
            var availableSize  = bounds.Size();
            var oldMeasureSize = InternalChild.Measure(availableSize);

            _horizontalScrollingOn = oldMeasureSize.X > bounds.Width;
            _verticalScrollingOn   = oldMeasureSize.Y > bounds.Height;
            if (_horizontalScrollingOn || _verticalScrollingOn)
            {
                var vsWidth  = VerticalScrollbarWidth;
                var hsHeight = HorizontalScrollbarHeight;

                if (_horizontalScrollingOn && ShowHorizontalScrollBar)
                {
                    availableSize.Y -= hsHeight;

                    if (availableSize.Y < 0)
                    {
                        availableSize.Y = 0;
                    }
                }

                if (_verticalScrollingOn && ShowVerticalScrollBar)
                {
                    availableSize.X -= vsWidth;

                    if (availableSize.X < 0)
                    {
                        availableSize.X = 0;
                    }
                }

                // Remeasure with scrollbars
                var measureSize = InternalChild.Measure(availableSize);

                var bw = bounds.Width - (_verticalScrollingOn && ShowVerticalScrollBar ? vsWidth : 0);

                _horizontalScrollbarFrame = new Rectangle(bounds.Left,
                                                          bounds.Bottom - hsHeight,
                                                          bw,
                                                          hsHeight);

                var mw = measureSize.X;
                if (mw == 0)
                {
                    mw = 1;
                }

                _horizontalScrollbarThumb = new Rectangle(bounds.Left,
                                                          bounds.Bottom - hsHeight,
                                                          Math.Max(HorizontalScrollKnob.Size.X, bw * bw / mw),
                                                          HorizontalScrollKnob.Size.Y);

                var bh = bounds.Height - (_horizontalScrollingOn ? hsHeight : 0);

                _verticalScrollbarFrame = new Rectangle(
                    bounds.Left + bounds.Width - vsWidth,
                    bounds.Top,
                    vsWidth,
                    bh);

                var mh = measureSize.Y;
                if (mh == 0)
                {
                    mh = 1;
                }

                _verticalScrollbarThumb = new Rectangle(
                    bounds.Left + bounds.Width - vsWidth,
                    bounds.Top,
                    VerticalScrollKnob.Size.X,
                    Math.Max(VerticalScrollKnob.Size.Y, bh * bh / mh));

                _thumbMaximumX = bw - _horizontalScrollbarThumb.Width;
                _thumbMaximumY = bh - _verticalScrollbarThumb.Height;

                if (_thumbMaximumX == 0)
                {
                    _thumbMaximumX = 1;
                }

                if (_thumbMaximumY == 0)
                {
                    _thumbMaximumY = 1;
                }

                if (_horizontalScrollingOn && ShowHorizontalScrollBar)
                {
                    bounds.Width = measureSize.X;
                }
                else if (_horizontalScrollingOn)
                {
                    bounds.Width = oldMeasureSize.X;
                }
                else
                {
                    bounds.Width = availableSize.X;
                }

                if (_verticalScrollingOn && ShowVerticalScrollBar)
                {
                    bounds.Height = measureSize.Y;
                }
                else if (_verticalScrollingOn)
                {
                    bounds.Height = oldMeasureSize.Y;
                }
                else
                {
                    bounds.Height = availableSize.Y;
                }
            }

            InternalChild.Layout(bounds);

            // Fit scroll position in new maximums
            var scrollPosition = ScrollPosition;

            ScrollPosition = scrollPosition;
        }
コード例 #6
0
        public override void Arrange()
        {
            if (InternalChild == null)
            {
                return;
            }

            var bounds        = ActualBounds;
            var availableSize = bounds.Size();
            var measureSize   = InternalChild.Measure(availableSize);

            _horizontalScrollbarVisible = AllowHorizontalScrolling && measureSize.X > bounds.Width;
            _verticalScrollbarVisible   = AllowVerticalScrolling && measureSize.Y > bounds.Height;
            if (_horizontalScrollbarVisible || _verticalScrollbarVisible)
            {
                if (_horizontalScrollbarVisible)
                {
                    availableSize.Y -= HorizontalScrollKnob.Size.Y;

                    if (availableSize.Y < 0)
                    {
                        availableSize.Y = 0;
                    }
                }

                if (_verticalScrollbarVisible)
                {
                    availableSize.X -= VerticalScrollKnob.Size.X;

                    if (availableSize.X < 0)
                    {
                        availableSize.X = 0;
                    }
                }

                // Remeasure with scrollbars
                measureSize = InternalChild.Measure(availableSize);

                var vsWidth  = VerticalScrollBackground != null ? VerticalScrollBackground.Size.X : VerticalScrollKnob.Size.X;
                var hsHeight = HorizontalScrollBackground != null ? HorizontalScrollBackground.Size.Y : HorizontalScrollKnob.Size.Y;

                var bw = bounds.Width - (_verticalScrollbarVisible ? vsWidth : 0);

                _horizontalScrollbarFrame = new Rectangle(bounds.Left,
                                                          bounds.Bottom - hsHeight,
                                                          bw,
                                                          hsHeight);

                var mw = measureSize.X;
                if (mw == 0)
                {
                    mw = 1;
                }

                _horizontalScrollbarThumb = new Rectangle(bounds.Left,
                                                          bounds.Bottom - hsHeight,
                                                          Math.Max(HorizontalScrollKnob.Size.X, bw * bw / mw),
                                                          HorizontalScrollKnob.Size.Y);

                var bh = bounds.Height - (_horizontalScrollbarVisible ? hsHeight : 0);

                _verticalScrollbarFrame = new Rectangle(
                    bounds.Left + bounds.Width - vsWidth,
                    bounds.Top,
                    vsWidth,
                    bh);

                var mh = measureSize.Y;
                if (mh == 0)
                {
                    mh = 1;
                }

                _verticalScrollbarThumb = new Rectangle(
                    bounds.Left + bounds.Width - vsWidth,
                    bounds.Top,
                    VerticalScrollKnob.Size.X,
                    Math.Max(VerticalScrollKnob.Size.Y, bh * bh / mh));

                _horizontalMaximum = bw - _horizontalScrollbarThumb.Width;
                _verticalMaximum   = bh - _verticalScrollbarThumb.Height;

                if (_horizontalMaximum == 0)
                {
                    _horizontalMaximum = 1;
                }

                if (_verticalMaximum == 0)
                {
                    _verticalMaximum = 1;
                }

                bounds.Width  = _horizontalScrollbarVisible ? measureSize.X : availableSize.X;
                bounds.Height = _verticalScrollbarVisible ? measureSize.Y : availableSize.Y;

                if (_scrollPosition.X < 0)
                {
                    _scrollPosition.X = 0;
                }

                if (_scrollPosition.X > _horizontalMaximum)
                {
                    _scrollPosition.X = _horizontalMaximum;
                }

                if (_scrollPosition.Y < 0)
                {
                    _scrollPosition.Y = 0;
                }

                if (_scrollPosition.Y > _verticalMaximum)
                {
                    _scrollPosition.Y = _verticalMaximum;
                }
            }

            InternalChild.Layout(bounds);

            UpdateWidgetLocation();
        }