Ejemplo n.º 1
0
        private void MesureChildAbsolute(UIElement child, Orientation orientation, Size availableSize, GridLength sizeHint, ref Size totalSize)
        {
            if (orientation == Orientation.Vertical)
            {
                availableSize.Height = Math.Max(sizeHint.Value, 0);
            }
            else
            {
                availableSize.Width = Math.Max(sizeHint.Value, 0);
            }

#if __ANDROID__ || __IOS__
            var desiredSize = MeasureElement(child, availableSize);
#else
            child.Measure(availableSize);
            var desiredSize = child.DesiredSize;
#endif

            if (orientation == Orientation.Vertical)
            {
                desiredSize.Height = availableSize.Height;
            }
            else
            {
                desiredSize.Width = availableSize.Width;
            }

            AddToTotalSize(orientation, desiredSize, ref totalSize);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Measures an native element, in the same way <see cref="Measure"/> would do.
        /// </summary>
        /// <param name="view">The view to be measured.</param>
        /// <param name="availableSize">
        /// The available space that a parent can allocate to a child object. A child object can request a larger
        /// space than what is available; the provided size might be accommodated if scrolling or other resize behavior is
        /// possible in that particular container.
        /// </param>
        /// <returns>The measured size - INCLUDES THE MARGIN</returns>
        protected Size MeasureElement(View view, Size availableSize)
        {
#if __WASM__
            view.Measure(availableSize);
            return(view.DesiredSize);
#else
            return(_layouter.MeasureElement(view, availableSize));
#endif
        }
Ejemplo n.º 3
0
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            base.OnLayout(changed, l, t, r, b);

            if (NativeView != null)
            {
                var msw = MeasureSpec.MakeMeasureSpec(r - l, Android.Views.MeasureSpecMode.Exactly);
                var msh = MeasureSpec.MakeMeasureSpec(b - t, Android.Views.MeasureSpecMode.Exactly);

                NativeView.Measure(msw, msh);
                NativeView.Layout(0, 0, r - l, b - t);
            }
        }
Ejemplo n.º 4
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            int contentViewHeight = 0;
            int childCount        = ChildCount;
            int menuWidthSpec     = MeasureSpec.MakeMeasureSpec(MeasureSpec.GetSize(widthMeasureSpec), MeasureSpec.GetMode(widthMeasureSpec));
            int menuHeightSpec    = MeasureSpec.MakeMeasureSpec(MeasureSpec.GetSize(heightMeasureSpec), MeasureSpec.GetMode(heightMeasureSpec));

            for (int i = 0; i < childCount; i++)
            {
                View view = GetChildAt(i);
                view.Measure(menuWidthSpec, menuHeightSpec);
                contentViewHeight += view.MeasuredHeight;
            }
            SetMeasuredDimension(MeasureSpec.GetSize(widthMeasureSpec), contentViewHeight);
        }
Ejemplo n.º 5
0
        public static Bitmap AsBitmap(this Android.Views.View view, Context context, int width, int height)
        {
            DisplayMetrics displayMetrics = new DisplayMetrics();

            view.Measure(displayMetrics.WidthPixels, displayMetrics.HeightPixels);
            view.Layout(0, 0, displayMetrics.WidthPixels, displayMetrics.HeightPixels);

            view.BuildDrawingCache();
            Bitmap bitmap = Bitmap.CreateBitmap(displayMetrics, width, height, Bitmap.Config.Argb8888);

            Canvas canvas = new Canvas(bitmap);

            view.Draw(canvas);

            return(bitmap);
        }
Ejemplo n.º 6
0
        private void MesureChildAuto(UIElement child, Orientation orientation, Size availableSize, ref Size totalSize)
        {
            if (orientation == Orientation.Vertical)
            {
                availableSize.Height = Math.Max(availableSize.Height - totalSize.Height, 0);
            }
            else
            {
                availableSize.Width = Math.Max(availableSize.Width - totalSize.Width, 0);
            }

#if __ANDROID__ || __IOS__
            var desiredSize = MeasureElement(child, availableSize);
#else
            child.Measure(availableSize);
            var desiredSize = child.DesiredSize;
#endif

            AddToTotalSize(orientation, desiredSize, ref totalSize);
        }
Ejemplo n.º 7
0
        private void MesureChildStar(UIElement child, Orientation orientation, Size availableSize, GridLength sizeHint, double starTotal, ref Size totalSize)
        {
            var portion = sizeHint.Value / starTotal;

            if (orientation == Orientation.Vertical)
            {
                availableSize.Height *= portion;
            }
            else
            {
                availableSize.Width *= portion;
            }

#if __ANDROID__ || __IOS__
            var desiredSize = MeasureElement(child, availableSize);
#else
            child.Measure(availableSize);
            var desiredSize = child.DesiredSize;
#endif

            AddToTotalSize(orientation, desiredSize, ref totalSize);
        }