Exemplo n.º 1
0
        //internal void SaveViews (FigmaCodeRendererService codeRendererService, bool writePublicClassIfExists = true, bool translateLabels = false)
        //{
        //	SaveViews(codeRendererService, writePublicClassIfExists, translateLabels, Views.ToArray ());
        //}

        public void SaveViews(CodeRenderService codeRendererService, bool writePublicClassIfExists, bool translateLabels, params FigmaBundleViewBase[] Views)
        {
            foreach (var view in Views)
            {
                view.Generate(codeRendererService, writePublicClassIfExists, translateStrings: translateLabels);
            }
        }
Exemplo n.º 2
0
        public void GeneratePartialDesignerClass(CodeRenderService codeRendererService, string directoryPath, string namesSpace = null, bool translateStrings = false)
        {
            var partialDesignerClass = GetFigmaPartialDesignerClass(codeRendererService, namesSpace, translateStrings);

            var partialDesignerClassFilePath = Path.Combine(directoryPath, PartialDesignerClassName);

            partialDesignerClass.Save(partialDesignerClassFilePath);
        }
Exemplo n.º 3
0
        public void Generate(string directoryPath, CodeRenderService codeRendererService, bool writePublicClassIfExists = true, string namesSpace = null, bool translateStrings = false)
        {
            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }

            GeneratePartialDesignerClass(codeRendererService, directoryPath, namesSpace, translateStrings);
            GeneratePublicPartialClass(directoryPath, writePublicClassIfExists);
        }
Exemplo n.º 4
0
        public override void Init()
        {
            base.Init();
            converters = FigmaControlsContext.Current.GetConverters(true);

            provider = new ControlRemoteNodeProvider();
            provider.Load("6AMAixZCkmIrezBY7W7jKU");

            propertyConfigure = new CodePropertyConfigure();
            service           = new CodeRenderService(provider, converters, propertyConfigure);
        }
Exemplo n.º 5
0
        public ShowContentMethodCodeObject(List <FigmaFrame> figmaFrames, string name, string contentViewName, string enumTypeName, CodeNode parentNode, CodeRenderService figmaRendererService) : base(name)
        {
            MethodModifier      = CodeObjectModifierType.Public;
            argumentName        = "content";
            selectedContentName = "SelectedContent";
            figmaFrameEntities  = figmaFrames;

            this.rendererService = figmaRendererService;
            this.parentNode      = parentNode;
            this.contentViewName = contentViewName;
            this.enumTypeName    = enumTypeName;
        }
Exemplo n.º 6
0
        public override string ConvertToCode(CodeNode codeNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            var code = new StringBuilder();

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

            code.WritePropertyEquality(codeNode.Name, nameof(NSView.TranslatesAutoresizingMaskIntoConstraints), false);

            ConfigureCodeProperty(Properties.EdgeInsets, codeNode, code);
            ConfigureCodeProperty(Properties.Spacing, codeNode, code);
            ConfigureCodeProperty(Properties.Orientation, codeNode, code);
            ConfigureCodeProperty(Properties.Distribution, codeNode, code);

            return(code.ToString());
        }
Exemplo n.º 7
0
        public FigmaPartialDesignerClass GetFigmaPartialDesignerClass(CodeRenderService codeRendererService, string namesSpace = null, bool translateStrings = false)
        {
            var partialDesignerClass = new FigmaPartialDesignerClass();

            partialDesignerClass.Manifest = new FigmaManifest()
            {
                Date             = DateTime.Now,
                FileId           = bundle.FileId,
                DocumentVersion  = "0.1f",
                Namespace        = namesSpace ?? FigmaBundle.DefaultNamespace,
                RemoteApiVersion = AppContext.Api.Version.ToString(),
                ApiVersion       = AppContext.Current.Version
            };

            partialDesignerClass.ClassName = Name;
            partialDesignerClass.Namespace = bundle.Namespace;

            OnGetPartialDesignerClass(partialDesignerClass, codeRendererService, translateStrings);

            return(partialDesignerClass);
        }
