Пример #1
0
        protected override IView OnConvertToView(FigmaNode currentNode, ProcessedNode parentNode, FigmaRendererService rendererService)
        {
            var textField = new NSTextField();

            var frame = (FigmaFrame)currentNode;

            frame.TryGetNativeControlType(out var controlType);
            frame.TryGetNativeControlVariant(out var controlVariant);


            if (controlType == NativeControlType.SearchField)
            {
                textField = new NSSearchField();
            }


            FigmaNode optionsGroup = frame.Options();

            FigmaNode passwordNode = optionsGroup?.GetChildren()
                                     .OfType <FigmaNode>()
                                     .FirstOrDefault(s => s.name == ComponentString.PASSWORD && s.visible);

            if (passwordNode != null)
            {
                textField             = new NSSecureTextField();
                textField.StringValue = "Password";
            }


            FigmaText placeholderText = optionsGroup?.GetChildren()
                                        .OfType <FigmaText>()
                                        .FirstOrDefault(s => s.name == ComponentString.PLACEHOLDER && s.visible);

            if (placeholderText != null && !placeholderText.characters.Equals(ComponentString.PLACEHOLDER, StringComparison.InvariantCultureIgnoreCase))
            {
                textField.PlaceholderString = placeholderText.characters;
            }



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

            if (text != null)
            {
                textField.Alignment   = CocoaHelpers.GetNSTextAlignment(text);
                textField.StringValue = text.characters;
            }

            textField.ControlSize = CocoaHelpers.GetNSControlSize(controlVariant);
            textField.Font        = CocoaHelpers.GetNSFont(controlVariant);

            return(new View(textField));
        }
Пример #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));
        }
Пример #3
0
 public static string GetNSTextAlignmentString(FigmaText text)
 {
     return($"{nameof(NSTextAlignment)}.{CocoaHelpers.GetNSTextAlignment(text)}");
 }