コード例 #1
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            RectF pathBounds = new RectF();
            var   path       = this.GetPath();

            if (path != null)
            {
                path.ComputeBounds(pathBounds, false);
            }

            _pathWidth  = pathBounds.Width();
            _pathHeight = pathBounds.Height();

            if (ShouldPreserveOrigin)
            {
                _pathWidth  += pathBounds.Left;
                _pathHeight += pathBounds.Top;
            }

            var aspectRatio = _pathWidth / _pathHeight;

            var widthMode  = ViewHelper.MeasureSpecGetMode(widthMeasureSpec);
            var heightMode = ViewHelper.MeasureSpecGetMode(heightMeasureSpec);

            var availableWidth  = ViewHelper.MeasureSpecGetSize(widthMeasureSpec);
            var availableHeight = ViewHelper.MeasureSpecGetSize(heightMeasureSpec);

            var userWidth  = ViewHelper.LogicalToPhysicalPixels(this.Width);
            var userHeight = ViewHelper.LogicalToPhysicalPixels(this.Height);

            switch (widthMode)
            {
            case Android.Views.MeasureSpecMode.AtMost:
            case Android.Views.MeasureSpecMode.Exactly:
                _controlWidth = availableWidth;
                break;

            default:
            case Android.Views.MeasureSpecMode.Unspecified:
                switch (Stretch)
                {
                case Stretch.Uniform:
                    if (heightMode != Android.Views.MeasureSpecMode.Unspecified)
                    {
                        _controlWidth = availableHeight * aspectRatio;
                    }
                    else
                    {
                        _controlWidth = _pathWidth;
                    }
                    break;

                default:
                    _controlWidth = _pathWidth;
                    break;
                }
                break;
            }

            switch (heightMode)
            {
            case Android.Views.MeasureSpecMode.AtMost:
            case Android.Views.MeasureSpecMode.Exactly:
                _controlHeight = availableHeight;
                break;

            default:
            case Android.Views.MeasureSpecMode.Unspecified:
                switch (Stretch)
                {
                case Stretch.Uniform:
                    if (widthMode != Android.Views.MeasureSpecMode.Unspecified)
                    {
                        _controlHeight = availableWidth / aspectRatio;
                    }
                    else
                    {
                        _controlHeight = _pathHeight;
                    }
                    break;

                default:
                    _controlHeight = _pathHeight;
                    break;
                }
                break;
            }

            // Default values
            _calculatedWidth  = LimitWithUserSize(_controlWidth, userWidth, _pathWidth);
            _calculatedHeight = LimitWithUserSize(_controlHeight, userHeight, _pathHeight);
            _scaleX           = (_calculatedWidth - this.PhysicalStrokeThickness) / _pathWidth;
            _scaleY           = (_calculatedHeight - this.PhysicalStrokeThickness) / _pathHeight;

            // Here we will override some of the default values
            switch (this.Stretch)
            {
            // If the Stretch is None, the drawing is not the same size as the control
            case Media.Stretch.None:
                _scaleX           = 1;
                _scaleY           = 1;
                _calculatedWidth  = (double)_pathWidth;
                _calculatedHeight = (double)_pathHeight;
                break;

            case Media.Stretch.Fill:
                break;

            // Override the _calculated dimensions if the stretch is Uniform or UniformToFill
            case Media.Stretch.Uniform:
                var scale = Math.Min(_scaleX, _scaleY);
                _calculatedWidth  = _pathWidth * scale;
                _calculatedHeight = _pathHeight * scale;
                break;

            case Media.Stretch.UniformToFill:
                scale             = Math.Max(_scaleX, _scaleY);
                _calculatedWidth  = _pathWidth * scale;
                _calculatedHeight = _pathHeight * scale;
                break;
            }

            _calculatedWidth  += this.PhysicalStrokeThickness;
            _calculatedHeight += this.PhysicalStrokeThickness;

            SetMeasuredDimension((int)Math.Ceiling(_calculatedWidth), (int)Math.Ceiling(_calculatedHeight));
            IFrameworkElementHelper.OnMeasureOverride(this);
        }
コード例 #2
0
 public override CGSize SizeThatFits(CGSize size)
 {
     return(IFrameworkElementHelper.SizeThatFits(this, base.SizeThatFits(size)));
 }
コード例 #3
0
        partial void Initialize()
        {
            _children = new UIElementCollection(this);

            IFrameworkElementHelper.Initialize(this);
        }
コード例 #4
0
 partial void InitializePartial()
 {
     IFrameworkElementHelper.Initialize(this);
 }
コード例 #5
0
 private void Initialize()
 {
     BackgroundColor = UIColor.Clear;
     IFrameworkElementHelper.Initialize(this);
 }
コード例 #6
0
ファイル: TextBox.iOS.cs プロジェクト: nepronen/Uno
 public override CGSize SizeThatFits(CGSize size)
 {
     size = base.SizeThatFits(size);
     size = IFrameworkElementHelper.SizeThatFits(this, size);
     return(size);
 }
コード例 #7
0
 public HorizontalGridView()
 {
     InitializeBinder();
     IFrameworkElementHelper.Initialize(this);
 }
コード例 #8
0
 public HorizontalListView() : base(ContextHelper.Current, null)
 {
     InitializeBinder();
     SetClipToPadding(false);
     IFrameworkElementHelper.Initialize(this);
 }
コード例 #9
0
 public ContentControl()
 {
     IFrameworkElementHelper.Initialize(this);
 }
コード例 #10
0
        public ContentPresenter()
        {
            InitializeContentPresenter();

            IFrameworkElementHelper.Initialize(this);
        }