Exemplo n.º 1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = "Animation";

            var box1 = new UIView {
                BackgroundColor = UIColor.FromRGB(250, 250, 250)
            };
            var box2 = new UIView {
                BackgroundColor = UIColor.FromRGB(10, 10, 10)
            };
            var box3 = new UIView {
                BackgroundColor = UIColor.FromRGB(240, 240, 240)
            };
            var box4 = new UIView {
                BackgroundColor = UIColor.FromRGB(240, 240, 240)
            };

            // set constraints as usual
            ConstraintHelper

            .Attach(box1)
            .Top().Left().Right().Height(1f)
            .Attach(box2)
            .Width(10f).Height(10f).Center().Middle()
            .Attach(box3)
            .Top(20f).Left().Height(40f).Width(0f)
            .Attach(box4)
            .Bottom(20f).Right().Height(40f).Width(0f)

            // layout constraints (equal to LayoutIfNeeded)
            .UpdateConstraints();


            UIView.Animate(0.8, 0, UIViewAnimationOptions.CurveEaseOut,
                           () => {
                box1.BackgroundColor    = UIColor.FromRGB(10, 10, 10);
                box2.BackgroundColor    = UIColor.FromRGB(128, 128, 128);
                box2.Layer.CornerRadius = 75f;

                // change the constraints
                ConstraintHelper

                .WorkWith(box1)
                .RemoveHeightConstraint().HeightOfParent(0.5f)
                .WorkWith(box2)
                .RemoveWidthConstraint().Width(150f)
                .RemoveHeightConstraint().Height(150f)
                .WorkWith(box3)
                .RemoveWidthConstraint().WidthOfParent(0.8f)
                .WorkWith(box4)
                .RemoveWidthConstraint().WidthOfParent(0.8f)

                // layout constraints again (equal to LayoutIfNeeded)
                .UpdateConstraints();
            }, null
                           );
        }
Exemplo n.º 2
0
 public void TestPhoneNumber()
 {
     Assert.AreEqual(true, ConstraintHelper.ValidatePhoneNumber("0123456789"));
     Assert.AreEqual(true, ConstraintHelper.ValidatePhoneNumber("0 123 456 789"));
     Assert.AreEqual(true, ConstraintHelper.ValidatePhoneNumber("+48 012 345 6789"));
     Assert.AreEqual(false, ConstraintHelper.ValidatePhoneNumber("0123t456789"));
     Assert.AreEqual(false, ConstraintHelper.ValidatePhoneNumber("test"));
 }
Exemplo n.º 3
0
        private bool ValidateForm()
        {
            var result = true;

            result = !ValidationHelper.ValidateTextFiled(LoginBox.Text.Length > 0, LoginBox) ? false : result;
            result = !ValidationHelper.ValidateTextFiled(NameBox.Text.Length > 0, NameBox) ? false : result;
            result = !ValidationHelper.ValidateTextFiled(PhoneBox.Text.Length > 0 && ConstraintHelper.ValidatePhoneNumber(PhoneBox.Text), PhoneBox) ? false : result;
            result = !ValidationHelper.ValidateTextFiled(ConstraintHelper.ValidateEmail(EmailBox.Text), EmailBox) ? false : result;
            return(result);
        }
Exemplo n.º 4
0
        public void SpringDampingTest()
        {
            float erp = 0.3f;
            float cfm = 0.001f;

            float spring  = ConstraintHelper.ComputeSpringConstant(1 / 60f, erp, cfm);
            float damping = ConstraintHelper.ComputeDampingConstant(1 / 60f, erp, cfm);

            Assert.IsTrue(Numeric.AreEqual(erp, ConstraintHelper.ComputeErrorReduction(1 / 60f, spring, damping)));
            Assert.IsTrue(Numeric.AreEqual(cfm, ConstraintHelper.ComputeSoftness(1 / 60f, spring, damping)));
        }
