Ejemplo n.º 1
0
        public void CocoaNodeStringObject_GenerationTest()
        {
            var node             = new CodeNode(new Models.FigmaNode(), "hello");
            var shapeLayerObject = new CocoaNodeStringObject(node, default(Type));

            Assert.AreEqual(node.Name, shapeLayerObject.ToString());
            shapeLayerObject.AddChild("test1");
            Assert.AreEqual($"{node.Name}.test1", shapeLayerObject.ToString());
            shapeLayerObject.AddArrayChild("Views", 2);
            Assert.AreEqual($"{node.Name}.test1.Views[2]", shapeLayerObject.ToString());
            shapeLayerObject.AddCast(typeof(System.String));
            Assert.AreEqual($"(System.String){node.Name}.test1.Views[2]", shapeLayerObject.ToString());
            shapeLayerObject.AddEnclose();
            Assert.AreEqual($"((System.String){node.Name}.test1.Views[2])", shapeLayerObject.ToString());
        }
Ejemplo n.º 2
0
        public void ConfigureCodeProperty(string propertyName, CodeNode codeNode, CocoaStringBuilder code)
        {
            var elipseNode = (FigmaElipse)codeNode.Node;

            var circleLayer = new CocoaNodeStringObject(codeNode, typeof(NSView))
                              .AddChild(nameof(NSView.Layer))
                              .AddArrayChild(nameof(NSView.Layer.Sublayers), 0);

            circleLayer.AddCast(typeof(CAShapeLayer));
            circleLayer.AddEnclose();

            if (propertyName == nameof(Properties.FillColor))
            {
                //to define system colors
                var fills = elipseNode.fills.OfType <FigmaPaint>().FirstOrDefault();
                if (fills != null && fills.color != null)
                {
                    code.WritePropertyEquality(circleLayer.ToString(), nameof(CAShapeLayer.FillColor), fills.color.ToDesignerString(true));
                }
                else
                {
                    code.WritePropertyEquality(circleLayer.ToString(), nameof(CAShapeLayer.FillColor), Members.Colors.Clear);
                }

                return;
            }

            if (propertyName == nameof(Properties.StrokeColor))
            {
                var strokes = elipseNode.strokes.FirstOrDefault();
                if (strokes?.color != null)
                {
                    code.WritePropertyEquality(circleLayer.ToString(),
                                               nameof(CAShapeLayer.StrokeColor),
                                               strokes.color.MixOpacity(strokes.opacity).ToDesignerString(true)
                                               );
                }
                return;
            }

            if (propertyName == nameof(Properties.StrokeDashes))
            {
                if (elipseNode.strokeDashes != null)
                {
                    var number = new NSNumber[elipseNode.strokeDashes.Length];
                    for (int i = 0; i < elipseNode.strokeDashes.Length; i++)
                    {
                        number[i] = elipseNode.strokeDashes[i];
                    }

                    code.WritePropertyEquality(circleLayer.ToString(),
                                               nameof(CAShapeLayer.LineDashPattern),
                                               number.ToDesignerString()
                                               );
                }
                return;
            }

            if (propertyName == nameof(Properties.LineWidth))
            {
                code.WritePropertyEquality(circleLayer.ToString(),
                                           nameof(CAShapeLayer.LineWidth),
                                           elipseNode.strokeWeight.ToString()
                                           );
                return;
            }

            if (propertyName == nameof(Properties.Opacity))
            {
                code.WritePropertyEquality(codeNode.Name,
                                           nameof(NSView.AlphaValue),
                                           elipseNode.opacity.ToString()
                                           );
                return;
            }
        }