Exemplo n.º 8
0
        void RefreshTree(string docId)
        {
            var converters = FigmaControlsContext.Current.GetConverters();

            fileProvider = new ControlRemoteNodeProvider();
            fileProvider.Load(docId);

            if (fileProvider.Response == null)
            {
                return;
            }

            var codePropertyConverter = FigmaControlsContext.Current.GetCodePropertyConverter();

            codeRenderer = new NativeViewCodeService(fileProvider, converters, codePropertyConverter, translationService);



            data = new FigmaNodeView(fileProvider.Response.document);
            figmaDelegate.ConvertToNodes(fileProvider.Response.document, data);
            outlinePanel.GenerateTree(data);

            ((NSTextView)logTextField.DocumentView).Value = string.Empty;
        }
Exemplo n.º 9
0
        public static bool IsParentDialog(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            if (currentNode.Node.Parent.TryGetWindowLinkedContentNode(rendererService.figmaProvider, out var nativeWindow) &&
                nativeWindow.IsDialog())
            {
                return(true);
            }

            if (currentNode.Node.Parent.TryGetLinkedWindowNode(rendererService.figmaProvider, out var figmaInstance) &&
                figmaInstance.IsDialog())
            {
                if (currentNode.Node.Parent.IsWindowContent())
                {
                    return(true);
                }
            }

            if (currentNode.Node.Parent.IsDialogParentContainer())
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 10
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));
            }

            FigmaNode optionsGroup = frame.Options();

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

            if (passwordNode != null)
            {
                code.WritePropertyEquality(name, nameof(NSSecureTextField.StringValue), ComponentString.PASSWORD, inQuotes: true);
            }

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

            if (placeholderText != null && !placeholderText.characters.Equals(ComponentString.PLACEHOLDER, StringComparison.InvariantCultureIgnoreCase))
            {
                code.WriteTranslatedEquality(name, nameof(NSTextField.PlaceholderString), placeholderText, rendererService);
            }

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

            if (text != null)
            {
                code.WritePropertyEquality(name, nameof(NSTextField.Font), CodeHelper.GetNSFontString(controlVariant, text, withWeight: false));
                code.WriteTranslatedEquality(name, nameof(NSTextField.StringValue), text, rendererService);
            }

            return(code);
        }
Exemplo n.º 11
0
        public override string ConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            StringBuilder builder = new StringBuilder();

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

            builder.Configure(currentNode.Node, currentNode.Name);

            builder.AppendLine(string.Format("{0}.{1} = {2};", currentNode.Name, nameof(NSBox.BoxType), NSBoxType.NSBoxSeparator.GetFullName()));

            return(builder.ToString());
        }
Exemplo n.º 12
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));
            }

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

            if (text == null)
            {
                return(null);
            }

            code.WritePropertyEquality(name, nameof(NSTextField.Editable), false);
            code.WritePropertyEquality(name, nameof(NSTextField.Bordered), false);
            code.WritePropertyEquality(name, nameof(NSTextField.DrawsBackground), false);
            code.WritePropertyEquality(name, nameof(NSTextField.PreferredMaxLayoutWidth), "1");

            code.WriteTranslatedEquality(name, nameof(NSTextField.StringValue), text, rendererService);

            if (text != null)
            {
                code.WritePropertyEquality(name, nameof(NSTextField.Alignment), CodeHelper.GetNSTextAlignmentString(text).ToString());
            }

            if (controlType == FigmaControlType.LabelHeader)
            {
                code.WritePropertyEquality(name, nameof(NSTextField.Font),
                                           $"{ typeof(NSFont) }.{ nameof(NSFont.SystemFontOfSize) }({ headerFontSize }, { CodeHelper.GetNSFontWeightString(text) })");
            }
            else
            {
                code.WritePropertyEquality(name, nameof(NSTextField.Font), CodeHelper.GetNSFontString(controlVariant, text));
            }

            foreach (var styleMap in text?.styles)
            {
                if ((rendererService.NodeProvider as NodeProvider).TryGetStyle(styleMap.Value, out FigmaStyle style))
                {
                    if (styleMap.Key == "fill")
                    {
                        code.WritePropertyEquality(name, nameof(NSTextField.TextColor), ColorService.GetNSColorString(style.name));
                    }
                }
            }

            return(code);
        }