Exemplo n.º 5
0
 public void TestEmail()
 {
     Assert.AreEqual(true, ConstraintHelper.ValidateEmail("*****@*****.**"));
     Assert.AreEqual(false, ConstraintHelper.ValidateEmail("[email protected]"));
     Assert.AreEqual(false, ConstraintHelper.ValidateEmail("testcms.com"));
     Assert.AreEqual(false, ConstraintHelper.ValidateEmail("@cms.com"));
     Assert.AreEqual(false, ConstraintHelper.ValidateEmail("[email protected]"));
     Assert.AreEqual(false, ConstraintHelper.ValidateEmail("test@cmscom"));
     Assert.AreEqual(false, ConstraintHelper.ValidateEmail("test@cms."));
     Assert.AreEqual(false, ConstraintHelper.ValidateEmail("testcmscom"));
 }
Exemplo n.º 6
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = "Sizing";

            var box1 = new UIView {
                BackgroundColor = UIColor.FromRGB(100, 180, 100)
            };
            var box2 = new UIView {
                BackgroundColor = UIColor.FromRGB(100, 180, 150)
            };
            var box3 = new UIView {
                BackgroundColor = UIColor.FromRGB(100, 180, 200)
            };
            var box4 = new UIView {
                BackgroundColor = UIColor.FromRGB(140, 140, 140)
            };
            var box5 = new UIView {
                BackgroundColor = UIColor.FromRGB(160, 160, 160)
            };
            var box6 = new UIView {
                BackgroundColor = UIColor.FromRGB(180, 180, 180)
            };

            ConstraintHelper
            .Attach(box1)
            .Width(80f).Height(100f)                             // setting size by fixed values
            .Top().Left()

            .Attach(box2)
            .WidthOf(box1).HeightOf(box1)                             // setting size to the same of another element
            .Top().LeftOf(box1)

            .Attach(box3)
            .WidthOf(box2, 2f).HeightOf(box2)                             // setting size to the same of another element with modifier
            .Top().LeftOf(box2).StackTop()

            .Attach(box4)
            .WidthOfParent(0.25f)                          // setting sizes of parent containers with modifier
            .HeightFromWidth()                             // use views height as width
            .Top().Left()

            .Attach(box5)
            .WidthOfParent(0.5f)
            .HeightFromWidth()                             // use views width as height
            .Top().LeftOf(box4)

            .Attach(box6)
            .HeightOf(box4)
            .WidthFromHeight()
            .Top().Right();
        }
Exemplo n.º 7
0
        public FileCopy()
        {
            // add the validation to the list of validations for this activity
            this.Constraints.Add(ConstraintHelper.VerifiyNoChildPersistActivity <FileCopy>());

            // create the variables to hold the NoPersistHandle and Bookmark
            this.noPersistHandle  = new Variable <NoPersistHandle>();
            this.bookmarkProgress = new Variable <Bookmark>();

            this.bookmarkProgressCallback = new BookmarkCallback(OnExtensionProgress);
            this.StepIncrement            = 1;
        }
Exemplo n.º 8
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = "Stacking";

            int amount = 15;

            int max        = amount * amount;
            int color      = 255;
            int colorSteps = (int)Math.Floor((double)(255 / max));


            // In this case we work with as scrollview
            _scrollview = new UIScrollView();
            ConstraintHelper.Attach(_scrollview).Top().Right().Bottom().Left();

            // We get us a new constraint helper to work with the scroll view as parent
            var scrollViewConstraintHelper = new ConstraintHelper(_scrollview);

            // Stacking makes it easier to position elements around each other without needing them to know
            // it works exactly the same way as AboveOf, BelowOf, LeftOf and RightOf

            for (int i = 1; i < max + 1; i++)
            {
                scrollViewConstraintHelper
                .Attach(new UIView {
                    BackgroundColor = UIColor.FromRGB(color, color, color)
                })
                .WidthOfParent((float)1 / amount)
                .HeightFromWidth()
                .Top()
                .Left()
                .StackLeft();                         // makes next call of Left behave like LeftOf currrent item

                if (i % amount == 0)
                {
                    scrollViewConstraintHelper
                    .StackTop()                             // makes next call of Top behave like LeftOf currrent item
                    .ResetLeftStack();                      // afterwards Left will position according to parents left
                }

                color -= colorSteps;
            }

            // Since we use a scroll view, it is important to set a bottom constraint
            // for the last element otherwise scrolling will not work
            scrollViewConstraintHelper.Bottom(); // we still work on the last attached element
        }
