Example #1
0
        public void TestUxSizeEqualsUxSizeWithSameValuesReturnsTrue()
        {
            var s1 = new UxSize(3.2f, UxUnit.Percent);
            var s2 = new UxSize(3.2f, UxUnit.Percent);

            Assert.That(s1.Equals(s2), Is.True);
        }
Example #2
0
        public void TestEqualReferenceVariableReturnsTrue()
        {
            var s1 = new UxSize(3.2f, UxUnit.Percent);
            var s2 = s1;

            Assert.That(s1.Equals(s2), Is.True);
        }
Example #3
0
        public void TestGetHashCode()
        {
            var s1 = new UxSize(3.2f, UxUnit.Percent);
            var s2 = new UxSize(3.2f, UxUnit.Pixels);
            var s3 = new UxSize(3.2f, UxUnit.Percent);


            Assert.That(s1.GetHashCode(), Is.Not.EqualTo(s2.GetHashCode()));
            Assert.That(s1.GetHashCode(), Is.EqualTo(s3.GetHashCode()));
        }
Example #4
0
        UxSize AnchorForAlignment(UxAxisAlignment alignment)
        {
            switch (alignment)
            {
            case UxAxisAlignment.Start: return(UxSize.Percent(0));

            case UxAxisAlignment.End: return(UxSize.Percent(100));

            default: return(UxSize.Percent(50));
            }
        }
Example #5
0
        public UxNode BuildSymbolClass(SketchSymbolMaster symbol)
        {
            var symbolClassNode = new UxNode
            {
                ClassName       = "Panel",
                SketchLayerName = symbol.Name,
                Attributes      = new Dictionary <string, IUxSerializeable> {
                    { "ux:Class", new UxString(_symbolClassNameBuilder.GetClassName(symbol)) },
                    { "Width", UxSize.Points((float)symbol.Frame.Width) },
                    { "Height", UxSize.Points((float)symbol.Frame.Height) }
                }
            };

            AddChildrenLayers(symbolClassNode, symbol);
            return(symbolClassNode);
        }
Example #6
0
        public static IControl Create(Text text, IAttribute <UxSize> property)
        {
            var propertyInPoints = property.Focus <UxSize, Points>(s =>
                                                                   s.PointsValue.Select(p => p.ToDouble()).Or(() =>
                                                                                                              s.PixelsValue.Select(p => p.ToDouble()).Or(() =>
                                                                                                                                                         s.PercentagesValue.Value.ToDouble())),
                                                                   (s, vv) =>
                                                                   s.PointsValue.HasValue
                                                ? UxSize.Points(vv.ToDouble())
                                                : s.PixelsValue.HasValue
                                                        ? UxSize.Pixels(vv.ToDouble())
                                                        : UxSize.Percentages(vv.ToDouble()),
                                                                   UxSizeParser.TryParsePoints,
                                                                   UxSizeParser.Serialize,
                                                                   0.0);

            return(Create(text, property.HasLocalValue(), property.IsReadOnly, property.Clear, propertyInPoints));
        }
Example #7
0
        public void TestEqualNullReturnsFalse()
        {
            var s1 = new UxSize(3.2f, UxUnit.Percent);

            Assert.That(s1.Equals(null), Is.False);
        }
Example #8
0
        public void TestEqualOtherTypeReturnsFalse()
        {
            var s1 = new UxSize(3.2f, UxUnit.Percent);

            Assert.That(s1.Equals(new object()), Is.False);
        }
Example #9
0
        public void TestEqualDifferentUxSizeReturnsFalse()
        {
            var s1 = new UxSize(3.2f, UxUnit.Percent);

            Assert.That(s1.Equals(new UxSize(3.2f, UxUnit.Points)), Is.False);
        }
Example #10
0
        public static IControl Create(IElement element, IEditorFactory editors)
        {
            element = element.As("Fuse.Elements.Element");

            var x = element.GetSize("X", UxSize.Points(0.0));
            var y = element.GetSize("Y", UxSize.Points(0.0));

            //var offset = element.GetSize2("Offset", Size.Create(UxSize.Points(0.0), UxSize.Points(0.0))).Transpose(UxSize.Points(0.0));

            var width     = element.GetPoints("Width", 0.0);
            var height    = element.GetPoints("Height", 0.0);
            var maxWidth  = element.GetPoints("MaxWidth", 0.0);
            var maxHeight = element.GetPoints("MaxHeight", 0.0);
            var minWidth  = element.GetPoints("MinWidth", 0.0);
            var minHeight = element.GetPoints("MinHeight", 0.0);

            return(Layout.StackFromTop(

                       Spacer.Medium,
                       Layout.Dock()
                       .Left(Layout.StackFromTop(
                                 editors.Label(" ", width, height),
                                 Spacer.Smaller,
                                 editors.Label("Width", width),
                                 Spacer.Small,
                                 editors.Label("Height", height))
                             .WithWidth(CellLayout.HalfCellWidth))
                       .Left(Spacer.Small)
                       .Left(Layout.StackFromTop(
                                 editors.Label(" ", width, height),
                                 Spacer.Smaller,
                                 editors.Field(width, toolTip: "Width"),
                                 Spacer.Small,
                                 editors.Field(height, toolTip: "Height"))
                             .WithWidth(CellLayout.HalfCellWidth))
                       .Right(Layout.StackFromTop(
                                  editors.Label("Max", maxWidth, maxHeight),
                                  Spacer.Smaller,
                                  editors.Field(maxWidth, toolTip: "Maximum width"),
                                  Spacer.Small,
                                  editors.Field(maxHeight, toolTip: "Maximum height"))
                              .WithWidth(CellLayout.HalfCellWidth))
                       .Right(Spacer.Small)
                       .Right(Layout.StackFromTop(
                                  editors.Label("Min", minWidth, minHeight),
                                  Spacer.Smaller,
                                  editors.Field(minWidth, toolTip: "Minimum width"),
                                  Spacer.Small,
                                  editors.Field(minHeight, toolTip: "Minimum height"))
                              .WithWidth(CellLayout.HalfCellWidth))
                       .Fill(Spacer.Small)
                       .WithInspectorPadding(),
                       Spacer.Medium,
                       Separator.Weak,
                       Spacer.Medium,

                       Layout.Dock()
                       .Fill(
                           Layout.Dock()
                           .Left(editors.Label("X", x)
                                 .WithWidth(26)
                                 .DockLeft(editors.Field(x)).WithWidth(CellLayout.FullCellWidth))
                           .Right(editors.Label("Y", y)
                                  .WithWidth(26)
                                  .DockLeft(editors.Field(y)).WithWidth(CellLayout.FullCellWidth))
                           .Fill(Spacer.Medium))

                       //.Right(Layout.StackFromTop(
                       //		editors.Label("\u2194", offset.Width)
                       //			.CenterHorizontally().WithWidth(26)
                       //			.DockLeft(editors.Field(offset.Width)),
                       //		Spacer.Small,
                       //		editors.Label("\u2195", offset.Height)
                       //			.CenterHorizontally().WithWidth(26)
                       //			.DockLeft(editors.Field(offset.Height)))
                       //	.WithWidth(CellLayout.FullCellWidth))


                       .WithInspectorPadding(),

                       Spacer.Medium, Separator.Weak));
        }
