protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService 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); }
protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService 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 (((NodeProvider)rendererService.NodeProvider).TryGetStyle(styleMap.Value, out FigmaStyle style)) { if (styleMap.Key == "fill") { code.WritePropertyEquality(name, nameof(NSColorWell.Color), ColorService.GetNSColorString(style.name)); } } } return(code); }
protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService 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, ICodeRenderService 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); }
protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService 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.WritePropertyEquality(name, nameof(NSButton.ControlSize), ViewHelper.GetNSControlSize(controlVariant)); code.WritePropertyEquality(name, nameof(NSButton.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.In(ComponentString.STATE_ON, ComponentString.STATE_OFF, ComponentString.STATE_MIXED) && 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); } if (group.name == ComponentString.STATE_MIXED) { code.WritePropertyEquality(name, nameof(NSButton.AllowsMixedState), true); code.WritePropertyEquality(name, nameof(NSButton.State), NSCellStateValue.Mixed); } } return(code); }
public override string ConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService 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, ICodeRenderService 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(NSComboBox.ControlSize), ViewHelper.GetNSControlSize(controlVariant)); code.WritePropertyEquality(name, nameof(NSComboBox.Font), CodeHelper.GetNSFontString(controlVariant)); FigmaNode optionsGroup = frame.Options(); 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(NSComboBox.PlaceholderString), placeholderText, rendererService); } FigmaText text = frame.children .OfType <FigmaText> () .FirstOrDefault(s => s.name == ComponentString.TITLE); if (text != null && !string.IsNullOrEmpty(text.characters)) { code.WriteTranslatedEquality(name, nameof(NSComboBox.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); }
protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService 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); }
public override string ConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService 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()); }
protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService 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); }
protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService 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, ICodeRenderService 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.WritePropertyEquality(currentNode.Name, nameof(NSImageView.Image), imageNamedMethod); return(builder); }
public override string ConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService 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()); }
public override string ConvertToCode(CodeNode codeNode, CodeNode parentNode, ICodeRenderService 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()); }
protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService 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(NSStepper.ControlSize), ViewHelper.GetNSControlSize(controlVariant)); return(code); }
protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService 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(NSProgressIndicator.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); }
protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService 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)); } FigmaText text = frame.children .OfType <FigmaText>() .FirstOrDefault(s => s.name == ComponentString.SYMBOL); code.WritePropertyEquality(name, nameof(NSButton.BezelStyle), NSBezelStyle.RegularSquare); code.WritePropertyEquality(name, nameof(NSButton.Bordered), false); code.WritePropertyEquality(name, nameof(NSButton.Title), text.characters, inQuotes: true); code.WritePropertyEquality(name, nameof(NSButton.Font), $"{ typeof(NSFont) }.{ nameof(NSFont.SystemFontOfSize) }({ text.style.fontSize }, { CodeHelper.GetNSFontWeightString(text) })"); foreach (var styleMap in text.styles) { if (rendererService.NodeProvider.TryGetStyle(styleMap.Value, out FigmaStyle style)) { if (styleMap.Key == "fill") { code.WritePropertyEquality(name, nameof(NSButton.ContentTintColor), ColorService.GetNSColorString(style.name)); } } } return(code); }
public override string ConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService 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, ICodeRenderService 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(NSPopUpButton.BezelStyle), NSBezelStyle.Rounded); if (controlType == FigmaControlType.PopUpButtonPullDown) { code.WritePropertyEquality(name, nameof(NSPopUpButton.PullsDown), true); } code.WritePropertyEquality(name, nameof(NSPopUpButton.ControlSize), ViewHelper.GetNSControlSize(controlVariant)); code.WritePropertyEquality(name, nameof(NSPopUpButton.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); }
protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService rendererService) { var code = new StringBuilder(); string name = 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(NSSlider.ControlSize), ViewHelper.GetNSControlSize(controlVariant)); code.WritePropertyEquality(name, nameof(NSSlider.MinValue), "0"); code.WritePropertyEquality(name, nameof(NSSlider.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); }
protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService rendererService) { var code = new StringBuilder(); string name = FigmaSharp.Resources.Ids.Conversion.NameIdentifier; if (rendererService.NeedsRenderConstructor(currentNode, parentNode)) { code.WriteConstructor(name, GetControlType(currentNode.Node), rendererService.NodeRendersVar(currentNode, parentNode)); } var frame = (FigmaFrame)currentNode.Node; frame.TryGetNodeCustomName(out string iconName); code.WritePropertyEquality(name, nameof(NSImageView.Image), $"{ typeof(NSImage) }.{ nameof(NSImage.ImageNamed) }(\"{ iconName }\")"); code.WritePropertyEquality(name, nameof(NSImageView.ImageScaling), NSImageScale.ProportionallyUpOrDown); code.WritePropertyEquality(name, $"{ nameof(NSImageView.Image) }.{ nameof(NSImageView.Image.Size) }", $"new { typeof(CGSize) }({ frame.absoluteBoundingBox.Width }, { frame.absoluteBoundingBox.Height })"); return(code); }
protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService 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(NSSwitch.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, ICodeRenderService rendererService) { var code = new StringBuilder(); // TODO: Get name from generator var name = currentNode.Name + "ScrollView"; string tableViewName = currentNode.Name; currentNode.Name = name; var frame = (FigmaFrame)currentNode.Node; code.WriteConstructor(name, typeof(NSScrollView)); code.WritePropertyEquality(name, nameof(NSScrollView.AutoresizingMask), $"{nameof(NSViewResizingMask)}.{nameof(NSViewResizingMask.WidthSizable)} | " + $"{nameof(NSViewResizingMask)}.{nameof(NSViewResizingMask.HeightSizable)}"); code.WritePropertyEquality(name, nameof(NSScrollView.BorderType), NSBorderType.BezelBorder); code.WritePropertyEquality(name, nameof(NSScrollView.DrawsBackground), true); code.AppendLine(); if (rendererService.NeedsRenderConstructor(currentNode, parentNode)) { code.WriteConstructor(tableViewName, typeof(NSTableView), rendererService.NodeRendersVar(currentNode, parentNode)); } code.WritePropertyEquality(tableViewName, nameof(NSTableView.Frame), string.Format("new {0} ({1}, {2}, {3}, {4})", typeof(CoreGraphics.CGRect), 0, 0, name + ".ContentSize.Width", name + ".ContentSize.Height")); var columnNodes = frame.FirstChild(s => s.name == ComponentString.COLUMNS && s.visible); // TODO: Parse options layers code.WritePropertyEquality(tableViewName, nameof(NSTableView.UsesAlternatingRowBackgroundColors), false); code.WritePropertyEquality(tableViewName, nameof(NSTableView.AllowsMultipleSelection), false); code.WritePropertyEquality(tableViewName, nameof(NSTableView.AllowsColumnResizing), true); code.WritePropertyEquality(tableViewName, nameof(NSTableView.AllowsColumnReordering), false); code.WritePropertyEquality(tableViewName, nameof(NSTableView.AllowsEmptySelection), false); code.AppendLine(); int columnCount = 1; foreach (FigmaNode tableColumNode in columnNodes.GetChildren(t => t.visible)) { FigmaText text = tableColumNode.FirstChild(s => s.name == ComponentString.TITLE) as FigmaText; if (text == null) { continue; } string columnId = "TableColumn" + columnCount; code.WriteConstructor(columnId, typeof(NSTableColumn)); code.WritePropertyEquality(columnId, $"{nameof(NSTableColumn.HeaderCell)}.{nameof(NSTableColumn.HeaderCell.Alignment)}", Helpers.CodeHelper.GetNSTextAlignmentString(text)); code.WritePropertyEquality(columnId, nameof(NSTableColumn.Identifier), columnId, inQuotes: true); code.WritePropertyEquality(columnId, nameof(NSTableColumn.Title), rendererService.GetTranslatedText(text), inQuotes: true); code.WritePropertyEquality(columnId, nameof(NSTableColumn.Width), text.absoluteBoundingBox.Width.ToString(), inQuotes: false); code.WriteMethod(tableViewName, nameof(NSTableView.AddColumn), columnId); code.AppendLine(); columnCount++; } code.WritePropertyEquality(name, nameof(NSScrollView.DocumentView), tableViewName, inQuotes: false); code.AppendLine(); var rectangle = (RectangleVector)frame.FirstChild(s => s.name == ComponentString.BACKGROUND && s.visible); if (rectangle != null) { foreach (var styleMap in rectangle.styles) { if (rendererService.NodeProvider.TryGetStyle(styleMap.Value, out FigmaStyle style) && styleMap.Key == "fill") { code.WritePropertyEquality(tableViewName, nameof(NSTableView.BackgroundColor), ColorService.GetNSColorString(style.name)); } } } return(code); }
protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService 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.WritePropertyEquality(name, nameof(NSButton.BezelStyle), NSBezelStyle.Rounded); break; case FigmaControlType.ButtonRoundRect: code.WritePropertyEquality(name, nameof(NSButton.BezelStyle), NSBezelStyle.RoundRect); break; case FigmaControlType.ButtonHelp: code.WritePropertyEquality(name, nameof(NSButton.BezelStyle), NSBezelStyle.HelpButton); code.WritePropertyEquality(name, nameof(NSButton.Title), string.Empty, inQuotes: true); break; } code.WritePropertyEquality(name, nameof(NSButton.ControlSize), ViewHelper.GetNSControlSize(controlVariant)); code.WritePropertyEquality(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) { code.WriteTranslatedEquality(name, nameof(NSButton.Title), text, rendererService); } if (group.name == ComponentString.STATE_DISABLED) { code.WritePropertyEquality(name, nameof(NSButton.Enabled), false); } if (group.name == ComponentString.STATE_DEFAULT) { code.WritePropertyEquality(name, nameof(NSButton.KeyEquivalent), "\\r", true); } } return(code); }
protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService 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)); FigmaNode items = frame.FirstChild(s => s.name == ComponentString.ITEMS); if (items != null) { code.WritePropertyEquality(name, nameof(NSSegmentedControl.SegmentCount), "" + items.GetChildren(t => t.visible).Count()); if (controlType == FigmaControlType.SegmentedControlRoundRect) { code.WritePropertyEquality(name, nameof(NSSegmentedControl.SegmentStyle), NSSegmentStyle.RoundRect); } else { code.WritePropertyEquality(name, nameof(NSSegmentedControl.SegmentStyle), NSSegmentStyle.Rounded); } code.AppendLine(); int i = 0; bool hasSelection = false; 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 }"); if (state.name == ComponentString.STATE_SELECTED) { hasSelection = true; code.WriteMethod(name, nameof(NSSegmentedControl.SetSelected), $"{ bool.TrueString.ToLower() }, { i }"); } i++; } code.AppendLine(); // Use tab-like behaviour if there is a selected item. Otherwise use the button-like behaviour if (hasSelection) { code.WritePropertyEquality(name, nameof(NSSegmentedControl.TrackingMode), NSSegmentSwitchTracking.SelectOne); code.WritePropertyEquality(name, nameof(NSSegmentedControl.SegmentDistribution), NSSegmentDistribution.Fill); } else { code.WritePropertyEquality(name, nameof(NSSegmentedControl.TrackingMode), NSSegmentSwitchTracking.Momentary); code.WritePropertyEquality(name, nameof(NSSegmentedControl.SegmentDistribution), NSSegmentDistribution.FillEqually); } } return(code); }
protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService rendererService) { var code = new StringBuilder(); var frame = (FigmaFrame)currentNode.Node; currentNode.Node.TryGetNativeControlType(out FigmaControlType controlType); currentNode.Node.TryGetNativeControlVariant(out NativeControlVariant controlVariant); if (rendererService.NeedsRenderConstructor(currentNode, parentNode)) { code.WriteConstructor(currentNode.Name, GetControlType(currentNode.Node), rendererService.NodeRendersVar(currentNode, parentNode)); } if (controlType == FigmaControlType.Separator) { code.WritePropertyEquality(currentNode.Name, nameof(NSBox.BoxType), NSBoxType.NSBoxSeparator); } if (controlType == FigmaControlType.BoxCustom) { code.WritePropertyEquality(currentNode.Name, nameof(NSBox.BoxType), NSBoxType.NSBoxCustom); RectangleVector rectangle = frame.children .OfType <RectangleVector>() .FirstOrDefault(); if (rectangle != null) { if (rectangle.styles != null) { bool borderSet = false; foreach (var styleMap in rectangle.styles) { if ((rendererService.NodeProvider is NodeProvider nodeProvider) && nodeProvider.TryGetStyle(styleMap.Value, out FigmaStyle style)) { if (styleMap.Key == "fill") { code.WritePropertyEquality(currentNode.Name, nameof(NSBox.FillColor), ColorService.GetNSColorString(style.name)); } if (styleMap.Key == "stroke") { code.WritePropertyEquality(currentNode.Name, nameof(NSBox.BorderColor), ColorService.GetNSColorString(style.name)); code.WritePropertyEquality(currentNode.Name, nameof(NSBox.BorderWidth), rectangle.strokeWeight.ToString()); borderSet = true; } } } if (!borderSet) { code.WritePropertyEquality(currentNode.Name, nameof(NSBox.BorderWidth), "0"); } } code.WritePropertyEquality(currentNode.Name, nameof(NSBox.CornerRadius), rectangle.cornerRadius.ToString()); } } FigmaText text = null; if (frame.children != null) { text = frame.children .OfType <FigmaText>() .FirstOrDefault(s => (s.name == ComponentString.TITLE && s.visible)); } if (text != null) { code.WriteTranslatedEquality(currentNode.Name, nameof(NSBox.Title), text.characters, rendererService); } else { code.WritePropertyEquality(currentNode.Name, nameof(NSBox.Title), string.Empty, inQuotes: true); } return(code); }