Exemplo n.º 9
0
        public void SetVelocityTest()
        {
            var body = new RigidBody(new BoxShape(1, 2, 3));

            body.Pose            = new Pose(new Vector3F(10, 20, 30), QuaternionF.CreateRotationY(1.1f));
            body.LinearVelocity  = new Vector3F(1, 2, 3);
            body.AngularVelocity = new Vector3F(4, 5, 6);

            Vector3F pointLocal     = new Vector3F(0.5f, 0.9f, 1.3f);
            Vector3F point          = body.Pose.ToWorldPosition(pointLocal);
            Vector3F targetVelocity = new Vector3F(7, -8, 9);

            Assert.AreNotEqual(targetVelocity, body.GetVelocityOfLocalPoint(pointLocal));

            ConstraintHelper.SetVelocityOfWorldPoint(body, point, targetVelocity);
            Assert.IsTrue(Vector3F.AreNumericallyEqual(targetVelocity, body.GetVelocityOfLocalPoint(pointLocal)));
        }
Exemplo n.º 10
0
        public void ComputeKMatrix()
        {
            var b = new RigidBody(new EmptyShape());

            b.MassFrame = new MassFrame()
            {
                Mass    = 3,
                Inertia = new Vector3F(0.4f, 0.5f, 0.6f),
            };

            var r = new Vector3F(1, 2, 3);
            var k = ConstraintHelper.ComputeKMatrix(b, r);

            var desiredK = 1 / b.MassFrame.Mass * Matrix33F.Identity - r.ToCrossProductMatrix() * Matrix33F.CreateScale(b.MassFrame.InertiaInverse) * r.ToCrossProductMatrix();

            Assert.AreEqual(desiredK, k);
        }
Exemplo n.º 11
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = "Examples";

            _buttonSizing = new AutoRoundButton("Sizing")
            {
                BackgroundColor = UIColor.FromRGB(210, 210, 210)
            };
            _buttonPositioning = new AutoRoundButton("Positioning")
            {
                BackgroundColor = UIColor.FromRGB(180, 180, 180)
            };
            _buttonStacking = new AutoRoundButton("Stacking")
            {
                BackgroundColor = UIColor.FromRGB(150, 150, 150)
            };
            _buttonMargin = new AutoRoundButton("Margin")
            {
                BackgroundColor = UIColor.FromRGB(120, 120, 120)
            };
            _buttonAnimation = new AutoRoundButton("Animation")
            {
                BackgroundColor = UIColor.FromRGB(90, 90, 90)
            };

            ConstraintHelper

            .Attach(_buttonSizing)
            .Top(5f).Center(-50f).HeightFromWidth()

            .Attach(_buttonPositioning)
            .Top(5f).Center(50f).HeightFromWidth().StackTop()

            .Attach(_buttonStacking)
            .Top(-32).Center(-42).HeightFromWidth()

            .Attach(_buttonMargin)
            .Top(10f).Center(42f).HeightFromWidth().StackTop()

            .Attach(_buttonAnimation)
            .Top(-18).Center(-25f).HeightFromWidth().StackTop();
        }
