Пример #1
0
        public static StackOptions Create(
            bool constrainStart             = true,
            bool constrainSides             = true,
            bool constrainEnd               = true,
            ClStrength strength             = null,
            EdgeInsets?insets               = null,
            bool intrinsicIfNotSet          = false,
            bool alignToCenter              = false,
            double spacing                  = 0,
            EdgeConstraints edgeConstraints = null)
        {
            var options = new StackOptions();

            options.ConstrainStart    = constrainStart;
            options.ConstrainSides    = constrainSides;
            options.ConstrainEnd      = constrainEnd;
            options.Strength          = strength ?? ClStrength.Default;
            options.Insets            = insets.HasValue ? insets.Value : EdgeInsets.Zero;
            options.IntrinsicIfNotSet = intrinsicIfNotSet;
            options.AlignToCenter     = alignToCenter;
            options.Spacing           = spacing;
            options.EdgeConstraints   = edgeConstraints;

            return(options);
        }
Пример #2
0
 public ClLinearExpression GetSideBExpression(StackOptions options)
 {
     if (options.EdgeConstraints != null)
     {
         return(SideBExpression(options.EdgeConstraints) ?? SideBInset(options.Insets));
     }
     else
     {
         return(SideBInset(options.Insets));
     }
 }
Пример #3
0
 public ClLinearExpression GetTrailingExpression(StackOptions options)
 {
     if (options.EdgeConstraints != null)
     {
         return(TrailingExpression(options.EdgeConstraints) ?? TrailingInset(options.Insets));
     }
     else
     {
         return(TrailingInset(options.Insets));
     }
 }
Пример #4
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);
            }
        }
Пример #5
0
 public static void StackBottom(this CElement parent, StackOptions options, IEnumerable items)
 {
     Stack(parent, toTop, options, items);
 }
Пример #6
0
 public static void StackRight(this CElement parent, StackOptions options, IEnumerable items)
 {
     Stack(parent, toLeft, options, items);
 }
Пример #7
0
 public static void StackBottom(this CElement parent, StackOptions options, params object[] items)
 {
     StackBottom(parent, options, (IEnumerable)items);
 }