Exemplo n.º 13
0
        protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            var code = new StringBuilder();

            // TODO: Get name from generator
            var    name         = currentNode.Name + "ScrollView";
            string textViewName = currentNode.Name;

            currentNode.Name = name;

            var frame = (FigmaFrame)currentNode.Node;

            frame.TryGetNativeControlVariant(out var controlVariant);

            code.WriteConstructor(name, typeof(NSScrollView));
            code.WritePropertyEquality(name, nameof(NSScrollView.BorderType), NSBorderType.LineBorder.GetFullName());
            code.WritePropertyEquality(name, nameof(NSScrollView.HasHorizontalRuler), false);
            code.WritePropertyEquality(name, nameof(NSScrollView.HasVerticalScroller), true);

            code.AppendLine();

            if (rendererService.NeedsRenderConstructor(currentNode, parentNode))
            {
                code.WriteConstructor(textViewName, typeof(NSTextView), rendererService.NodeRendersVar(currentNode, parentNode));
            }

            code.WritePropertyEquality(textViewName,
                                       nameof(NSTextView.Frame),
                                       string.Format("new {0} ({1}, {2}, {3}, {4})",
                                                     typeof(CoreGraphics.CGRect), 0, 0, name + ".ContentSize.Width", name + ".ContentSize.Height"));

            code.WritePropertyEquality(textViewName, nameof(NSTextView.AutoresizingMask), NSViewResizingMask.WidthSizable.GetFullName());

            // TODO: Use CocoaConverter methods
            switch (controlVariant)
            {
            case NativeControlVariant.Regular:
                code.WritePropertyEquality(textViewName, nameof(NSTextView.Font), Members.Font.SystemFontOfSize(Members.Font.SystemFontSize));
                break;

            case NativeControlVariant.Small:
                code.WritePropertyEquality(textViewName, nameof(NSTextView.Font), Members.Font.SystemFontOfSize(Members.Font.SmallSystemFontSize));
                break;
            }

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

            if (text != null)
            {
                code.WriteTranslatedEquality(textViewName, nameof(NSTextView.Value), text.characters, rendererService, textCondition: text.visible);
            }

            code.AppendLine();
            code.WritePropertyEquality(name, nameof(NSScrollView.DocumentView), textViewName);

            return(code);
        }
Exemplo n.º 14
0
        protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            StringBuilder code = base.OnConvertToCode(currentNode, parentNode, rendererService);
            string        name = FigmaSharp.Resources.Ids.Conversion.NameIdentifier;

            code.WritePropertyEquality(name, nameof(NSSlider.SliderType), NSSliderType.Circular);

            return(code);
        }
Exemplo n.º 15
0
 protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
 {
     return(new StringBuilder());
 }
