Exemple #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));
            }

            /* 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);
        }
Exemple #2
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);
        }
        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);
        }
Exemple #4
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);
        }
        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.WriteEquality(name, nameof(NSScrollView.BorderType), NSBorderType.LineBorder.GetFullName());
            code.WriteEquality(name, nameof(NSScrollView.HasHorizontalRuler), false);
            code.WriteEquality(name, nameof(NSScrollView.HasVerticalScroller), true);

            code.AppendLine();

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

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

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

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

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

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

            if (text != null)
            {
                var stringLabel = CodeHelper.GetTranslatableString(text.characters, rendererService.CurrentRendererOptions.TranslateLabels);
                code.WriteEquality(textViewName, nameof(NSTextView.Value), stringLabel, inQuotes: !rendererService.CurrentRendererOptions.TranslateLabels);
            }

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

            return(code);
        }
Exemple #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).FullName, rendererService.NodeRendersVar(currentNode, parentNode));
            }

            switch (controlType)
            {
            case FigmaControlType.Button:
                code.WriteEquality(name, nameof(NSButton.BezelStyle), NSBezelStyle.Rounded);
                break;

            case FigmaControlType.ButtonHelp:
                code.WriteEquality(name, nameof(NSButton.BezelStyle), NSBezelStyle.HelpButton);
                code.WriteEquality(name, nameof(NSButton.Title), string.Empty, inQuotes: true);
                break;
            }

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

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

            if (group != null)
            {
                FigmaText text = group.children
                                 .OfType <FigmaText> ()
                                 .FirstOrDefault(s => s.name == ComponentString.TITLE);

                if (text != null && controlType != FigmaControlType.ButtonHelp)
                {
                    string labelTranslated = CodeHelper.GetTranslatableString(text.characters, rendererService.CurrentRendererOptions.TranslateLabels);
                    code.WriteEquality(name, nameof(NSButton.Title), labelTranslated, inQuotes: !rendererService.CurrentRendererOptions.TranslateLabels);
                }

                if (group.name == ComponentString.STATE_DISABLED)
                {
                    code.WriteEquality(name, nameof(NSButton.Enabled), false);
                }

                if (group.name == ComponentString.STATE_DEFAULT)
                {
                    code.WriteEquality(name, nameof(NSButton.KeyEquivalent), "\\r", true);
                }
            }

            return(code);
        }
Exemple #7
0
        public override string ConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            var builder = new StringBuilder();

            if (rendererService.NeedsRenderConstructor(currentNode, parentNode))
            {
                builder.WriteConstructor(currentNode.Name, GetControlType(currentNode.Node), rendererService.NodeRendersVar(currentNode, parentNode));
            }
            builder.Configure((FigmaVector)currentNode.Node, Resources.Ids.Conversion.NameIdentifier);
            return(builder.ToString());
        }
		protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
		{
			var builder = new StringBuilder ();

			var type = GetControlType(currentNode.Node);
			if (type != null) {
				if (rendererService.NeedsRenderConstructor(currentNode, parentNode))
					builder.WriteConstructor(currentNode.Name, type, !currentNode.Node.TryGetNodeCustomName(out var _));
			}

			return builder;
		}
        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);
        }
        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.WriteEquality(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))
            {
                var stringLabel = CodeHelper.GetTranslatableString(placeholderText.characters, rendererService.CurrentRendererOptions.TranslateLabels);
                code.WriteEquality(name, nameof(NSTextField.PlaceholderString), stringLabel, true);
            }

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

            if (text != null)
            {
                code.WriteEquality(name, nameof(NSTextField.Font), CodeHelper.GetNSFontString(controlVariant, text, withWeight: false));

                var stringLabel = CodeHelper.GetTranslatableString(text.characters, rendererService.CurrentRendererOptions.TranslateLabels);
                code.WriteEquality(name, nameof(NSTextField.StringValue), stringLabel, inQuotes: !rendererService.CurrentRendererOptions.TranslateLabels);
            }

            return(code);
        }
Exemple #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());
        }
Exemple #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));
            }

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

            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();

            if (text != null)
            {
                code.WriteTranslatedEquality(name, nameof(NSButton.Title), text, rendererService);
            }

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

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

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

            return(code);
        }
        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));
            }

            var itemNodes = frame.FirstChild(s => s.name == ComponentString.ITEMS);

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

            code.AppendLine();
            code.AppendLine($"{ name }.{ nameof(NSTabView.SetItems) }(");
            code.AppendLine($"\tnew { typeof(NSTabViewItem[]) }");
            code.AppendLine("\t{");

            foreach (FigmaNode tabNode in itemNodes.GetChildren(t => t.visible, reverseChildren: true))
            {
                var firstChild = tabNode.FirstChild(s => s.name.In(ComponentString.STATE_REGULAR, ComponentString.STATE_SELECTED) && s.visible);

                if (firstChild != null)
                {
                    FigmaText text = firstChild.FirstChild(s => s.name == ComponentString.TITLE) as FigmaText;

                    if (text != null)
                    {
                        code.AppendLine($"\t\tnew {typeof(NSTabViewItem)}() {{ {nameof(NSTabViewItem.Label)} = \"{text.characters}\" }},");
                    }
                }
            }

            code.AppendLine("\t}");
            code.AppendLine(");");

            return(code);
        }
        protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            var builder = new StringBuilder();

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

            builder.Configure(currentNode.Node, Resources.Ids.Conversion.NameIdentifier);
            currentNode.Node.TryGetNodeCustomName(out string nodeName);

            var imageNamedMethod = CodeGenerationHelpers.GetMethod(typeof(NSImage).FullName, nameof(NSImage.ImageNamed), nodeName, true);

            builder.WriteEquality(currentNode.Name, nameof(NSImageView.Image), imageNamedMethod);

            return(builder);
        }
        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());
        }
Exemple #16
0
        public override string ConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            var builder = new CocoaStringBuilder();

            CreateCodeMember(
                currentNode,
                builder,
                rendererService.NeedsRenderConstructor(currentNode, parentNode),
                rendererService.NodeRendersVar(currentNode, parentNode)
                );
            ConfigureCodeProperty(Properties.Opacity, currentNode, builder);
            ConfigureCodeProperty(Properties.FillColor, currentNode, builder);
            ConfigureCodeProperty(Properties.StrokeColor, currentNode, builder);
            ConfigureCodeProperty(Properties.StrokeDashes, currentNode, builder);
            ConfigureCodeProperty(Properties.LineWidth, currentNode, builder);

            return(builder.ToString());
        }
Exemple #17
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);
        }
        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.WriteEquality(name, nameof(NSButton.BezelStyle), NSBezelStyle.Rounded);

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

            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(s => s.name == ComponentString.TITLE);

            if (text != null && !string.IsNullOrEmpty(text.characters))
            {
                var stringLabel = CodeHelper.GetTranslatableString(text.characters,
                                                                   rendererService.CurrentRendererOptions.TranslateLabels);

                code.WriteMethod(name, nameof(NSPopUpButton.AddItem), stringLabel,
                                 inQuotes: !rendererService.CurrentRendererOptions.TranslateLabels);
            }

            return(code);
        }
Exemple #19
0
        public override string ConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            var figmaText = (FigmaText)currentNode.Node;

            StringBuilder builder = new StringBuilder();

            if (rendererService.NeedsRenderConstructor(currentNode, parentNode))
            {
                builder.WritePropertyEquality(currentNode.Name, null, FigmaExtensions.CreateLabelToDesignerString(figmaText.characters), instanciate: true);
            }

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

            var alignment = FigmaExtensions.ToNSTextAlignment(figmaText.style.textAlignHorizontal);

            if (alignment != default)
            {
                builder.WritePropertyEquality(currentNode.Name, nameof(AppKit.NSTextField.Alignment), alignment);
            }
            return(builder.ToString());
        }
        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));

            FigmaGroup group = frame.children
                               .OfType <FigmaGroup>()
                               .FirstOrDefault(s => (s.name == ComponentString.STYLE_DETERMINATE || s.name == ComponentString.STYLE_INDETERMINATE) && s.visible);

            if (group != null)
            {
                if (group.name == ComponentString.STYLE_DETERMINATE)
                {
                    code.WritePropertyEquality(name, nameof(NSProgressIndicator.Indeterminate), false);
                    code.WritePropertyEquality(name, nameof(NSProgressIndicator.MinValue), "0");
                    code.WritePropertyEquality(name, nameof(NSProgressIndicator.MaxValue), "1");
                    code.WritePropertyEquality(name, nameof(NSProgressIndicator.DoubleValue), "0.618");
                }

                if (group.name == ComponentString.STYLE_INDETERMINATE)
                {
                    code.WritePropertyEquality(name, nameof(NSProgressIndicator.Indeterminate), true);
                }
            }

            return(code);
        }
Exemple #21
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(NSSegmentedControl.Font), CodeHelper.GetNSFontString(controlVariant));

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

            if (text != null && !string.IsNullOrEmpty(text.characters))
            {
                code.WriteTranslatedEquality(name, nameof(NSButton.StringValue), text, rendererService);

                //string textLabel = NativeControlHelper.GetTranslatableString(text.characters, rendererService.CurrentRendererOptions.TranslateLabels);

                //if (!rendererService.CurrentRendererOptions.TranslateLabels)
                //	textLabel = $"\"{textLabel}\"";

                //string nsstringcontructor = typeof (Foundation.NSString).GetConstructor (new[] { textLabel });
                //code.WriteMethod (name, nameof (NSComboBox.Add), nsstringcontructor);
            }

            return(code);
        }
Exemple #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));
            }

            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);
        }
        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.WriteEquality(name, nameof(NSButton.ControlSize), ViewHelper.GetNSControlSize(controlVariant));

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

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

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

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

            return(code);
        }
Exemple #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));
            }

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

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

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

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

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

                code.WritePropertyEquality(name, nameof(NSBox.CornerRadius), rectangle.cornerRadius.ToString());

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

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

            if (text != null)
            {
                code.WriteTranslatedEquality(name, nameof(NSBox.Title), text.characters, rendererService);
            }
            else
            {
                code.WritePropertyEquality(name, nameof(NSBox.Title), string.Empty, inQuotes: true);
            }

            return(code);
        }