Beispiel #1
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            if (View == null)
            {
                SetMeasuredDimension(0, 0);
                return;
            }
            if (!View.IsVisible)
            {
                View.Measure(0, 0);
                SetMeasuredDimension(0, 0);
                return;
            }

            var width  = MeasureSpecFactory.GetSize(widthMeasureSpec);
            var height = MeasureSpecFactory.GetSize(heightMeasureSpec);

            var measureWidth  = width > 0 ? Context.FromPixels(width) : double.PositiveInfinity;
            var measureHeight = height > 0 ? Context.FromPixels(height) : double.PositiveInfinity;

            _shellViewRenderer.LayoutView(measureWidth, measureHeight);

            SetMeasuredDimension((MatchWidth && width != 0) ? width : (int)Context.ToPixels(View.Width),
                                 (MatchHeight && height != 0) ? height : (int)Context.ToPixels(View.Height));
        }
Beispiel #2
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
            var measureWidth  = MeasureSpecFactory.GetSize(widthMeasureSpec);
            var measureHeight = MeasureSpecFactory.GetSize(heightMeasureSpec);

            SetMeasuredDimension(measureWidth, (int)Context.ToPixels(35));
        }
        public override SizeRequest GetDesiredSize(int widthConstraint, int heightConstraint)
        {
            if (_lastSizeRequest.HasValue)
            {
                // if we are measuring the same thing, no need to waste the time
                bool canRecycleLast = widthConstraint == _lastConstraintWidth && heightConstraint == _lastConstraintHeight;

                if (!canRecycleLast)
                {
                    // if the last time we measured the returned size was all around smaller than the passed constraint
                    // and the constraint is bigger than the last size request, we can assume the newly measured size request
                    // will not change either.
                    int lastConstraintWidthSize  = MeasureSpecFactory.GetSize(_lastConstraintWidth);
                    int lastConstraintHeightSize = MeasureSpecFactory.GetSize(_lastConstraintHeight);

                    int currentConstraintWidthSize  = MeasureSpecFactory.GetSize(widthConstraint);
                    int currentConstraintHeightSize = MeasureSpecFactory.GetSize(heightConstraint);

                    bool lastWasSmallerThanConstraints = _lastSizeRequest.Value.Request.Width < lastConstraintWidthSize && _lastSizeRequest.Value.Request.Height < lastConstraintHeightSize;

                    bool currentConstraintsBiggerThanLastRequest = currentConstraintWidthSize >= _lastSizeRequest.Value.Request.Width && currentConstraintHeightSize >= _lastSizeRequest.Value.Request.Height;

                    canRecycleLast = lastWasSmallerThanConstraints && currentConstraintsBiggerThanLastRequest;
                }

                if (canRecycleLast)
                {
                    return(_lastSizeRequest.Value);
                }
            }

            //We need to clear the Hint or else it will interfere with the sizing of the Label
            var hint = Control.Hint;

            if (!string.IsNullOrEmpty(hint))
            {
                Control.Hint = string.Empty;
            }

            SizeRequest result = base.GetDesiredSize(widthConstraint, heightConstraint);

            //Set Hint back after sizing
            Control.Hint = hint;

            result.Minimum = new Size(Math.Min(Context.ToPixels(10), result.Request.Width), result.Request.Height);

            _lastConstraintWidth  = widthConstraint;
            _lastConstraintHeight = heightConstraint;
            _lastSizeRequest      = result;

            return(result);
        }
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            SetMeasuredDimension(MeasureSpec.GetSize(widthMeasureSpec), MeasureSpec.GetSize(heightMeasureSpec));

            var width  = MeasureSpecFactory.GetSize(widthMeasureSpec);
            var height = MeasureSpecFactory.GetSize(heightMeasureSpec);

            for (int i = 0; i < ChildCount; i++)
            {
                var child = GetChildAt(i);
                child.Measure(MeasureSpecFactory.MakeMeasureSpec(width, MeasureSpecMode.Exactly),
                              MeasureSpecFactory.MakeMeasureSpec(height, MeasureSpecMode.Exactly));
            }
        }
        public void LayoutView(double width, double height)
        {
            _width  = width;
            _height = height;
            Context context;

            if (_renderer == null || !(_context.TryGetTarget(out context)) || !_renderer.View.IsAlive())
            {
                return;
            }

            if (View == null)
            {
                var empty = MeasureSpecFactory.GetSize(0);
                _renderer.View.Measure(empty, empty);
                return;
            }

            var request = View.Measure(width, height, MeasureFlags.None);

            var layoutParams = NativeView.LayoutParameters;

            if (height == -1)
            {
                height = request.Request.Height;
            }

            if (width == -1)
            {
                width = request.Request.Width;
            }

            if (layoutParams.Width != LP.MatchParent)
            {
                layoutParams.Width = (int)context.ToPixels(width);
            }

            if (layoutParams.Height != LP.MatchParent)
            {
                layoutParams.Height = (int)context.ToPixels(height);
            }

            NativeView.LayoutParameters = layoutParams;
            View.Layout(new Rectangle(0, 0, width, height));
            _renderer.UpdateLayout();
        }