Exemplo n.º 16
0
        public override string ConvertToCode(string propertyName, CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            //    if (propertyName == CodeProperties.Frame)
            //    {

            //        if (currentNode.Node.Parent is FigmaCanvas)
            //            return string.Empty;

            //        if (currentNode.Node is IAbsoluteBoundingBox absoluteBounding && currentNode.Node.Parent is IAbsoluteBoundingBox parentAbsoluteBoundingBox)
            //        {
            //            var x = absoluteBounding.absoluteBoundingBox.X - parentAbsoluteBoundingBox.absoluteBoundingBox.X;

            //            var parentY = parentAbsoluteBoundingBox.absoluteBoundingBox.Y + parentAbsoluteBoundingBox.absoluteBoundingBox.Height;
            //            var actualY = absoluteBounding.absoluteBoundingBox.Y + absoluteBounding.absoluteBoundingBox.Height;
            //            var y = parentY - actualY;

            //            var rectangeConstructor = typeof(CoreGraphics.CGRect).GetConstructor(
            //new string[] {
            //                                x.ToDesignerString (),
            //                y.ToDesignerString (),
            //                                absoluteBounding.absoluteBoundingBox.Width.ToDesignerString (),
            //                                absoluteBounding.absoluteBoundingBox.Height.ToDesignerString ()
            //            });

            //            var getFrameForAlignmentRectMethod = currentNode.GetMethod(nameof(NSView.GetFrameForAlignmentRect), rectangeConstructor);
            //            currentNode.GetEquality(nameof(NSView.Frame), getFrameForAlignmentRectMethod);

            //            return currentNode.GetEquality(nameof(NSView.Frame), getFrameForAlignmentRectMethod);
            //        }
            //        return string.Empty;
            //    }
            //    if (propertyName == CodeProperties.AddChild)
            //    {
            //        return parentNode?.GetMethod(nameof(NSView.AddSubview), currentNode.Name);
            //    }
            //    if (propertyName == CodeProperties.Size)
            //    {

            //        if (currentNode.Node is IAbsoluteBoundingBox container)
            //        {

            //            if (currentNode.Node is FigmaLine line)
            //            {
            //                var width = container.absoluteBoundingBox.Width == 0 ? 1 : container.absoluteBoundingBox.Width;
            //                var height = container.absoluteBoundingBox.Height == 0 ? 1 : container.absoluteBoundingBox.Height;
            //                var size = typeof(CoreGraphics.CGSize).GetConstructor(new string[] { width.ToDesignerString(), height.ToDesignerString() });
            //                return currentNode.GetMethod(nameof(NSView.SetFrameSize), size);
            //            }

            //            var sizeConstructor = typeof(CoreGraphics.CGSize).GetConstructor(
            //             container.absoluteBoundingBox.Width.ToDesignerString(),
            //             container.absoluteBoundingBox.Height.ToDesignerString());
            //            return currentNode.GetMethod(nameof(NSView.SetFrameSize), sizeConstructor);

            //        }
            //        return string.Empty;
            //    }
            //    if (propertyName == CodeProperties.Position)
            //    {
            //        //first level has an special behaviour on positioning
            //        if (currentNode.Node.Parent is FigmaCanvas)
            //            return string.Empty;

            //        if (currentNode.Node is IAbsoluteBoundingBox absoluteBounding && currentNode.Node.Parent is IAbsoluteBoundingBox parentAbsoluteBoundingBox)
            //        {
            //            var x = absoluteBounding.absoluteBoundingBox.X - parentAbsoluteBoundingBox.absoluteBoundingBox.X;

            //            var parentY = parentAbsoluteBoundingBox.absoluteBoundingBox.Y + parentAbsoluteBoundingBox.absoluteBoundingBox.Height;
            //            var actualY = absoluteBounding.absoluteBoundingBox.Y + absoluteBounding.absoluteBoundingBox.Height;
            //            var y = parentY - actualY;

            //            if (x != default || y != default)
            //            {
            //                var pointConstructor = CodeGenerationExtensions.GetConstructor(
            //                 typeof(CoreGraphics.CGPoint),
            //                 x.ToDesignerString(),
            //                 y.ToDesignerString()
            //            );
            //                return currentNode.GetMethod(nameof(AppKit.NSView.SetFrameOrigin), pointConstructor);
            //            }
            //        }
            //        return string.Empty;
            //    }

            throw new System.NotImplementedException(propertyName);
        }
Exemplo n.º 17
0
 public override string ConvertToCode(CodeNode currentNode, CodeNode parent, CodeRenderService rendererService)
 {
     return($"var [NAME] = new {typeof(Entry).FullName}();");
 }
Exemplo n.º 18
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));
            }

            code.WritePropertyEquality(name, nameof(NSButton.BezelStyle), NSBezelStyle.Rounded);

            if (controlType == FigmaControlType.PopUpButtonPullDown)
            {
                code.WritePropertyEquality(name, nameof(NSPopUpButton.PullsDown), true);
            }

            code.WritePropertyEquality(name, nameof(NSButton.ControlSize), ViewHelper.GetNSControlSize(controlVariant));
            code.WritePropertyEquality(name, nameof(NSSegmentedControl.Font), CodeHelper.GetNSFontString(controlVariant));

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

            if (text != null && !string.IsNullOrEmpty(text.characters))
            {
                var stringLabel = rendererService.GetTranslatedText(text);
                code.WriteMethod(name, nameof(NSPopUpButton.AddItem), stringLabel,
                                 inQuotes: !rendererService.Options.TranslateLabels);
            }

            return(code);
        }
