/// <summary>
        /// Recalculates/Reposition the big/small cicles on resizing
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RelativeLayout1_SizeChanged(object sender, EventArgs e)
        {
            if (_rl1.Width <= 0 || _rl1.Height <= 0)
            {
                return;
            }

            var minRadi = Math.Min(_rl1.Width * 2, _rl1.Height);
            var L       = minRadi * RatioBig;
            var l       = minRadi * RatioSmall;

            var x1 = (_rl1.Width - L) / 2;
            var y1 = (_rl1.Height - L) / 2;
            var c1 = BoundsConstraint.FromExpression((Expression <Func <Rectangle> >)(() => new Rectangle(x1, y1, L, L)));

            RelativeLayout.SetBoundsConstraint(_circleView, c1);

            var x2 = (_rl1.Width - l) / 2;
            var y2 = (_rl1.Height - L) / 2 - l + OverlapSize;
            var c2 = BoundsConstraint.FromExpression((Expression <Func <Rectangle> >)(() => new Rectangle(x2, y2, l, l)));

            RelativeLayout.SetBoundsConstraint(_circleUp, c2);

            var x3 = (_rl1.Width - l) / 2;
            var y3 = (_rl1.Height + L) / 2 - OverlapSize;
            var c3 = BoundsConstraint.FromExpression((Expression <Func <Rectangle> >)(() => new Rectangle(x3, y3, l, l)));

            RelativeLayout.SetBoundsConstraint(_circleDown, c3);

            _rl1.ForceLayout();
        }
        /// <summary>
        /// Update the UI controls position/size when the page layout/size changes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnRootViewSizeChanged(object sender, EventArgs e)
        {
            var w = RLRoot.Width * 3 / 10;
            var h = w;

            if (w <= 0)
            {
                return;
            }

            var x1 = (RLRoot.Width - w) / 2;
            var y1 = RLRoot.Height / 3 - h;
            var c1 = BoundsConstraint.FromExpression((Expression <Func <Rectangle> >)(() => new Rectangle(x1, y1, w, h)));

            RelativeLayout.SetBoundsConstraint(BtnPumpSession, c1);

            var x2 = RLRoot.Width / 1.7 - w - w / 2;
            var y2 = RLRoot.Height / 2 - h / 1.1;
            var c2 = BoundsConstraint.FromExpression((Expression <Func <Rectangle> >)(() => new Rectangle(x2, y2, w, h)));

            RelativeLayout.SetBoundsConstraint(BtnFeedSession, c2);

            var x3 = RLRoot.Width / 2.3 + w / 2;
            var y3 = RLRoot.Height / 2 - h / 1.1;
            var c3 = BoundsConstraint.FromExpression((Expression <Func <Rectangle> >)(() => new Rectangle(x3, y3, w, h)));

            RelativeLayout.SetBoundsConstraint(BtnNurseSession, c3);
            RLRoot.ForceLayout();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Update the UI controls position/size when the page layout/size changes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ONRL1_SizeChanged(object sender, EventArgs e)
        {
            var W = _rl1.Width * 2.93 / 10;
            var H = W;

            if (W <= 0)
            {
                return;
            }

            var x1 = (_rl1.Width - W) / 2;
            var y1 = 16;
            var c1 = BoundsConstraint.FromExpression((Expression <Func <Rectangle> >)(() => new Rectangle(x1, y1, W, H)));

            RelativeLayout.SetBoundsConstraint(BtnPumpSession, c1);

            var w = _rl1.Width * 2.56 / 10;
            var h = w;

            var x2 = x1 - w - 14;
            var y2 = y1 + H / 2 + 12;
            var c2 = BoundsConstraint.FromExpression((Expression <Func <Rectangle> >)(() => new Rectangle(x2, y2, w, h)));

            RelativeLayout.SetBoundsConstraint(BtnFeedSession, c2);

            var x3 = x1 + W + 14;
            var y3 = y2;
            var c3 = BoundsConstraint.FromExpression((Expression <Func <Rectangle> >)(() => new Rectangle(x3, y3, w, h)));

            RelativeLayout.SetBoundsConstraint(BtnNurseSession, c3);
            _rl1.ForceLayout();
        }
Ejemplo n.º 4
0
        private void SetDisplayEditButton(bool bWidthVisible)
        {
            if (bWidthVisible)
            {
                double dX = (this.Width / 2) + ((Kataview.X + Kataview.WidthRequest) / 2) - Editsentence.Width;
                double dY = (this.Height / 2) + ((Kataview.Y + Kataview.HeightRequest) / 2) - Editsentence.Height;

                RelativeLayout.SetBoundsConstraint(Editsentence,
                                                   BoundsConstraint.FromExpression(
                                                       () => new Rectangle(
                                                           dX,
                                                           dY,
                                                           Editsentence.Width,
                                                           Editsentence.Height),
                                                       null));
            }
            else
            {
                double dX = (this.Width / 2) + ((Kataview.X + Kataview.WidthRequest) / 2) - Editsentence.Width;
                double dY = (this.Height / 2) + ((Kataview.Y + Kataview.HeightRequest) / 2) - (Editsentence.Height) - 5;

                RelativeLayout.SetBoundsConstraint(Editsentence,
                                                   BoundsConstraint.FromExpression(
                                                       () => new Rectangle(
                                                           dX,
                                                           dY,
                                                           Editsentence.Width,
                                                           Editsentence.Height),
                                                       null));
            }
        }
Ejemplo n.º 5
0
        //TODO Implement shape classes (Rectangle done)
        static void Initialize()
        {
            deltaClock = new Clock();


            _window.MouseButtonPressed  += Input.onMousePressed;
            _window.MouseButtonReleased += Input.onMouseRelease;
            _window.MouseMoved          += Input.onMouseMove;
            _window.Closed += Input.onWindowClose;

            deltaClock.Restart();

            windowBounds = new BoundsConstraint(new Rect(0, 0, 800, 600), 0.3f);

            Vector2f[] rect     = { new Vector2f(25, 25), new Vector2f(125, 25), new Vector2f(125, 125), new Vector2f(25, 125) };
            Vector2f[] triangle = { new Vector2f(25, 25), new Vector2f(25, 125), new Vector2f(125, 125) };
            Test  = new Rectangle(rect.Select(x => new PointMass(x)).ToArray());
            Test2 = new Triangle(triangle.Select(x => new PointMass(x)).ToArray());


            //TODO Attempt multithreading constraint solving

            /*
             * PointMass TestOne = new PointMass(new Vector2f(25, 25));
             * PointMass TestTwo = new PointMass(new Vector2f(125, 25));
             * PointMass TestThree = new PointMass(new Vector2f(125, 125));
             * PointMass TestFour = new PointMass(new Vector2f(25, 125));
             *
             *
             * PointMass TestThree = new PointMass(new Vector2f(225, 200));
             *
             * PointMass TestFour = new PointMass(new Vector2f(150, 400));
             * PointMass TestFive = new PointMass(new Vector2f(300, 400));
             * PointMass TestSix = new PointMass(new Vector2f(225, 200));
             * PointMass TestSeven = new PointMass(mousePos);
             *
             *
             * RodConstraint TestRod2 = new RodConstraint(TestTwo, TestThree, 100);
             * RodConstraint TestRod3 = new RodConstraint(TestThree, TestOne, 100);
             * RodConstraint TestRod4 = new RodConstraint(TestFour, TestFive, 50);
             * RodConstraint TestRod5 = new RodConstraint(TestFive, TestSix, 50);
             * RodConstraint TestRod6 = new RodConstraint(TestSix, TestFour, 50);
             * RodConstraint TestRod7 = new RodConstraint(TestSeven, TestOne, 50);
             *
             *
             * RodConstraint TestRod = new RodConstraint(TestOne, TestTwo, 100);
             * RodConstraint TestRod2 = new RodConstraint(TestTwo, TestThree, 100);
             * RodConstraint TestRod3 = new RodConstraint(TestThree, TestFour, 100);
             * RodConstraint TestRod4 = new RodConstraint(TestFour, TestOne, 100);
             * double hypotenuse = Math.Sqrt((100 * 100) * 2);
             * RodConstraint TestRod5 = new RodConstraint(TestOne, TestThree, hypotenuse);
             * RodConstraint TestRod6 = new RodConstraint(TestFour, TestTwo, hypotenuse);
             */

            Constraint.drawAll(true);
            //PointMass.drawAll(true);
        }
Ejemplo n.º 6
0
            public void Add(View view, Expression <Func <Rectangle> > bounds)
            {
                if (bounds == null)
                {
                    throw new ArgumentNullException(nameof(bounds));
                }
                SetBoundsConstraint(view, BoundsConstraint.FromExpression(bounds, fromExpression: true));

                base.Add(view);
            }
Ejemplo n.º 7
0
        /*
         * Hack for rezising and changing position of elements,
         * as it's not an operation supported by default
         *
         * Be sure to call ForceLayout() on the view's parent after rezising element
         */
        public void UpdateLayout(double x, double y, double w, double h)
        {
            var constraint = BoundsConstraint.FromExpression(() => new Rectangle(x, y, w, h), new View[0]);

            SetBoundsConstraint(this, constraint);

            if (Parent != null && Parent is RelativeLayout)
            {
                (Parent as RelativeLayout).ForceLayout();
            }
        }
Ejemplo n.º 8
0
        protected override void OnAdded(View view)
        {
            BoundsConstraint boundsConstraint = GetBoundsConstraint(view);

            if (boundsConstraint == null || !boundsConstraint.CreatedFromExpression)
            {
                // user probably added the view through the strict Add method.
                CreateBoundsFromConstraints(view, GetXConstraint(view), GetYConstraint(view), GetWidthConstraint(view), GetHeightConstraint(view));
            }

            _childrenInSolveOrder = null;
            base.OnAdded(view);
        }
Ejemplo n.º 9
0
        static Rectangle SolveView(View view)
        {
            BoundsConstraint boundsConstraint = GetBoundsConstraint(view);

            if (boundsConstraint == null)
            {
                throw new Exception("BoundsConstraint should not be null at this point");
            }

            var result = boundsConstraint.Compute();

            return(result);
        }
Ejemplo n.º 10
0
        public virtual void AddSubview(View view, double x, double y, double w, double h)
        {
            if (view.Parent == null)
            {
                Children.Add(view, GetConstraint(x), GetConstraint(y), GetConstraint(w), GetConstraint(h, ConstraintProperty_Height));
            }
            else
            {
                var constraint = BoundsConstraint.FromExpression(() => new Rectangle(x, y, w, h), new View[0]);
                SetBoundsConstraint(view, constraint);

                if (view.Parent is RelativeLayout)
                {
                    (view.Parent as RelativeLayout).ForceLayout();
                }
            }
        }
Ejemplo n.º 11
0
        private void SetLocationArrow(bool bVisible)
        {
            if (bVisible)
            {
                IsVisibleBottomArrow(false);

                SetDisplayEditButton(true);


                RelativeLayout.SetBoundsConstraint(upPrePayImage,
                                                   BoundsConstraint.FromExpression(
                                                       () => new Rectangle(
                                                           relLayout.X + 10,
                                                           ((relLayout.Height - upPrePayImage.Height) - 10),//(relLayout.Height / 2 - upPrePayImage.Height / 2),
                                                           upPrePayImage.Width,
                                                           upPrePayImage.Height),
                                                       null));

                RelativeLayout.SetBoundsConstraint(upNextplayImage,
                                                   BoundsConstraint.FromExpression(
                                                       () => new Rectangle(
                                                           ((relLayout.Width - upNextplayImage.Width) - 10),
                                                           ((relLayout.Height - upPrePayImage.Height) - 10),//(relLayout.Height / 2 - upPrePayImage.Height / 2),
                                                           upNextplayImage.Width,
                                                           upNextplayImage.Height),
                                                       null));
            }
            else
            {
                IsVisibleBottomArrow(true);

                SetDisplayEditButton(false);
            }

            RelativeLayout.SetBoundsConstraint(playImage,
                                               BoundsConstraint.FromExpression(
                                                   () => new Rectangle(
                                                       ((relLayout.Width - playImage.Width) - 1.5), //((relLayout.Width - playImage.Width) - 10),
                                                       (relLayout.Y + 1.5),                         //relLayout.Y,//relLayout.Y + 10,
                                                       playImage.Width,
                                                       playImage.Height),
                                                   null));
        }
Ejemplo n.º 12
0
        /*
         * private async Task SlideIn()
         * {
         *  await this.FadeTo(0);
         *  var animate = new Animation();
         *  var slidein = new Animation(callback: ax => this.TranslationY = ax,
         *          start: Height,
         *          end: 0,
         *          easing: Easing.SpringOut);
         *  animate.Add(0, 1, slidein);
         *  animate.Commit(this, "SlideIn", length: 1000);
         *  await this.FadeTo(1);
         * }
         *
         * private async Task SlideOut()
         * {
         *  await this.FadeTo(1);
         *  var animate = new Animation();
         *  var slideout = new Animation(callback: ax => this.TranslationY = ax,
         *         start: 0,
         *         end: -Height,
         *         easing: Easing.SpringIn);
         *  animate.Add(0, 1, slideout);
         *  animate.Commit(this, "SlideOut", length: 1000);
         *  await this.FadeTo(0);
         * }
         */

        protected override void OnSizeAllocated(double width, double height)
        {
            base.OnSizeAllocated(width, height);

            if (width <= 0 || height <= 0)
            {
                return;
            }

            RelativeLayout.SetBoundsConstraint(btnTextRecord,
                                               BoundsConstraint.FromExpression(
                                                   () => new Rectangle(
                                                       relLayout.X + 10,
                                                       ((relLayout.Height - btnTextRecord.Height) - 10),
                                                       btnTextRecord.Width,
                                                       btnTextRecord.Height),
                                                   null));

            this.UpdateChildrenLayout();
        }
Ejemplo n.º 13
0
        bool CanSolveView(View view, Dictionary <View, bool> solveTable)
        {
            BoundsConstraint boundsConstraint = GetBoundsConstraint(view);
            var parents = new List <View>();

            if (boundsConstraint == null)
            {
                throw new Exception("BoundsConstraint should not be null at this point");
            }
            parents.AddRange(boundsConstraint.RelativeTo);
            // expressions probably referenced the base layout somewhere
            while (parents.Remove(this))             // because winphone does not have RemoveAll...
            {
                ;
            }

            if (!parents.Any())
            {
                return(true);
            }

            for (var i = 0; i < parents.Count; i++)
            {
                View p = parents[i];

                bool solvable;
                if (!solveTable.TryGetValue(p, out solvable))
                {
                    throw new InvalidOperationException("Views that have relationships to or from them must be kept in the RelativeLayout.");
                }

                if (!solvable)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 14
0
            public void Add(View view, Expression <Func <double> > x = null, Expression <Func <double> > y = null, Expression <Func <double> > width = null, Expression <Func <double> > height = null)
            {
                Func <double> xCompiled = x != null?x.Compile() : () => 0;

                Func <double> yCompiled = y != null?y.Compile() : () => 0;

                Func <double> widthCompiled = width != null?width.Compile() : () => view.Measure(Parent.Width, Parent.Height, MeasureFlags.IncludeMargins).Request.Width;

                Func <double> heightCompiled = height != null?height.Compile() : () => view.Measure(Parent.Width, Parent.Height, MeasureFlags.IncludeMargins).Request.Height;

                var parents = new List <View>();

                parents.AddRange(ExpressionSearch.Default.FindObjects <View>(x));
                parents.AddRange(ExpressionSearch.Default.FindObjects <View>(y));
                parents.AddRange(ExpressionSearch.Default.FindObjects <View>(width));
                parents.AddRange(ExpressionSearch.Default.FindObjects <View>(height));

                BoundsConstraint bounds = BoundsConstraint.FromExpression(() => new Rectangle(xCompiled(), yCompiled(), widthCompiled(), heightCompiled()), fromExpression: true, parents: parents.Distinct().ToArray());

                SetBoundsConstraint(view, bounds);

                base.Add(view);
            }
Ejemplo n.º 15
0
    public App()
    {
        var label = new Label {
            Text = "Test",
            HorizontalTextAlignment = TextAlignment.Center,
            VerticalTextAlignment   = TextAlignment.Center,
            BackgroundColor         = Color.Silver
        };
        var layout = new RelativeLayout();

        layout.Children.Add(label,
                            Constraint.Constant(50),
                            Constraint.Constant(100),
                            Constraint.Constant(260),
                            Constraint.Constant(30));
        MainPage = new ContentPage {
            Content = layout
        };

        var fwd = true;

        layout.Animate("bounce",
                       (delta) => {
            var d = fwd ? delta : 1.0 - delta;
            var y = 100.0 + (50.0 * d);
            var c = BoundsConstraint.FromExpression((Expression <Func <Rectangle> >)(() => new Rectangle(50, y, 260, 30)), new View [0]);
            RelativeLayout.SetBoundsConstraint(label, c);
            layout.ForceLayout();
        }, 16, 800, Easing.SinInOut, (f, b) => {
            // reset direction
            fwd = !fwd;
        }, () => {
            // keep bouncing
            return(true);
        });
    }
 public static TBindable SetBoundsConstraint <TBindable>(this TBindable bindable, BoundsConstraint value) where TBindable : BindableObject
 => bindable.Set(RelativeLayout.BoundsConstraintProperty, value);
        public static void UpdateLayout(this View view, double x, double y, double w, double h)
        {
            var constraint = BoundsConstraint.FromExpression(() => new Rectangle(x, y, w, h), new View[0]);

            RelativeLayout.SetBoundsConstraint(view, constraint);
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Sets the bounds constraint of element in RelativeLayout
 /// </summary>
 /// <param name="bindable">Bindable.</param>
 /// <param name="value">Value.</param>
 public static void SetBoundsConstraint(BindableObject bindable, BoundsConstraint value) => Xamarin.Forms.RelativeLayout.SetBoundsConstraint(bindable, value);
Ejemplo n.º 19
0
        /// <summary>
        /// Alternative method for defining constraints within a <see cref="RelativeLayout"/> using <see cref="ExposedConstraint"/>
        /// </summary>
        /// <param name="relativeLayout"><see cref="RelativeLayout"/> to add the <paramref name="view"/> to.</param>
        /// <param name="xConstraint">X constraint.</param>
        /// <param name="yConstraint">Y constraint.</param>
        /// <param name="widthConstraint">Width constraint.</param>
        /// <param name="heightConstraint">Height constraint.</param>
        public static void SetConstraints(this View view, RelativeLayout relativeLayout,
                                          ExposedConstraint xConstraint     = null, ExposedConstraint yConstraint      = null,
                                          ExposedConstraint widthConstraint = null, ExposedConstraint heightConstraint = null)
        {
            var parents = new List <View>();

            Func <double> x;

            if (xConstraint != null)
            {
                x = () => xConstraint.Compute(relativeLayout);
                if (xConstraint.RelativeTo != null)
                {
                    parents.AddRange(xConstraint.RelativeTo);
                }
            }
            else
            {
                x = () => 0;
            }

            Func <double> y;

            if (yConstraint != null)
            {
                y = () => yConstraint.Compute(relativeLayout);
                if (yConstraint.RelativeTo != null)
                {
                    parents.AddRange(yConstraint.RelativeTo);
                }
            }
            else
            {
                y = () => 0;
            }

            Func <double> width;

            if (widthConstraint != null)
            {
                width = () => widthConstraint.Compute(relativeLayout);
                if (widthConstraint.RelativeTo != null)
                {
                    parents.AddRange(widthConstraint.RelativeTo);
                }
            }
            else
            {
                width = () => view.Measure(relativeLayout.Width, relativeLayout.Height, MeasureFlags.IncludeMargins).Request.Width;
            }

            Func <double> height;

            if (heightConstraint != null)
            {
                height = () => heightConstraint.Compute(relativeLayout);
                if (heightConstraint.RelativeTo != null)
                {
                    parents.AddRange(heightConstraint.RelativeTo);
                }
            }
            else
            {
                height = () => view.Measure(relativeLayout.Width, relativeLayout.Height, MeasureFlags.IncludeMargins).Request.Height;
            }

            BoundsConstraint bounds = BoundsConstraint.FromExpression(() => new Rectangle(x(), y(), width(), height()), parents.Distinct().ToArray());

            RelativeLayout.SetBoundsConstraint(view, bounds);
        }
Ejemplo n.º 20
0
 public static void SetBoundsConstraint(BindableObject bindable, BoundsConstraint value)
 {
     bindable.SetValue(BoundsConstraintProperty, value);
 }
Ejemplo n.º 21
0
        void CreateBoundsFromConstraints(View view, Constraint xConstraint, Constraint yConstraint, Constraint widthConstraint, Constraint heightConstraint)
        {
            var parents = new List <View>();

            Func <double> x;

            if (xConstraint != null)
            {
                x = () => xConstraint.Compute(this);
                if (xConstraint.RelativeTo != null)
                {
                    parents.AddRange(xConstraint.RelativeTo);
                }
            }
            else
            {
                x = () => 0;
            }

            Func <double> y;

            if (yConstraint != null)
            {
                y = () => yConstraint.Compute(this);
                if (yConstraint.RelativeTo != null)
                {
                    parents.AddRange(yConstraint.RelativeTo);
                }
            }
            else
            {
                y = () => 0;
            }

            Func <double> width;
            Func <double> height = null;

            if (widthConstraint != null)
            {
                width = () => widthConstraint.Compute(this);
                if (widthConstraint.RelativeTo != null)
                {
                    parents.AddRange(widthConstraint.RelativeTo);
                }
            }
            else
            {
                width = () => view.Measure(Width, heightConstraint != null ? height() : Height, MeasureFlags.IncludeMargins).Request.Width;
            }

            if (heightConstraint != null)
            {
                height = () => heightConstraint.Compute(this);
                if (heightConstraint.RelativeTo != null)
                {
                    parents.AddRange(heightConstraint.RelativeTo);
                }
            }
            else
            {
                height = () => view.Measure(widthConstraint != null ? width() : Width, Height, MeasureFlags.IncludeMargins).Request.Height;
            }

            BoundsConstraint bounds = BoundsConstraint.FromExpression(() => new Rectangle(x(), y(), width(), height()), parents.Distinct().ToArray());

            SetBoundsConstraint(view, bounds);
        }