Beispiel #6
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            if (View == null)
            {
                SetMeasuredDimension(0, 0);
                return;
            }

            // chain on down
            _renderer.View.Measure(widthMeasureSpec, heightMeasureSpec);

            var width  = MeasureSpecFactory.GetSize(widthMeasureSpec);
            var height = MeasureSpecFactory.GetSize(heightMeasureSpec);

            var measureWidth  = width > 0 ? _context.FromPixels(width) : double.PositiveInfinity;
            var measureHeight = height > 0 ? _context.FromPixels(height) : double.PositiveInfinity;

            var sizeReq = View.Measure(measureWidth, measureHeight);

            SetMeasuredDimension((MatchWidth && width != 0) ? width : (int)_context.ToPixels(sizeReq.Request.Width),
                                 (MatchHeight && height != 0) ? height : (int)_context.ToPixels(sizeReq.Request.Height));
        }
Beispiel #7
0
            protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
            {
                if (_child?.Element == null)
                {
                    SetMeasuredDimension(0, 0);
                    return;
                }

                VisualElement element = _child.Element;

                Context ctx = Context;

                var width = (int)ctx.FromPixels(MeasureSpecFactory.GetSize(widthMeasureSpec));

                SizeRequest request = element.Measure(width, double.PositiveInfinity, MeasureFlags.IncludeMargins);

                Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion(element, new Rectangle(0, 0, width, request.Request.Height));

                int widthSpec  = MeasureSpecFactory.MakeMeasureSpec((int)ctx.ToPixels(width), MeasureSpecMode.Exactly);
                int heightSpec = MeasureSpecFactory.MakeMeasureSpec((int)ctx.ToPixels(request.Request.Height), MeasureSpecMode.Exactly);

                _child.View.Measure(widthMeasureSpec, heightMeasureSpec);
                SetMeasuredDimension(widthSpec, heightSpec);
            }
Beispiel #8
0
        public void LayoutView(double x, double y, double width, double height, double?maxWidth = null, double?maxHeight = null)
        {
            if (width == -1)
            {
                width = double.PositiveInfinity;
            }

            if (height == -1)
            {
                height = double.PositiveInfinity;
            }

            Width     = width;
            Height    = height;
            MaxWidth  = maxWidth;
            MaxHeight = maxHeight;
            X         = x;
            Y         = y;

            Context context;

            if (Renderer == null || !(_context.TryGetTarget(out context)) || !Renderer.View.IsAlive())
            {
                return;
            }

            if (View == null)
            {
                var empty = MeasureSpecFactory.GetSize(0);
                Renderer.View.Measure(empty, empty);
                return;
            }

            var request = View.Measure(width, height, MeasureFlags.None);

            var layoutParams = NativeView.LayoutParameters;

            if (double.IsInfinity(height))
            {
                height = request.Request.Height;
            }

            if (double.IsInfinity(width))
            {
                width = request.Request.Width;
            }

            if (height > maxHeight)
            {
                height = maxHeight.Value;
            }

            if (width > maxWidth)
            {
                width = maxWidth.Value;
            }

            if (layoutParams.Width != LP.MatchParent)
            {
                layoutParams.Width = (int)context.ToPixels(width);
            }

            if (layoutParams.Height != LP.MatchParent)
            {
                layoutParams.Height = (int)context.ToPixels(height);
            }

            NativeView.LayoutParameters = layoutParams;
            View.Layout(new Rectangle(x, y, width, height));
            Renderer.UpdateLayout();
        }