Example #11
0
        public UxNode Build(UxNode node)
        {
            var alignment = _layer.Alignment;

            var frame       = _layer.Frame;
            var parentFrame = _layer.Parent.Frame;

            var attributes = node.Attributes;

            var horizontal = BuildAxisLayout(alignment.Horizontal,
                                             (float)frame.X,
                                             (float)frame.Width,
                                             (float?)parentFrame?.Width ?? 0);

            var vertical = BuildAxisLayout(alignment.Vertical,
                                           (float)frame.Y,
                                           (float)frame.Height,
                                           (float?)parentFrame?.Height ?? 0);

            if (horizontal.Size != null)
            {
                attributes["Width"] = horizontal.Size;
            }

            if (vertical.Size != null)
            {
                attributes["Height"] = vertical.Size;
            }

            var alignmentString = BuildUxAlignmentString(horizontal.Alignment, vertical.Alignment);

            if (alignmentString == "Default")
            {
                // If alignment is Default, we don't need to specify Width|Height="100%"
                if (horizontal.Size == UxSize.Percent(100))
                {
                    attributes.Remove("Width");
                }
                if (vertical.Size == UxSize.Percent(100))
                {
                    attributes.Remove("Height");
                }
            }
            else
            {
                attributes["Alignment"] = new UxString(alignmentString);
            }

            if (horizontal.Offset != null || vertical.Offset != null)
            {
                var horizontalOffset = horizontal.Offset ?? UxSize.Points(0);
                var verticalOffset   = vertical.Offset ?? UxSize.Points(0);

                if (horizontalOffset.Value != 0 || verticalOffset.Value != 0)
                {
                    attributes["Offset"] = new UxVector(horizontalOffset, verticalOffset);
                }
            }

            var hMargin = horizontal.Margin;
            var vMargin = vertical.Margin;

            attributes["Margin"] = new UxFloat4(
                hMargin.X,
                vMargin.X,
                hMargin.Y,
                vMargin.Y);

            return(node);
        }
Example #12
0
        UxAxisLayout BuildAxisLayout(SketchAxisAlignment sa, float start, float size, float parentSize)
        {
            var end = parentSize - (start + size);

            var layout = new UxAxisLayout()
            {
                Alignment = UxAxisAlignment.Start,
                Offset    = UxSize.Points(0),
                Margin    = new UxFloat2(0, 0),
                Size      = null
            };

            if (sa.FixSize)
            {
                layout.Size = UxSize.Points(size);

                if (sa.AlignStart)
                {
                    layout.Margin.X  = start;
                    layout.Alignment = UxAxisAlignment.Start;
                }
                else if (sa.AlignEnd)
                {
                    layout.Margin.Y  = end;
                    layout.Alignment = UxAxisAlignment.End;
                }
                else
                {
                    layout.Alignment = UxAxisAlignment.Center;

                    var offset = start + 0.5f * (size - parentSize);
                    layout.Offset = UxSize.Percent(100 * offset / parentSize);
                }
            }
            else
            {
                if (sa.AlignStart && sa.AlignEnd)
                {
                    layout.Alignment = UxAxisAlignment.Default;
                    layout.Margin.X  = start;
                    layout.Margin.Y  = end;
                }
                else
                {
                    layout.Size = UxSize.Percent(100 * size / parentSize);

                    if (sa.AlignStart)
                    {
                        layout.Alignment = UxAxisAlignment.Start;
                        layout.Offset    = UxSize.Points(start);
                    }
                    else if (sa.AlignEnd)
                    {
                        layout.Alignment = UxAxisAlignment.End;
                        layout.Offset    = UxSize.Points(-end);
                    }
                    else
                    {
                        layout.Alignment = UxAxisAlignment.Start;
                        layout.Offset    = UxSize.Percent(100 * start / parentSize);
                    }
                }
            }

            return(layout);
        }