Ejemplo n.º 1
0
        protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            var    code = new StringBuilder();
            string name = FigmaSharp.Resources.Ids.Conversion.NameIdentifier;

            var frame = (FigmaFrame)currentNode.Node;

            currentNode.Node.TryGetNativeControlType(out FigmaControlType controlType);
            currentNode.Node.TryGetNativeControlVariant(out NativeControlVariant controlVariant);

            if (rendererService.NeedsRenderConstructor(currentNode, parentNode))
            {
                code.WriteConstructor(name, GetControlType(currentNode.Node), rendererService.NodeRendersVar(currentNode, parentNode));
            }

            FigmaVector rectangle = frame.children
                                    .OfType <FigmaVector>()
                                    .FirstOrDefault(s => s.name == ComponentString.VALUE);

            foreach (var styleMap in rectangle?.styles)
            {
                if ((rendererService.figmaProvider as NodeProvider).TryGetStyle(styleMap.Value, out FigmaStyle style))
                {
                    if (styleMap.Key == "fill")
                    {
                        code.WriteEquality(name, nameof(NSColorWell.Color), ColorService.GetNSColorString(style.name));
                    }
                }
            }

            return(code);
        }
Ejemplo n.º 2
0
        protected override IView OnConvertToView(FigmaNode currentNode, ViewNode parentNode, ViewRenderService rendererService)
        {
            var colorWell = new NSColorWell()
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };
            var frame = (FigmaFrame)currentNode;

            FigmaVector rectangle = frame.children
                                    .OfType <FigmaVector>()
                                    .FirstOrDefault(s => s.name == ComponentString.VALUE);

            foreach (var styleMap in rectangle?.styles)
            {
                if (rendererService.NodeProvider.TryGetStyle(styleMap.Value, out FigmaStyle style))
                {
                    if (styleMap.Key == "fill")
                    {
                        colorWell.Color = ColorService.GetNSColor(style.name);
                    }
                }
            }

            return(new View(colorWell));
        }
        public static void Configure(this FrameworkElement view, FigmaVector child)
        {
            Configure(view, (FigmaNode)child);

            if (view is Panel canvas)
            {
                if (child.HasFills && child.fills[0].color != null)
                {
                    canvas.Background = child.fills[0].color.ToColor();
                }
            }
        }
Ejemplo n.º 4
0
        public static void Configure(this StringBuilder builder, FigmaVector figmaNode, string name)
        {
            Configure(builder, (FigmaNode)figmaNode, name);

            var fills = figmaNode.fills.FirstOrDefault();

            if (fills != null && fills.visible && fills.color != null)
            {
                builder.AppendLine(string.Format("{0}.Layer.BackgroundColor = {1};", name, fills.color.ToDesignerString(true)));
            }

            var strokes = figmaNode.strokes.FirstOrDefault();

            if (strokes != null && strokes.visible)
            {
                if (strokes.color != null)
                {
                    builder.AppendLine(string.Format("{0}.Layer.BorderColor = {1};", name, strokes.color.ToDesignerString(true)));
                }
                builder.AppendLine(string.Format("{0}.Layer.BorderWidth = {1};", name, figmaNode.strokeWeight));
            }
        }
Ejemplo n.º 5
0
 public static void Configure(this NSView view, FigmaVector child)
 {
     Configure(view, (FigmaNode)child);
     view.AlphaValue = child.opacity;
 }
Ejemplo n.º 6
0
        protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            var    code = new StringBuilder();
            string name = FigmaSharp.Resources.Ids.Conversion.NameIdentifier;

            var frame = (FigmaFrame)currentNode.Node;

            currentNode.Node.TryGetNativeControlType(out FigmaControlType controlType);
            currentNode.Node.TryGetNativeControlVariant(out NativeControlVariant controlVariant);

            if (rendererService.NeedsRenderConstructor(currentNode, parentNode))
            {
                code.WriteConstructor(name, GetControlType(currentNode.Node), rendererService.NodeRendersVar(currentNode, parentNode));
            }

            if (controlType == FigmaControlType.Separator)
            {
                code.WriteEquality(name, nameof(NSBox.BoxType), NSBoxType.NSBoxSeparator);
            }

            if (controlType == FigmaControlType.BoxCustom)
            {
                code.WriteEquality(name, nameof(NSBox.BoxType), NSBoxType.NSBoxCustom);
                bool borderSet = false;

                FigmaVector rectangle = frame.children
                                        .OfType <FigmaVector>()
                                        .FirstOrDefault();

                foreach (var styleMap in rectangle?.styles)
                {
                    if ((rendererService.figmaProvider as NodeProvider).TryGetStyle(styleMap.Value, out FigmaStyle style))
                    {
                        if (styleMap.Key == "fill")
                        {
                            code.WriteEquality(name, nameof(NSBox.FillColor), ColorService.GetNSColorString(style.name));
                        }

                        if (styleMap.Key == "stroke")
                        {
                            code.WriteEquality(name, nameof(NSBox.BorderColor), ColorService.GetNSColorString(style.name));
                            code.WriteEquality(name, nameof(NSBox.BorderWidth), rectangle.strokeWeight.ToString());
                            borderSet = true;
                        }
                    }
                }

                if (!borderSet)
                {
                    code.WriteEquality(name, nameof(NSBox.BorderWidth), "0");
                }
            }

            FigmaText text = frame.children
                             .OfType <FigmaText>()
                             .FirstOrDefault(s => (s.name == ComponentString.TITLE && s.visible));

            if (text != null)
            {
                string stringTitle = CodeHelper.GetTranslatableString(text.characters,
                                                                      rendererService.CurrentRendererOptions.TranslateLabels);

                code.WriteEquality(name, nameof(NSBox.Title), stringTitle,
                                   inQuotes: !rendererService.CurrentRendererOptions.TranslateLabels);
            }
            else
            {
                code.WriteEquality(name, nameof(NSBox.Title), "", inQuotes: true);
            }

            return(code);
        }