public override void NativeArrange(Rectangle frame) { // This is a hack to force the shimmed control to actually do layout; without this, some controls won't actually // call OnLayout after SetFrame if their sizes haven't changed (e.g., ScrollView) // Luckily, measuring with MeasureSpecMode.Exactly is pretty fast, since it just returns the value you give it. NativeView?.Measure(MeasureSpecMode.Exactly.MakeMeasureSpec((int)frame.Width), MeasureSpecMode.Exactly.MakeMeasureSpec((int)frame.Height)); base.NativeArrange(frame); }
public override Size GetDesiredSize(double widthConstraint, double heightConstraint) { if (NativeView == null || VirtualView == null || Context == null) { return(Size.Zero); } // Create a spec to handle the native measure var widthSpec = CreateMeasureSpec(widthConstraint, VirtualView.Width); var heightSpec = CreateMeasureSpec(heightConstraint, VirtualView.Height); NativeView.Measure(widthSpec, heightSpec); // Convert back to xplat sizes for the return value return(Context.FromPixels(NativeView.MeasuredWidth, NativeView.MeasuredHeight)); }
public override Size GetDesiredSize(double widthConstraint, double heightConstraint) { if (NativeView == null || VirtualView == null) { return(Size.Zero); } if (widthConstraint < 0 || heightConstraint < 0) { return(Size.Zero); } var measureConstraint = new Windows.Foundation.Size(widthConstraint, heightConstraint); NativeView.Measure(measureConstraint); return(new Size(NativeView.DesiredSize.Width, NativeView.DesiredSize.Height)); }
public override Size GetDesiredSize(double widthConstraint, double heightConstraint) { if (NativeView == null || VirtualView == null) { return(Size.Zero); } if (widthConstraint < 0 || heightConstraint < 0) { return(Size.Zero); } var explicitWidth = VirtualView.Width; var explicitHeight = VirtualView.Height; var useExplicitWidth = explicitWidth >= 0; var useExplicitHeight = explicitHeight >= 0; if (useExplicitWidth) { widthConstraint = Math.Min(VirtualView.Width, widthConstraint); } if (useExplicitHeight) { heightConstraint = Math.Min(VirtualView.Height, heightConstraint); } var measureConstraint = new Windows.Foundation.Size(widthConstraint, heightConstraint); NativeView.Measure(measureConstraint); var desiredWidth = NativeView.DesiredSize.Width; var desiredHeight = NativeView.DesiredSize.Height; var resultWidth = useExplicitWidth ? Math.Max(desiredWidth, explicitWidth) : desiredWidth; var resultHeight = useExplicitHeight ? Math.Max(desiredHeight, explicitHeight) : desiredHeight; return(new Size(resultWidth, resultHeight)); }
public void Measure(int widthMeasureSpec, int heightMeasureSpec, int?maxHeightPixels, int?maxWidthPixels) { //if (width == -1) // width = double.PositiveInfinity; //if (height == -1) // height = double.PositiveInfinity; //Width = width; //Height = height; //MaxWidth = maxWidth; //MaxHeight = maxHeight; //X = x; //Y = y; var width = widthMeasureSpec.GetSize(); var height = heightMeasureSpec.GetSize(); var maxWidth = maxWidthPixels; var maxHeight = maxHeightPixels; Context context; if (Handler == null || !(_context.TryGetTarget(out context)) || !NativeView.IsAlive()) { return; } if (View == null) { //MauiView.Measure(0, 0); //MauiView.Arrange(Rectangle.Zero); return; } // NativeView.Measure(widthMeasureSpec, heightMeasureSpec); var layoutParams = NativeView.LayoutParameters; //if (double.IsInfinity(height)) // height = request.Height; //if (double.IsInfinity(width)) // width = request.Width; if (height > maxHeight) { heightMeasureSpec = MeasureSpecMode.AtMost.MakeMeasureSpec(maxHeight.Value); } if (width > maxWidth) { widthMeasureSpec = MeasureSpecMode.AtMost.MakeMeasureSpec(maxWidth.Value); } if (layoutParams.Width != LP.MatchParent && width > 0) { layoutParams.Width = width; } else { widthMeasureSpec = MeasureSpecMode.Unspecified.MakeMeasureSpec(0); } if (layoutParams.Height != LP.MatchParent && height > 0) { layoutParams.Height = height; } else { heightMeasureSpec = MeasureSpecMode.Unspecified.MakeMeasureSpec(0); } NativeView.LayoutParameters = layoutParams; //var c = NativeView.Context; //var l = (int)c.ToPixels(x); //var t = (int)c.ToPixels(y); //var r = (int)c.ToPixels(width) + l; //var b = (int)c.ToPixels(height) + t; //NativeView.Layout(l, t, r, b); NativeView.Measure(widthMeasureSpec, heightMeasureSpec); }