Exemplo n.º 19
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));
            }

            code.WritePropertyEquality(name, nameof(NSButton.ControlSize), ViewHelper.GetNSControlSize(controlVariant));

            return(code);
        }
Exemplo n.º 20
0
        public override string ConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            StringBuilder builder = new StringBuilder();

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

            builder.Configure((RectangleVector)currentNode.Node, Resources.Ids.Conversion.NameIdentifier);
            return(builder.ToString());
        }
Exemplo n.º 21
0
        public override string ConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            var           FigmaFrame = (FigmaFrame)currentNode.Node;
            StringBuilder builder    = new StringBuilder();

            var name = Resources.Ids.Conversion.NameIdentifier;

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

            builder.Configure(FigmaFrame, currentNode.Name);
            return(builder.ToString());
        }
Exemplo n.º 22
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);
        }
Exemplo n.º 23
0
 public override string ConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
 {
     return(string.Empty);
 }
Exemplo n.º 24
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));
            }

            /* TODO
             *
             * code.WriteMethod (name, nameof (NSButton.SetButtonType), NSButtonType.PushOnPushOff);
             * code.WriteEquality (name, nameof (NSButton.BezelStyle), NSBezelStyle.Disclosure);
             * code.WriteEquality (name, nameof (NSButton.Title), CodeGenerationHelpers.StringEmpty);
             * code.WriteMethod (name, nameof (NSButton.Highlight), false);
             *
             * figmaInstance.TryGetNativeControlComponentType (out var controlType);
             * switch (controlType) {
             *      case NativeControlComponentType.DisclosureTriangleStandard:
             *      case NativeControlComponentType.DisclosureTriangleStandardDark:
             *              code.WriteEquality (name, nameof (NSButton.ControlSize), NSControlSize.Regular);
             *              break;
             * }
             */
            return(code);
        }
Exemplo n.º 25
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));
            }

            code.WritePropertyEquality(name, nameof(NSButton.ControlSize), NSControlSize.Regular);

            FigmaGroup group = frame.children
                               .OfType <FigmaGroup> ()
                               .FirstOrDefault(s => s.name.In(ComponentString.STATE_ON, ComponentString.STATE_OFF) && s.visible);

            if (group != null)
            {
                if (group.name == ComponentString.STATE_ON)
                {
                    code.WritePropertyEquality(name, nameof(NSSwitch.State), "1", inQuotes: false);
                }

                if (group.name == ComponentString.STATE_OFF)
                {
                    code.WritePropertyEquality(name, nameof(NSSwitch.State), "0", inQuotes: false);
                }
            }

            return(code);
        }
Exemplo n.º 26
0
        protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            StringBuilder code = base.OnConvertToCode(currentNode, parentNode, rendererService);
            string        name = FigmaSharp.Resources.Ids.Conversion.NameIdentifier;

            code.WritePropertyEquality(name, nameof(NSProgressIndicator.Style), NSProgressIndicatorStyle.Spinning);

            return(code);
        }
Exemplo n.º 27
0
        protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            StringBuilder code = base.OnConvertToCode(currentNode, parentNode, rendererService);
            string        name = FigmaSharp.Resources.Ids.Conversion.NameIdentifier;

            var frame = (FigmaFrame)currentNode.Node;

            code.WritePropertyEquality(name, nameof(NSSlider.SliderType), NSSliderType.Linear);

            if (frame.absoluteBoundingBox.Height > frame.absoluteBoundingBox.Width)
            {
                code.WritePropertyEquality(name, nameof(NSSlider.IsVertical), "1", inQuotes: false);
            }

            return(code);
        }