Exemplo n.º 12
0
        /// <summary>
        /// Called when constraint should be set up for a new time step.
        /// </summary>
        /// <remarks>
        /// This method is called by <see cref="Constraint.Setup"/>, but only if the constraint is
        /// enabled and all <see cref="Constraint"/> properties are properly initialized.
        /// </remarks>
        protected override void OnSetup()
        {
            Debug.Assert(_wheel.HasGroundContact, "WheelConstraint must be disabled if wheel does not touch ground.");

            // The pose where the suspension is fixed on the car.
            Pose anchorPoseA = BodyA.Pose * new Pose(_wheel.Offset);

            // The ground contact position relative to the anchor pose.
            Vector3 relativePosition = anchorPoseA.ToLocalPosition(_wheel.GroundPosition);

            // Radius vectors from the centers of mass to the points where the
            // suspension forces should be applied:
            Vector3 rA = anchorPoseA.Position - BodyA.PoseCenterOfMass.Position;
            Vector3 rB = _wheel.GroundPosition - BodyB.PoseCenterOfMass.Position;

            // Get some simulation settings.
            float deltaTime                  = Simulation.Settings.Timing.FixedTimeStep;
            float allowedDeviation           = Simulation.Settings.Constraints.AllowedPenetration;
            float maxErrorCorrectionVelocity = Simulation.Settings.Constraints.MaxErrorCorrectionVelocity;

            // The position of ground contact relative to the suspension anchor pose.
            float relativePositionY = relativePosition.Y;

            // The suspension axis (= the Y axis of the chassis body).
            var suspensionAxis = BodyA.Pose.Orientation.GetColumn(1);

            {
                // ----- Set up the suspension spring constraint:
                float deviation = -_wheel.SuspensionRestLength - _wheel.Radius - relativePositionY + allowedDeviation;

                // Compute error reduction and softness from spring and damping values.
                // Note: The wheel suspension stiffness and damping are scaled by the mass because they
                // should be scaled with different chassis masses.
                var   mass              = BodyA.MassFrame.Mass;
                var   suspensionSpring  = _wheel.SuspensionStiffness * mass;
                var   suspensionDamping = _wheel.SuspensionDamping * mass;
                float errorReduction    = ConstraintHelper.ComputeErrorReduction(deltaTime, suspensionSpring, suspensionDamping);
                float softness          = ConstraintHelper.ComputeSoftness(deltaTime, suspensionSpring, suspensionDamping);

                _suspensionSpringConstraint.TargetRelativeVelocity = MathHelper.Clamp(deviation * errorReduction / deltaTime, -maxErrorCorrectionVelocity, maxErrorCorrectionVelocity);
                _suspensionSpringConstraint.Softness = softness / deltaTime;
                _suspensionSpringConstraint.Prepare(BodyA, BodyB, -suspensionAxis, -Vector3.Cross(rA, suspensionAxis), suspensionAxis, Vector3.Cross(rB, suspensionAxis));
            }

            // ----- Set up the hard suspension limit:
            _suspensionLimitIsActive = relativePositionY > -_wheel.MinSuspensionLength - _wheel.Radius;
            if (_suspensionLimitIsActive)
            {
                float deviation = -_wheel.MinSuspensionLength - _wheel.Radius - relativePositionY + allowedDeviation;

                // This constraint is as "hard" as a normal contact constraint.
                float errorReduction = Simulation.Settings.Constraints.ContactErrorReduction;

                _suspensionLimitConstraint.TargetRelativeVelocity = MathHelper.Clamp(deviation * errorReduction / deltaTime, -maxErrorCorrectionVelocity, maxErrorCorrectionVelocity);
                _suspensionLimitConstraint.Prepare(BodyA, BodyB, -suspensionAxis, -Vector3.Cross(rA, suspensionAxis), suspensionAxis, Vector3.Cross(rB, suspensionAxis));
            }
            else
            {
                _suspensionLimitConstraint.ConstraintImpulse = 0;
            }

            // The forward and side constraints are applied in the ground plane. But to make the
            // car more stable we can optionally apply the impulses at a higher position (to avoid rolling).
            rA = rA - (1 - _wheel.RollReduction) * (_wheel.SuspensionLength + _wheel.Radius) * suspensionAxis;

            // ---- Set up lateral friction constraint:
            _sideConstraint.TargetRelativeVelocity = 0;
            _sideConstraint.Prepare(BodyA, BodyB, -_wheel.GroundRight, -Vector3.Cross(rA, _wheel.GroundRight), _wheel.GroundRight, Vector3.Cross(rB, _wheel.GroundRight));

            // ----- Set up forward constraint (motor, brake, friction):
            _forwardConstraint.Prepare(BodyA, BodyB, -_wheel.GroundForward, -Vector3.Cross(rA, _wheel.GroundForward), _wheel.GroundForward, Vector3.Cross(rB, _wheel.GroundForward));

            if (Math.Abs(_wheel.MotorForce) > Math.Abs(_wheel.BrakeForce))
            {
                // The wheel is driven by the motor.
                // The constraint tries to accelerate the car as much as possible. The actual acceleration
                // is limited by the motor and brake force.
                _forwardConstraint.TargetRelativeVelocity = -Math.Sign(_wheel.MotorForce) * float.PositiveInfinity;
                _forwardImpulseLimit = (Math.Abs(_wheel.MotorForce) - Math.Abs(_wheel.BrakeForce)) * deltaTime;
            }
            else
            {
                // The wheel is freely rolling or braking.
                _forwardConstraint.TargetRelativeVelocity = 0;
                _forwardImpulseLimit = Math.Max(_wheel.RollingFrictionForce, _wheel.BrakeForce - Math.Abs(_wheel.MotorForce)) * deltaTime;
            }

            // Warmstart the suspension constraints.
            _suspensionSpringConstraint.ApplyImpulse(BodyA, BodyB, _suspensionSpringConstraint.ConstraintImpulse);
            _suspensionLimitConstraint.ApplyImpulse(BodyA, BodyB, _suspensionLimitConstraint.ConstraintImpulse);

            // Do not warmstart the tangential friction-based constraints.
            _forwardConstraint.ConstraintImpulse = 0;
            _sideConstraint.ConstraintImpulse    = 0;
        }
