Beispiel #1
0
        public TFluent AddChild(View view, Rectangle bounds, AbsoluteLayoutFlags flags = AbsoluteLayoutFlags.None)
        {
            this.BuilderActions.Add(absoluteLayout => {
                absoluteLayout.Children.Add(view, bounds, flags);
            });

            return(this as TFluent);
        }
 private static void AddPopupToView(AbsoluteLayoutFlags layoutFlags)
 {
     MainThread.BeginInvokeOnMainThread(() =>
     {
         AbsoluteLayout.SetLayoutFlags(PopUpContent[PopUpContent.Count - 1], layoutFlags);
         AbsoluteLayout.SetLayoutBounds(PopUpContent[PopUpContent.Count - 1], LayoutBounds);
         Absolute.Children.Add(PopUpContent[PopUpContent.Count - 1]);
     });
 }
Beispiel #3
0
 /// <summary>
 /// Adds a <see cref="View"/> to an <see cref="AbsoluteLayout"/>.
 /// </summary>
 /// <param name="Layout">The <see cref="AbsoluteLayout"/> to add the <see cref="View"/> into.</param>
 /// <param name="View">The <see cref="View"/> to add into the <see cref="AbsoluteLayout"/>.</param>
 /// <param name="RelativeX">Relative to the <see cref="AbsoluteLayout"/>, between 0.0 and 1.0</param>
 /// <param name="RelativeY">Relative to the <see cref="AbsoluteLayout"/>, between 0.0 and 1.0</param>
 /// <param name="Flags">Options to layout in the <see cref="AbsoluteLayout"/>.</param>
 public static void AddPosition(this AbsoluteLayout Layout, View View, double RelativeX, double RelativeY,
                                AbsoluteLayoutFlags Flags = AbsoluteLayoutFlags.PositionProportional)
 {
     // PositionProportional flag maps the range (0.0, 1.0) to
     // the range "flush [left|top]" to "flush [right|bottom]"
     AbsoluteLayout.SetLayoutFlags(View, Flags);
     AbsoluteLayout.SetLayoutBounds(View, new Rectangle(RelativeX, RelativeY,
                                                        AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
     Layout.Children.Add(View);
 }
        public static T LayoutFlags <T>(this T element, AbsoluteLayoutFlags flags) where T : IRxElement
        {
            if (element == null)
            {
                return(element);
            }

            element.SetAttachedProperty(AbsoluteLayout.LayoutFlagsProperty, flags);

            return(element);
        }
Beispiel #5
0
        internal override void ComputeConstraintForView(View view)
        {
            AbsoluteLayoutFlags layoutFlags = GetLayoutFlags(view);

            if ((layoutFlags & AbsoluteLayoutFlags.SizeProportional) == AbsoluteLayoutFlags.SizeProportional)
            {
                if (view.VerticalOptions.Alignment == LayoutAlignment.Fill &&
                    view.HorizontalOptions.Alignment == LayoutAlignment.Fill)
                {
                    view.ComputedConstraint = Constraint;
                }

                return;
            }

            var       result       = LayoutConstraint.None;
            Rectangle layoutBounds = GetLayoutBounds(view);

            if ((layoutFlags & AbsoluteLayoutFlags.HeightProportional) != 0)
            {
                bool widthLocked = layoutBounds.Width != AutoSize;
                result = Constraint & LayoutConstraint.VerticallyFixed;
                if (widthLocked)
                {
                    result |= LayoutConstraint.HorizontallyFixed;
                }
            }
            else if ((layoutFlags & AbsoluteLayoutFlags.WidthProportional) != 0)
            {
                bool heightLocked = layoutBounds.Height != AutoSize;
                result = Constraint & LayoutConstraint.HorizontallyFixed;
                if (heightLocked)
                {
                    result |= LayoutConstraint.VerticallyFixed;
                }
            }
            else
            {
                if (layoutBounds.Width != AutoSize)
                {
                    result |= LayoutConstraint.HorizontallyFixed;
                }
                if (layoutBounds.Height != AutoSize)
                {
                    result |= LayoutConstraint.VerticallyFixed;
                }
            }

            view.ComputedConstraint = result;
        }
Beispiel #6
0
        private void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            var viewModel = (DemoPageViewModel)sender;

            AbsoluteLayout.SetLayoutBounds(this.BoundsBox, new Rectangle(viewModel.X, viewModel.Y, viewModel.Width, viewModel.Height));

            viewModel.SetMinMaxs();

            AbsoluteLayoutFlags flags = AbsoluteLayoutFlags.None;

            if (viewModel.FlagsAll)
            {
                flags = flags | AbsoluteLayoutFlags.All;
            }

            if (viewModel.FlagsXProp)
            {
                flags = flags | AbsoluteLayoutFlags.XProportional;
            }

            if (viewModel.FlagsYProp)
            {
                flags = flags | AbsoluteLayoutFlags.YProportional;
            }

            if (viewModel.FlagsSizeProp)
            {
                flags = flags | AbsoluteLayoutFlags.SizeProportional;
            }

            if (viewModel.FlagsWidthProp)
            {
                flags = flags | AbsoluteLayoutFlags.SizeProportional;
            }

            if (viewModel.FlagsHeightProp)
            {
                flags = flags | AbsoluteLayoutFlags.HeightProportional;
            }

            if (viewModel.FlagsPositionProp)
            {
                flags = flags | AbsoluteLayoutFlags.PositionProportional;
            }

            AbsoluteLayout.SetLayoutFlags(this.BoundsBox, flags);
        }
        private bool TryCreateView(
            object source,
            ViewIndex index,
            ref View target,
            AbsoluteLayoutFlags flags = AbsoluteLayoutFlags.All,
            double height             = 1)
        {
            if (Container?.Children == null || source == null)
            {
                return(false);
            }

            var loggableTarget = target;

            InternalLogger.Debug(Tag, () => $"TryCreateView( source: {source}, index: {index}, target: {loggableTarget} )");

            if (target != null)
            {
                Container.Children.Remove(target);
                target.BindingContext = null;
            }

            target = source is DataTemplate dataTemplate
                ? (View)dataTemplate.CreateContent()
                : (View)source;
            target.IsVisible = false;

            var bounds = AbsoluteLayout.GetLayoutBounds(target);

            if (bounds.Width < 1 || bounds.Height < 1)
            {
                // Apply default bounds
                AbsoluteLayout.SetLayoutBounds(target, new Rectangle(1, 1, 1, height));
                AbsoluteLayout.SetLayoutFlags(target, flags);
            }

            Container.Children.Insert((int)index, target);
            return(true);
        }
        public static void Open(ContentView popUpContent, AbsoluteLayoutFlags absoluteLayoutFlags, Rectangle absoluteLayoutBounds, Color overlayBgColor)
        {
            MainThread.BeginInvokeOnMainThread(() =>
            {
                LayoutBounds = absoluteLayoutBounds;
                PopUpContent.Add(popUpContent);

                FindContent();
                if (!(CurrentContent is AbsoluteLayout))
                {
                    AdjustView();
                }
                else
                {
                    Absolute = (AbsoluteLayout)CurrentContent;
                }

                AddOverlayToView(overlayBgColor);
                AddPopupToView(absoluteLayoutFlags);

                ChangeStateOverlay(true);
            });
        }
Beispiel #9
0
 public static T SetAbsoluteLayoutFlags <T>(this T bindable, AbsoluteLayoutFlags absoluteLayoutFlags) where T : BindableObject
 {
     AbsoluteLayout.SetLayoutFlags(bindable, absoluteLayoutFlags);
     return(bindable);
 }
Beispiel #10
0
 /// <summary>
 /// Sets the layout flags of element in AbsoluteLayout
 /// </summary>
 /// <param name="bindable">Bindable.</param>
 /// <param name="flags">Flags.</param>
 public static void SetLayoutFlags(BindableObject bindable, AbsoluteLayoutFlags flags) => Xamarin.Forms.AbsoluteLayout.SetLayoutFlags(bindable, flags);
Beispiel #11
0
        public void SetViewOverlay(View viewOverlay, double width, double height, double xProportional, double yProportional, AbsoluteLayoutFlags layoutFlags = AbsoluteLayoutFlags.All)
        {
            Console.WriteLine("PageController 60 View Overlay Set");

            // Bug: For cabinet edit page, currentpage is not part of tabbed page, thus overlay is not added to the correct page
            currentPageContent.Children.Add(viewOverlaybackgroundTint, new Rectangle(0, 0, 1, 1), layoutFlags);
            currentPageContent.Children.Add(viewOverlay, new Rectangle(xProportional, yProportional, width, height), layoutFlags);
        }
        public static ActivityIndicator AddActivityIndicator(AbsoluteLayout layout, string bindingPath, double x, double y, double width, double height, AbsoluteLayoutFlags flags, Color color)
        {
            ActivityIndicator indicator = new ActivityIndicator {
                Color = color
            };

            indicator.SetBinding(ActivityIndicator.IsRunningProperty, new Binding()
            {
                Path = bindingPath
            });
            AbsoluteLayout.SetLayoutBounds(indicator, new Rectangle(x, y, width, height));
            AbsoluteLayout.SetLayoutFlags(indicator, flags);
            layout.Children.Add(indicator);
            return(indicator);
        }
Beispiel #13
0
 public static TView SetAbsoluteLayout <TView>(this TView view, AbsoluteLayoutFlags flags = AbsoluteLayoutFlags.None, double x = 0, double y = 0, double width = -1, double height = -1) where TView : BindableObject
 {
     AbsoluteLayout.SetLayoutFlags(view, flags);
     AbsoluteLayout.SetLayoutBounds(view, new Rectangle(x, y, width, height));
     return(view);
 }
Beispiel #14
0
 public static void SetLayoutFlags(BindableObject bindable, AbsoluteLayoutFlags flags)
 {
     bindable.SetValue(LayoutFlagsProperty, flags);
 }
Beispiel #15
0
        static Rectangle ComputeLayoutForRegion(View view, Size region)
        {
            var result = new Rectangle();

            SizeRequest         sizeRequest;
            Rectangle           bounds   = GetLayoutBounds(view);
            AbsoluteLayoutFlags absFlags = GetLayoutFlags(view);
            bool widthIsProportional     = (absFlags & AbsoluteLayoutFlags.WidthProportional) != 0;
            bool heightIsProportional    = (absFlags & AbsoluteLayoutFlags.HeightProportional) != 0;
            bool xIsProportional         = (absFlags & AbsoluteLayoutFlags.XProportional) != 0;
            bool yIsProportional         = (absFlags & AbsoluteLayoutFlags.YProportional) != 0;

            if (widthIsProportional)
            {
                result.Width = Device.Info.DisplayRound(region.Width * bounds.Width);
            }
            else if (bounds.Width != AutoSize)
            {
                result.Width = bounds.Width;
            }

            if (heightIsProportional)
            {
                result.Height = Device.Info.DisplayRound(region.Height * bounds.Height);
            }
            else if (bounds.Height != AutoSize)
            {
                result.Height = bounds.Height;
            }

            if (!widthIsProportional && bounds.Width == AutoSize)
            {
                if (!heightIsProportional && bounds.Width == AutoSize)
                {
                    // Width and Height are auto
                    sizeRequest   = view.Measure(region.Width, region.Height, MeasureFlags.IncludeMargins);
                    result.Width  = sizeRequest.Request.Width;
                    result.Height = sizeRequest.Request.Height;
                }
                else
                {
                    // Only width is auto
                    sizeRequest  = view.Measure(region.Width, result.Height, MeasureFlags.IncludeMargins);
                    result.Width = sizeRequest.Request.Width;
                }
            }
            else if (!heightIsProportional && bounds.Height == AutoSize)
            {
                // Only height is auto
                sizeRequest   = view.Measure(result.Width, region.Height, MeasureFlags.IncludeMargins);
                result.Height = sizeRequest.Request.Height;
            }

            if (xIsProportional)
            {
                result.X = Device.Info.DisplayRound((region.Width - result.Width) * bounds.X);
            }
            else
            {
                result.X = bounds.X;
            }

            if (yIsProportional)
            {
                result.Y = Device.Info.DisplayRound((region.Height - result.Height) * bounds.Y);
            }
            else
            {
                result.Y = bounds.Y;
            }

            return(result);
        }
 public static TBindable SetLayoutFlags <TBindable>(this TBindable bindable, AbsoluteLayoutFlags value) where TBindable : BindableObject
 => bindable.Set(AbsoluteLayout.LayoutFlagsProperty, value);
 public static TView WithAbsFlags <TView>(this TView view, AbsoluteLayoutFlags flags) where TView : VisualElement
 {
     AbsoluteLayout.SetLayoutFlags(view, flags);
     return(view);
 }
Beispiel #18
0
        static SizeRequest ComputeBoundingRegionDesiredSize(View view)
        {
            var width  = 0.0;
            var height = 0.0;

            var sizeRequest = new Lazy <SizeRequest>(() => view.Measure(double.PositiveInfinity, double.PositiveInfinity, MeasureFlags.IncludeMargins));

            Rectangle           bounds   = GetLayoutBounds(view);
            AbsoluteLayoutFlags absFlags = GetLayoutFlags(view);
            bool widthIsProportional     = (absFlags & AbsoluteLayoutFlags.WidthProportional) != 0;
            bool heightIsProportional    = (absFlags & AbsoluteLayoutFlags.HeightProportional) != 0;
            bool xIsProportional         = (absFlags & AbsoluteLayoutFlags.XProportional) != 0;
            bool yIsProportional         = (absFlags & AbsoluteLayoutFlags.YProportional) != 0;

            // add in required x values
            if (!xIsProportional)
            {
                width += bounds.X;
            }

            if (!yIsProportional)
            {
                height += bounds.Y;
            }

            double minWidth  = width;
            double minHeight = height;

            if (!widthIsProportional && bounds.Width != AutoSize)
            {
                // fixed size
                width    += bounds.Width;
                minWidth += bounds.Width;
            }
            else if (!widthIsProportional)
            {
                // auto size
                width    += sizeRequest.Value.Request.Width;
                minWidth += sizeRequest.Value.Minimum.Width;
            }
            else
            {
                // proportional size
                width += sizeRequest.Value.Request.Width / Math.Max(0.25, bounds.Width);
                //minWidth += 0;
            }

            if (!heightIsProportional && bounds.Height != AutoSize)
            {
                // fixed size
                height    += bounds.Height;
                minHeight += bounds.Height;
            }
            else if (!heightIsProportional)
            {
                // auto size
                height    += sizeRequest.Value.Request.Height;
                minHeight += sizeRequest.Value.Minimum.Height;
            }
            else
            {
                // proportional size
                height += sizeRequest.Value.Request.Height / Math.Max(0.25, bounds.Height);
                //minHeight += 0;
            }

            return(new SizeRequest(new Size(width, height), new Size(minWidth, minHeight)));
        }
 void SetLayoutFlags(IAbsoluteLayout layout, IView child, AbsoluteLayoutFlags flags)
 {
     layout.GetLayoutFlags(child).Returns(flags);
 }
Beispiel #20
0
 public void Add(View view, Rectangle bounds, AbsoluteLayoutFlags flags = AbsoluteLayoutFlags.None)
 {
     SetLayoutBounds(view, bounds);
     SetLayoutFlags(view, flags);
     Add(view);
 }
Beispiel #21
0
        public static void Add(this AbsoluteLayout layout, IView child, Rectangle bounds, AbsoluteLayoutFlags flags)
        {
            layout.Add(child);

            layout.SetLayoutBounds(child, bounds);
            layout.SetLayoutFlags(child, flags);
        }
Beispiel #22
0
 static bool HasFlag(AbsoluteLayoutFlags a, AbsoluteLayoutFlags b)
 {
     // Avoiding Enum.HasFlag here for performance reasons; we don't need the type check
     return((a & b) == b);
 }
        public static Button AddButton(AbsoluteLayout absoluteLayout, string text, EventHandler onclick, double x, double y, double width, double height, int cornerradius, int fontsize, AbsoluteLayoutFlags flags, Color backgroundColor)
        {
            Button button = new Button()
            {
                Text = text
            };

            if (fontsize != 0)
            {
                button.FontSize = fontsize;
            }
            button.BackgroundColor = backgroundColor;
            if (cornerradius != 0)
            {
                button.CornerRadius = cornerradius;
            }
            button.Clicked += onclick;
            AbsoluteLayout.SetLayoutFlags(button, flags);
            AbsoluteLayout.SetLayoutBounds(button, new Rectangle(x, y, width, height));
            absoluteLayout.Children.Add(button);
            return(button);
        }