Example #1
0
        public static void ConstrainSize(this CElement element, double width, double height, ClStrength strength = null)
        {
            if (strength == null)
            {
                strength = ClStrength.Default;
            }

            element.AddConstraint(new ClLinearConstraint(element.width, toLinearExpression(width), strength));
            element.AddConstraint(new ClLinearConstraint(element.height, toLinearExpression(height), strength));
        }
Example #2
0
        public static void Center(this CElement parent, CElement child, EdgeInsets insets, ClStrength strength = null)
        {
            if (strength == null)
            {
                strength = ClStrength.Default;
            }

            parent.AddConstraint(parent.centerX ^ ((insets.Left - insets.Right) / 2) + child.centerX, strength);
            parent.AddConstraint(parent.centerY ^ ((insets.Top - insets.Bottom) / 2) + child.centerY, strength);
        }
Example #3
0
        public static void Center(this CElement parent, CElement child, ClStrength strength = null)
        {
            if (strength == null)
            {
                strength = ClStrength.Default;
            }

            parent.AddConstraint(parent.centerX ^ child.centerX, strength);
            parent.AddConstraint(parent.centerY ^ child.centerY, strength);
        }
Example #4
0
        public static void MakeSizeIntristic(this CElement element, EdgeInsets insets, ClStrength strength = null)
        {
            if (strength == null)
            {
                strength = ClStrength.Default;
            }

            element.AddConstraint(element.width ^ element.intrinsicWidth + insets.Width, strength);
            element.AddConstraint(element.height ^ element.intrinsicHeight + insets.Height, strength);
        }
Example #5
0
 public static void Embed(this CElement parent, CElement child, EdgeInsets insets, ClStrength strength = null)
 {
     if (strength == null)
     {
         strength = ClStrength.Default;
     }
     parent.AddConstraint(new ClLinearConstraint(parent.top, child.top - insets.Top, strength));
     parent.AddConstraint(new ClLinearConstraint(parent.right, child.right + insets.Right, strength));
     parent.AddConstraint(new ClLinearConstraint(parent.bottom, child.bottom + insets.Bottom, strength));
     parent.AddConstraint(new ClLinearConstraint(parent.left, child.left - insets.Left, strength));
 }
        /// <summary>
        /// Removes the subview
        /// </summary>
        /// <param name="element">children to remove</param>
        public void RemoveElement(CElement element)
        {
            if (!elements.Remove(element))
            {
                throw new InvalidOperationException($"view {element} is not a subview of {this}");
            }

            List <ClConstraint> movedConstraints = ShearConstraints(element);

            elements.Remove(element);
            element.parent_ = null;

            //Log.Message($"moved constraints:\n{string.Join("\n", movedConstraints)}");

            foreach (var cn in movedConstraints)
            {
                element.AddConstraint(cn);
            }
            SetNeedsUpdateLayout();
        }
Example #7
0
        private static void Stack(CElement parent, AnchorMapper mapper, StackOptions options, IEnumerable items)
        {
            ClLinearExpression trailing = mapper.Leading(parent) + mapper.GetLeadingExpression(options) * mapper.multipler;
            bool isFirst = true;

            foreach (var item in items)
            {
                CElement           element = null;
                ClLinearExpression size    = null;

                if (item is CElement)
                {
                    element = item as CElement;
                    size    = null;
                }
                else
                {
                    var type = item.GetType();
                    if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(ValueTuple <,>))
                    {
                        var maybeElement = type.GetField("Item1").GetValue(item);
                        var maybeVar     = type.GetField("Item2").GetValue(item);

                        element = maybeElement as CElement;
                        size    = toLinearExpression(maybeVar);
                    }
                }

                if (element != null)
                {
                    var child = element;
                    if (!isFirst)
                    {
                        trailing = trailing + options.Spacing;
                    }
                    parent.AddConstraint(new ClLinearConstraint(trailing, new ClLinearExpression(mapper.Leading(child)), options.Strength));
                    trailing = new ClLinearExpression(mapper.Trailing(child));

                    if (size != null)
                    {
                        parent.AddConstraint(new ClLinearConstraint(mapper.Size(child), size, options.Strength));
                    }
                    else if (options.IntrinsicIfNotSet)
                    {
                        parent.AddConstraint(mapper.Size(child) ^ mapper.IntrinsicSize(child));
                    }
                    if (options.ConstrainSides)
                    {
                        parent.AddConstraints(options.Strength,
                                              mapper.SideA(child) ^ mapper.SideA(parent) + mapper.GetSideAExpression(options) * mapper.multipler,
                                              mapper.SideB(child) ^ mapper.SideB(parent) - mapper.GetSideBExpression(options) * mapper.multipler
                                              );
                    }
                    if (options.AlignToCenter)
                    {
                        parent.AddConstraints(options.Strength,
                                              mapper.Center(child) ^ mapper.Center(parent)
                                              );
                    }
                    isFirst = false;
                }
                else
                {
                    trailing = trailing + toLinearExpression(item) * mapper.multipler;
                }
            }

            if (options.ConstrainEnd)
            {
                parent.AddConstraint(trailing + mapper.GetTrailingExpression(options) * mapper.multipler ^ mapper.Trailing(parent), options.Strength);
            }
        }