internal static Xamarin.Forms.Size Measure(ExtraView view) { var display = (Context as Activity)?.WindowManager.DefaultDisplay; Point size = new Point(); display.GetSize(size); var dWidth = Context.FromPixels(size.X); var dHeight = Context.FromPixels(size.Y); var fWidth = view.ProportionalWidth >= 0 ? dWidth * view.ProportionalWidth : dWidth; var fHeight = view.ProportionalHeight >= 0 ? dHeight * view.ProportionalHeight : dHeight; if (view.ProportionalWidth < 0 || view.ProportionalHeight < 0) { var sizeRequest = view.Measure(fWidth, fHeight); var reqWidth = view.ProportionalWidth >= 0 ? fWidth : sizeRequest.Request.Width; var reqHeight = view.ProportionalHeight >= 0 ? fHeight : sizeRequest.Request.Height; return(new XF.Size(reqWidth, reqHeight)); } return(new XF.Size(fWidth, fHeight)); }
internal static Size Measure(ExtraView view) { var window = UIApplication.SharedApplication.KeyWindow; var dWidth = window.Bounds.Width; var dHeight = window.Bounds.Height; double fWidth = dWidth; if (view.ProportionalWidth >= 0) { fWidth = dWidth * view.ProportionalWidth; } else if (view.HorizontalLayoutAlignment == LayoutAlignment.Fill) { fWidth = dWidth; } else if (view.WidthRequest == -1) { fWidth = double.PositiveInfinity; } else if (view.WidthRequest >= 0) { fWidth = view.WidthRequest; } double fHeight = dHeight; if (view.ProportionalHeight >= 0) { fHeight = dHeight * view.ProportionalHeight; } else if (view.VerticalLayoutAlignment == LayoutAlignment.Fill) { fHeight = dHeight; } else if (view.HeightRequest == -1) { fHeight = double.PositiveInfinity; } else if (view.HeightRequest >= 0) { fHeight = view.HeightRequest; } if (view.ProportionalWidth < 0 || view.ProportionalHeight < 0) { var sizeRequest = view.Measure(fWidth, fHeight, MeasureFlags.IncludeMargins); var reqWidth = view.ProportionalWidth >= 0 ? fWidth : sizeRequest.Request.Width; var reqHeight = view.ProportionalHeight >= 0 ? fHeight : sizeRequest.Request.Height; return(new Size(reqWidth, reqHeight)); } // If both width and height are proportional, Measure is not called. return(new Size(fWidth, fHeight)); }
internal static Xamarin.Forms.Size Measure(ExtraView view) { var dWidth = Context.FromPixels(ContentSize.Width); var dHeight = Context.FromPixels(ContentSize.Height); double fWidth = dWidth; if (view.ProportionalWidth >= 0) { fWidth = dWidth * view.ProportionalWidth; } else if (view.HorizontalLayoutAlignment == XF.LayoutAlignment.Fill) { fWidth = dWidth; } else if (view.WidthRequest == -1) { fWidth = double.PositiveInfinity; } else if (view.WidthRequest >= 0) { fWidth = view.WidthRequest; } double fHeight = dHeight; if (view.ProportionalHeight >= 0) { fHeight = dHeight * view.ProportionalHeight; } else if (view.VerticalLayoutAlignment == XF.LayoutAlignment.Fill) { fHeight = dHeight; } else if (view.HeightRequest == -1) { fHeight = double.PositiveInfinity; } else if (view.HeightRequest >= 0) { fHeight = view.HeightRequest; } if (view.ProportionalWidth < 0 || view.ProportionalHeight < 0) { var sizeRequest = view.Measure(fWidth, fHeight, XF.MeasureFlags.IncludeMargins); var reqWidth = view.ProportionalWidth >= 0 ? fWidth : sizeRequest.Request.Width; var reqHeight = view.ProportionalHeight >= 0 ? fHeight : sizeRequest.Request.Height; return(new XF.Size(reqWidth, reqHeight)); } return(new XF.Size(fWidth, fHeight)); }
internal static ViewGroup SetViewAppearance(ExtraView formsView, ViewGroup nativeView) { if (formsView.CornerRadius > 0 && formsView.BorderWidth > 0) { var wrapper = new CardView(Context); wrapper.Radius = Context.ToPixels(formsView.CornerRadius); wrapper.SetCardBackgroundColor(formsView.BorderColor.ToAndroid()); wrapper.CardElevation = 0; var borderW = (int)Context.ToPixels(formsView.BorderWidth); wrapper.SetContentPadding(borderW, borderW, borderW, borderW); wrapper.SetClipChildren(true); var inner = nativeView; var border = new GradientDrawable(); var innerRadius = Math.Max(formsView.CornerRadius - formsView.BorderWidth, 0); border.SetCornerRadius(Context.ToPixels(innerRadius)); if (!formsView.BackgroundColor.IsDefault) { border.SetColor(formsView.BackgroundColor.ToAndroid()); } inner.SetBackground(border); inner.ClipToOutline = true; wrapper.AddView(inner); return(wrapper); } if (formsView.CornerRadius > 0 || formsView.BorderWidth > 0) { var border = new GradientDrawable(); if (formsView.CornerRadius > 0) { border.SetCornerRadius(Context.ToPixels(formsView.CornerRadius)); } if (!formsView.BackgroundColor.IsDefault) { border.SetColor(formsView.BackgroundColor.ToAndroid()); } if (formsView.BorderWidth > 0) { var borderW = (int)Context.ToPixels(formsView.BorderWidth); border.SetStroke(borderW, formsView.BorderColor.ToAndroid()); nativeView.SetPadding(borderW, borderW, borderW, borderW); } nativeView.SetBackground(border); nativeView.ClipToOutline = true; } return(nativeView); }
internal static Size Measure(ExtraView view) { var window = UIApplication.SharedApplication.KeyWindow; var dWidth = window.Bounds.Width; var dHeight = window.Bounds.Height; var fWidth = view.ProportionalWidth >= 0 ? dWidth * view.ProportionalWidth : dWidth; var fHeight = view.ProportionalHeight >= 0 ? dHeight * view.ProportionalHeight : dHeight; if (view.ProportionalWidth < 0 || view.ProportionalHeight < 0) { var sizeRequest = view.Measure(fWidth, fHeight); var reqWidth = view.ProportionalWidth >= 0 ? fWidth : sizeRequest.Request.Width; var reqHeight = view.ProportionalHeight >= 0 ? fHeight : sizeRequest.Request.Height; return(new Size(reqWidth, reqHeight)); } // If both width and height are proportional, Measure is not called. return(new Size(fWidth, fHeight)); }
internal static GravityFlags GetGravity(ExtraView view) { GravityFlags gravity = GravityFlags.NoGravity; switch (view.VerticalLayoutAlignment) { case XF.LayoutAlignment.Start: gravity |= GravityFlags.Top; break; case XF.LayoutAlignment.End: gravity |= GravityFlags.Bottom; break; default: gravity |= GravityFlags.CenterVertical; break; } switch (view.HorizontalLayoutAlignment) { case XF.LayoutAlignment.Start: gravity |= GravityFlags.Left; break; case XF.LayoutAlignment.End: gravity |= GravityFlags.Right; break; default: gravity |= GravityFlags.CenterHorizontal; break; } return(gravity); }
internal static void SetOffsetMargin(FrameLayout.LayoutParams layoutParams, ExtraView view) { var offsetX = (int)Context.ToPixels(view.OffsetX); var offsetY = (int)Context.ToPixels(view.OffsetY); // the offset direction is reversed when GravityFlags contains Left or Bottom. if (view.HorizontalLayoutAlignment == XF.LayoutAlignment.End) { layoutParams.RightMargin = offsetX * -1; } else { layoutParams.LeftMargin = offsetX; } if (view.VerticalLayoutAlignment == XF.LayoutAlignment.End) { layoutParams.BottomMargin = offsetY * -1; } else { layoutParams.TopMargin = offsetY; } }
internal static void SetLayoutAlignment(UIView targetView, UIView parentView, ExtraView dialog) { switch (dialog.VerticalLayoutAlignment) { case Xamarin.Forms.LayoutAlignment.Start: targetView.TopAnchor.ConstraintEqualTo(parentView.TopAnchor, dialog.OffsetY).Active = true; break; case Xamarin.Forms.LayoutAlignment.End: targetView.BottomAnchor.ConstraintEqualTo(parentView.BottomAnchor, dialog.OffsetY).Active = true; break; default: targetView.CenterYAnchor.ConstraintEqualTo(parentView.CenterYAnchor, dialog.OffsetY).Active = true; break; } switch (dialog.HorizontalLayoutAlignment) { case Xamarin.Forms.LayoutAlignment.Start: targetView.LeftAnchor.ConstraintEqualTo(parentView.LeftAnchor, dialog.OffsetX).Active = true; break; case Xamarin.Forms.LayoutAlignment.End: targetView.RightAnchor.ConstraintEqualTo(parentView.RightAnchor, dialog.OffsetX).Active = true; break; default: targetView.CenterXAnchor.ConstraintEqualTo(parentView.CenterXAnchor, dialog.OffsetX).Active = true; break; } }