Exemplo n.º 13
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = "Positioning";

            var box1 = new UIView {
                BackgroundColor = UIColor.FromRGB(100, 100, 100)
            };
            var box2 = new UIView {
                BackgroundColor = UIColor.FromRGB(100, 100, 100)
            };
            var box3 = new UIView {
                BackgroundColor = UIColor.FromRGB(100, 100, 100)
            };
            var box4 = new UIView {
                BackgroundColor = UIColor.FromRGB(100, 100, 100)
            };

            var box5 = new UIView {
                BackgroundColor = UIColor.FromRGB(100, 100, 100)
            };

            var box6 = new UIView {
                BackgroundColor = UIColor.FromRGB(130, 190, 80)
            };
            var box7 = new UIView {
                BackgroundColor = UIColor.FromRGB(130, 190, 80)
            };
            var box8 = new UIView {
                BackgroundColor = UIColor.FromRGB(130, 190, 80)
            };
            var box9 = new UIView {
                BackgroundColor = UIColor.FromRGB(130, 190, 80)
            };

            var box10 = new UIView {
                BackgroundColor = UIColor.FromRGB(0, 100, 250)
            };
            var box11 = new UIView {
                BackgroundColor = UIColor.FromRGB(0, 100, 250)
            };
            var box12 = new UIView {
                BackgroundColor = UIColor.FromRGB(0, 100, 250)
            };
            var box13 = new UIView {
                BackgroundColor = UIColor.FromRGB(0, 100, 250)
            };


            ConstraintHelper

            .Attach(box1)
            .Top()                             // position to the top of the parent view
            .Left()                            // position to the left of the parent view
            .Width(50f).Height(50f)

            .Attach(box2)
            .Bottom()                           // position to the bottom of the parent view
            .Left()                             // position to the left of the parent view
            .Width(50f).Height(50f)

            .Attach(box3)
            .Top()                             // position to the top of the parent view
            .Right()                           // position to the right of the parent view
            .Width(50f).Height(50f)

            .Attach(box4)
            .Bottom()                            // position to the bottom of the parent view
            .Right()                             // position to the right of the parent view
            .Width(50f).Height(50f)


            .Attach(box5)
            .Center()                             // position to the vertical center of the parent view
            .Middle()                             // position to the horizontal center of the parent view
            .Width(50f).Height(50f)


            .Attach(box6)
            .AboveOf(box5)                             // position above another view
            .Center()
            .Width(50f).Height(50f)

            .Attach(box7)
            .BelowOf(box5)                             // position below another view
            .Center()
            .Width(50f).Height(50f)

            .Attach(box8)
            .RightOf(box5)                             // position on the right of another view
            .Middle()
            .Width(50f).Height(50f)

            .Attach(box9)
            .LeftOf(box5)                             // position on the left of another view
            .Middle()
            .Width(50f).Height(50f)


            .Attach(box10)
            .AboveOf(box6)
            .RightOf(box8)
            .Width(50f).Height(50f)

            .Attach(box11)
            .AboveOf(box6)
            .LeftOf(box9)
            .Width(50f).Height(50f)

            .Attach(box12)
            .BelowOf(box7)
            .RightOf(box8)
            .Width(50f).Height(50f)

            .Attach(box13)
            .BelowOf(box7)
            .LeftOf(box9)
            .Width(50f).Height(50f);
        }