Exemplo n.º 28
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;

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

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

            code.WritePropertyEquality(name, nameof(NSButton.ControlSize), ViewHelper.GetNSControlSize(controlVariant));
            code.WritePropertyEquality(name, nameof(NSSegmentedControl.Font), CodeHelper.GetNSFontString(controlVariant));

            FigmaNode items = frame.FirstChild(s => s.name == ComponentString.ITEMS);

            if (items != null)
            {
                code.WritePropertyEquality(name, nameof(NSSegmentedControl.SegmentCount), "" + items.GetChildren(t => t.visible).Count());
                code.WritePropertyEquality(name, nameof(NSSegmentedControl.SegmentDistribution), NSSegmentDistribution.FillEqually);
                code.WritePropertyEquality(name, nameof(NSSegmentedControl.SegmentStyle), NSSegmentStyle.Rounded);
                code.WritePropertyEquality(name, nameof(NSSegmentedControl.SelectedSegment), "0");
                code.WritePropertyEquality(name, nameof(NSSegmentedControl.TrackingMode), NSSegmentSwitchTracking.SelectOne);
                code.AppendLine();

                int i = 0;
                foreach (FigmaNode button in items.GetChildren(t => t.visible))
                {
                    FigmaNode state = button.FirstChild(s => s.visible &&
                                                        s.name.In(ComponentString.STATE_REGULAR, ComponentString.STATE_SELECTED));

                    if (state == null)
                    {
                        continue;
                    }

                    var text = (FigmaText)state.FirstChild(s => s.name == ComponentString.TITLE);
                    code.WriteMethod(name, nameof(NSSegmentedControl.SetLabel), $"\"{ text.characters }\", { i }");
                    i++;
                }

                code.AppendLine();
            }

            return(code);
        }
Exemplo n.º 29
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));
            }

            code.WritePropertyEquality(name, nameof(NSButton.ControlSize), ViewHelper.GetNSControlSize(controlVariant));

            code.WritePropertyEquality(name, nameof(NSProgressIndicator.MinValue), "0");
            code.WritePropertyEquality(name, nameof(NSProgressIndicator.MaxValue), "1");

            if (controlType == FigmaControlType.SliderLinear)
            {
                code.WritePropertyEquality(name, nameof(NSProgressIndicator.DoubleValue), "0.618");
            }

            FigmaGroup group = frame.children
                               .OfType <FigmaGroup>()
                               .FirstOrDefault(s => s.visible);

            if (group?.name == ComponentString.STATE_DISABLED)
            {
                code.WritePropertyEquality(name, nameof(NSSlider.Enabled), false);
            }

            return(code);
        }
Exemplo n.º 30
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));
            }

            code.WriteMethod(name, nameof(NSButton.SetButtonType), NSButtonType.Switch);

            code.WriteEquality(name, nameof(NSButton.ControlSize), ViewHelper.GetNSControlSize(controlVariant));
            code.WriteEquality(name, nameof(NSSegmentedControl.Font), CodeHelper.GetNSFontString(controlVariant));

            FigmaText text = frame.children
                             .OfType <FigmaText> ()
                             .FirstOrDefault();

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

                code.WriteEquality(name, nameof(NSButton.Title), labelTranslated,
                                   inQuotes: !rendererService.CurrentRendererOptions.TranslateLabels);
            }

            FigmaGroup group = frame.children
                               .OfType <FigmaGroup> ()
                               .FirstOrDefault(s => s.name.In(ComponentString.STATE_ON,
                                                              ComponentString.STATE_OFF,
                                                              ComponentString.STATE_MIXED) && s.visible);

            if (group != null)
            {
                if (group.name == ComponentString.STATE_ON)
                {
                    code.WriteEquality(name, nameof(NSButton.State), NSCellStateValue.On);
                }

                if (group.name == ComponentString.STATE_OFF)
                {
                    code.WriteEquality(name, nameof(NSButton.State), NSCellStateValue.Off);
                }

                if (group.name == ComponentString.STATE_MIXED)
                {
                    code.WriteEquality(name, nameof(NSButton.AllowsMixedState), true);
                    code.WriteEquality(name, nameof(NSButton.State), NSCellStateValue.Mixed);
                }
            }

            return(code);
        }