Exemplo n.º 1
0
 /// <summary>
 /// Returns a constraint like "this", but with the given relation "r".
 /// </summary>
 /// <returns></returns>
 public LinearConstraint /*!*/ ChangeRelation(ConstraintRelation rel)
 {
     Contract.Ensures(Contract.Result <LinearConstraint>() != null);
     if (Relation == rel)
     {
         return(this);
     }
     else
     {
         LinearConstraint z = new LinearConstraint(rel);
         z.coefficients = (Hashtable)this.coefficients.Clone();
         z.rhs          = this.rhs;
         return(z);
     }
 }
        public static NSLayoutRelation LayoutRelation(this ConstraintRelation @this)
        {
            switch (@this)
            {
            default:
            case ConstraintRelation.Equal:
                return(NSLayoutRelation.Equal);

            case ConstraintRelation.LessThanOrEqual:
                return(NSLayoutRelation.LessThanOrEqual);

            case ConstraintRelation.GreaterThanOrEqual:
                return(NSLayoutRelation.GreaterThanOrEqual);
            }
        }
        internal ConstraintMakerEditable RelatedTo(ConstraintRelatableTarget other, ConstraintRelation relation, string file, uint line)
        {
            var related  = (ConstraintItem)null;
            var constant = (ConstraintConstantTarget)null;

            if (other.Value is UIView)
            {
                constant = 0.0f;
                related  = new ConstraintItem(other.Value, ConstraintAttributes.None);
            }

            else if (other.Value is ConstraintItem)
            {
                constant = 0.0f;
                related  = (ConstraintItem)other.Value;
            }

            else if (other.Value is ConstraintLayoutGuide)
            {
                constant = 0.0f;
                related  = new ConstraintItem(other.Value, ConstraintAttributes.None);
            }

            else if (other.Value is ConstraintConstantTarget)
            {
                constant = (ConstraintConstantTarget)other.Value;
                related  = new ConstraintItem(null, ConstraintAttributes.None);
            }

            else
            {
                Console.WriteLine($"[ERROR] -- Invalid constraint. {file}:{line}");
            }

            var editable = new ConstraintMakerEditable(Description);

            editable.Description.SourceLocation = new Tuple <string, uint>(file, line);
            editable.Description.Relation       = relation;
            editable.Description.Related        = related;
            editable.Description.Constant       = constant;

            return(editable);
        }
Exemplo n.º 4
0
 public LinearConstraint(ConstraintRelation rel) {
   Relation = rel;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Returns a constraint like "this", but with the given relation "r".
 /// </summary>
 /// <returns></returns>
 public LinearConstraint/*!*/ ChangeRelation(ConstraintRelation rel) {
   Contract.Ensures(Contract.Result<LinearConstraint>() != null);
   if (Relation == rel) {
     return this;
   } else {
     LinearConstraint z = new LinearConstraint(rel);
     z.coefficients = (Hashtable)this.coefficients.Clone();
     z.rhs = this.rhs;
     return z;
   }
 }
Exemplo n.º 6
0
 public LinearConstraint(ConstraintRelation rel)
 {
     Relation = rel;
 }
Exemplo n.º 7
0
        public Constraint(ConstraintItem from, ConstraintItem to, ConstraintRelation relation, Tuple <string, uint> sourceLocation, ConstraintMultiplierTarget multiplier, ConstraintConstantTarget constant, ConstraintPriorityTarget priority, string label = null)
        {
            _to          = to;
            _from        = from;
            _relation    = relation;
            _constant    = constant;
            _priority    = priority;
            _multiplier  = multiplier;
            _constraints = new List <LayoutConstraint>();

            Label          = label;
            SourceLocation = sourceLocation;

            var layoutFrom     = _from.LayoutConstraintItem;
            var layoutRelation = _relation.LayoutRelation();

            var layoutToAttributes   = _to.Attributes.LayoutAttributes();
            var layoutFromAttributes = _from.Attributes.LayoutAttributes();



            foreach (var layoutFromAttribute in layoutFromAttributes)
            {
                var layoutToAttribute = default(NSLayoutAttribute);

                if (layoutToAttributes?.Length > 0)
                {
                    if (_from.Attributes == ConstraintAttributes.Edges &&
                        _to.Attributes == ConstraintAttributes.Margins)
                    {
                        switch (layoutFromAttribute)
                        {
                        case NSLayoutAttribute.Top:
                            layoutToAttribute = NSLayoutAttribute.TopMargin;
                            break;

                        case NSLayoutAttribute.Left:
                            layoutToAttribute = NSLayoutAttribute.LeftMargin;
                            break;

                        case NSLayoutAttribute.Bottom:
                            layoutToAttribute = NSLayoutAttribute.BottomMargin;
                            break;

                        case NSLayoutAttribute.Right:
                            layoutToAttribute = NSLayoutAttribute.RightMargin;
                            break;

                        default:
                            throw new InvalidOperationException();
                        }
                    }

                    else if (_from.Attributes == ConstraintAttributes.Margins &&
                             _to.Attributes == ConstraintAttributes.Edges)
                    {
                        switch (layoutFromAttribute)
                        {
                        case NSLayoutAttribute.TopMargin:
                            layoutToAttribute = NSLayoutAttribute.Top;
                            break;

                        case NSLayoutAttribute.LeftMargin:
                            layoutToAttribute = NSLayoutAttribute.Left;
                            break;

                        case NSLayoutAttribute.BottomMargin:
                            layoutToAttribute = NSLayoutAttribute.Bottom;
                            break;

                        case NSLayoutAttribute.RightMargin:
                            layoutToAttribute = NSLayoutAttribute.Right;
                            break;

                        default:
                            throw new InvalidOperationException();
                        }
                    }

                    else if (_from.Attributes == _to.Attributes)
                    {
                        layoutToAttribute = layoutFromAttribute;
                    }

                    else
                    {
                        layoutToAttribute = layoutToAttributes[0];
                    }
                }

                else
                {
                    if (_to.Target == null && (layoutFromAttribute == NSLayoutAttribute.CenterX || layoutFromAttribute == NSLayoutAttribute.CenterY))
                    {
                        layoutToAttribute = ((layoutFromAttribute == NSLayoutAttribute.CenterX) ? NSLayoutAttribute.Left : NSLayoutAttribute.Top);
                    }

                    else
                    {
                        layoutToAttribute = layoutFromAttribute;
                    }
                }

                var layoutConstant = _constant.ValueForAttribute(layoutToAttribute);

                var layoutTo = _to.Target;

                if (layoutTo == null &&
                    layoutToAttribute != NSLayoutAttribute.Width &&
                    layoutToAttribute != NSLayoutAttribute.Height)
                {
                    layoutTo = layoutFrom.Superview;
                }

                // Create layout constraint
                var layoutConstraint = new LayoutConstraint(
                    layoutFrom,
                    layoutFromAttribute,
                    layoutRelation,
                    (UIView)layoutTo,
                    layoutToAttribute,
                    _multiplier,
                    layoutConstant
                    );

                // Set label
                layoutConstraint.Label = Label;

                // Set priority
                layoutConstraint.Priority = _priority;

                // Set constraint
                layoutConstraint.Constraint = this;

                // Append
                _constraints.Add(layoutConstraint);
            }
        }