Beispiel #1
0
        protected override IView OnConvertToView(FigmaNode currentNode, ProcessedNode parentNode, FigmaRendererService rendererService)
        {
            var frame = (FigmaFrame)currentNode;
            var box   = new NSBox();

            currentNode.TryGetNativeControlType(out NativeControlType controlType);

            if (controlType == NativeControlType.Separator)
            {
                box.BoxType = NSBoxType.NSBoxSeparator;
            }

            if (controlType == NativeControlType.BoxCustom)
            {
                box.BoxType     = NSBoxType.NSBoxCustom;
                box.BorderWidth = 0;

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

                foreach (var styleMap in rectangle?.styles)
                {
                    if (rendererService.FileProvider.TryGetStyle(styleMap.Value, out FigmaStyle style))
                    {
                        if (styleMap.Key == "fill")
                        {
                            box.FillColor = CocoaHelpers.GetNSColor(style.name);
                        }

                        if (styleMap.Key == "stroke")
                        {
                            box.BorderColor = CocoaHelpers.GetNSColor(style.name);
                            box.BorderWidth = rectangle.strokeWeight;
                        }
                    }
                }
            }

            if (controlType == NativeControlType.Box)
            {
                FigmaText text = frame.children
                                 .OfType <FigmaText>()
                                 .FirstOrDefault(s => (s.name == ComponentString.TITLE && s.visible));

                if (text != null)
                {
                    box.Title = text.characters;
                }
                else
                {
                    box.Title = "";
                }
            }

            return(new View(box));
        }
Beispiel #2
0
        protected override IView OnConvertToView(FigmaNode currentNode, ProcessedNode parentNode, FigmaRendererService rendererService)
        {
            var label = new NSTextField();

            label.Editable                = false;
            label.DrawsBackground         = false;
            label.Bordered                = false;
            label.PreferredMaxLayoutWidth = 1;

            var frame = (FigmaFrame)currentNode;

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

            currentNode.TryGetNativeControlType(out NativeControlType controlType);
            currentNode.TryGetNativeControlVariant(out NativeControlVariant controlVariant);

            if (text != null)
            {
                label.StringValue = text.characters;
                label.Alignment   = CocoaHelpers.GetNSTextAlignment(text);
                label.Font        = CocoaHelpers.GetNSFont(controlVariant, text);
            }

            if (controlType == NativeControlType.LabelHeader)
            {
                label.Font = NSFont.SystemFontOfSize(headerFontSize, CocoaHelpers.GetNSFontWeight(text));
            }

            foreach (var styleMap in text?.styles)
            {
                if (rendererService.FileProvider.TryGetStyle(styleMap.Value, out FigmaStyle style))
                {
                    if (styleMap.Key == "fill")
                    {
                        label.TextColor = CocoaHelpers.GetNSColor(style.name);
                    }
                }
            }

            return(new View(label));
        }
        protected override IView OnConvertToView(FigmaNode currentNode, ProcessedNode parentNode, FigmaRendererService rendererService)
        {
            var colorWell = new NSColorWell();
            var frame     = (FigmaFrame)currentNode;

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

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

            return(new View(colorWell));
        }