Exemplo n.º 14
0
 public override void ViewDidLoad()
 {
     base.ViewDidLoad();
     View.BackgroundColor = UIColor.White;
     ConstraintHelper     = new ConstraintHelper(View);
 }
Exemplo n.º 15
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = "Margin";

            var box1 = new UIView()
            {
                BackgroundColor = UIColor.FromRGB(200, 200, 200)
            };
            var box2 = new UIView()
            {
                BackgroundColor = UIColor.FromRGB(210, 210, 210)
            };
            var box3 = new UIView()
            {
                BackgroundColor = UIColor.FromRGB(220, 220, 220)
            };

            var box4 = new UIView()
            {
                BackgroundColor = UIColor.FromRGB(230, 230, 230)
            };
            var box5 = new UIView()
            {
                BackgroundColor = UIColor.FromRGB(230, 230, 230)
            };

            var box6 = new UIView()
            {
                BackgroundColor = UIColor.FromRGB(240, 240, 240)
            };
            var box7 = new UIView()
            {
                BackgroundColor = UIColor.FromRGB(240, 240, 240)
            };
            var box8 = new UIView()
            {
                BackgroundColor = UIColor.FromRGB(240, 240, 240)
            };

            var helper = new UIView();

            // Margins are handeld similarly as they are in CSS. Methods for them also follow the same rules.
            // Margins will not collapse and will have affect when you position a an element around another
            ConstraintHelper

            .Attach(box1)
            .Left(10f)                            // add left margin
            .Right(10f)                           // add right margin
            .Top(10f)                             // add top margin
            .Height(40f)
            .StackTop()

            .Attach(box2)
            .SetMargin(10f)                     // setting all margin at once
            .Left()                             // the element still has to be positioned
            .Right()
            .Top()
            .Height(40f)
            .StackTop()

            .Attach(box3)
            // margin don't collaps, the bottom margin of the previous element takes effect, so no margin top
            .SetMargin(0, 10f)                  // there is multiple signatures (N, E, S, W), (N&S, E&W), (All the same)
            .Left()                             // the element still has to be positioned
            .Right()
            .Top()
            .Height(40f)
            .StackTop()

            // you can modify width and height you inherit of another view
            .Attach(box4)
            .SetMargin(10f, 5f, 0, 10f)
            .Top()
            .Left()
            .WidthOfParent(0.5f, -15f)                             // left and right margin as modifier
            .Height(45f)

            .Attach(box5)
            .SetMargin(10f, 10f, 0, 5f)
            .Top()
            .Right()
            .WidthOfParent(0.5f, -15f)                             // left and right margin as modifier
            .Height(45f)
            .StackTop()

            // don't be afraid to use helper views
            .Attach(helper)
            .WidthOfParent(1f, -10f)
            .Top(10f)
            .Left();

            (new ConstraintHelper(helper))
            .Attach(box6)
            .SetMargin(0, 0, 0, 10f)
            .Top()
            .Left().StackLeft()
            .WidthOfParent(0.3333f, -10f)
            .Height(45f)

            .Attach(box7)
            .SetMargin(0, 0, 0, 10f)
            .Top()
            .Left().StackLeft()
            .WidthOfParent(0.3333f, -10f)
            .Height(45f)

            .Attach(box8)
            .SetMargin(0, 0, 0, 10f)
            .Top()
            .Left().StackLeft()
            .WidthOfParent(0.3333f, -10f)
            .Height(45f)
            // make it a habit of pinning the last element to the bottom
            // if the parents height is not predefined (specialy if you use scroll views!)
            .Bottom();
        }