protected override StringBuilder OnConvertToCode(FigmaCodeNode currentNode, FigmaCodeNode parentNode, FigmaCodeRendererService rendererService) { StringBuilder code = base.OnConvertToCode(currentNode, parentNode, rendererService); string name = FigmaSharp.Resources.Ids.Conversion.NameIdentifier; code.WriteEquality(name, nameof(NSSlider.SliderType), NSSliderType.Circular); return(code); }
protected override StringBuilder OnConvertToCode(FigmaCodeNode currentNode, FigmaCodeNode parentNode, FigmaCodeRendererService rendererService) { var code = new StringBuilder(); string name = FigmaSharp.Resources.Ids.Conversion.NameIdentifier; var frame = (FigmaFrame)currentNode.Node; currentNode.Node.TryGetNativeControlType(out NativeControlType 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), CocoaHelpers.GetNSControlSize(controlVariant)); code.WriteEquality(name, nameof(NSProgressIndicator.MinValue), "0"); code.WriteEquality(name, nameof(NSProgressIndicator.MaxValue), "1"); if (controlType == NativeControlType.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); }
protected override StringBuilder OnConvertToCode(FigmaCodeNode currentNode, FigmaCodeNode parentNode, FigmaCodeRendererService rendererService) { var code = new StringBuilder(); string name = FigmaSharp.Resources.Ids.Conversion.NameIdentifier; var frame = (FigmaFrame)currentNode.Node; currentNode.Node.TryGetNativeControlType(out NativeControlType 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.WriteEquality(name, nameof(NSButton.ControlSize), CocoaHelpers.GetNSControlSize(controlVariant)); code.WriteEquality(name, nameof(NSSegmentedControl.Font), CocoaCodeHelpers.GetNSFontString(controlVariant)); FigmaText text = frame.children .OfType <FigmaText>() .FirstOrDefault(); if (text != null) { var labelTranslated = NativeControlHelper.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 == ComponentString.STATE_ON || s.name == ComponentString.STATE_OFF) && 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); } } return(code); }
protected override StringBuilder OnConvertToCode(FigmaCodeNode currentNode, FigmaCodeNode parentNode, FigmaCodeRendererService rendererService) { StringBuilder code = base.OnConvertToCode(currentNode, parentNode, rendererService); string name = FigmaSharp.Resources.Ids.Conversion.NameIdentifier; var frame = (FigmaFrame)currentNode.Node; code.WriteEquality(name, nameof(NSSlider.SliderType), NSSliderType.Linear); if (frame.absoluteBoundingBox.Height > frame.absoluteBoundingBox.Width) { code.WriteEquality(name, nameof(NSSlider.IsVertical), "1", inQuotes: false); } return(code); }
public override string ConvertToCode(FigmaCodeNode currentNode, FigmaCodeNode parentNode, FigmaCodeRendererService rendererService) { return(string.Empty); }
public ShowContentMethodCodeObject(List <FigmaFrame> figmaFrames, string name, string contentViewName, string enumTypeName, FigmaCodeNode parentNode, FigmaCodeRendererService figmaRendererService) : base(name) { MethodModifier = CodeObjectModifier.Public; argumentName = "content"; selectedContentName = "SelectedContent"; figmaFrameEntities = figmaFrames; this.rendererService = figmaRendererService; this.parentNode = parentNode; this.contentViewName = contentViewName; this.enumTypeName = enumTypeName; }
protected override StringBuilder OnConvertToCode(FigmaCodeNode currentNode, FigmaCodeNode parentNode, FigmaCodeRendererService rendererService) { var code = new StringBuilder(); string name = FigmaSharp.Resources.Ids.Conversion.NameIdentifier; var frame = (FigmaFrame)currentNode.Node; currentNode.Node.TryGetNativeControlType(out NativeControlType 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), CocoaHelpers.GetNSControlSize(controlVariant)); return(code); }
public override string ConvertToCode(FigmaCodeNode currentNode, FigmaCodeNode parentNode, FigmaCodeRendererService 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}.BoxType = {1};", currentNode.Name, NSBoxType.NSBoxSeparator.GetFullName())); return(builder.ToString()); }
public override string ConvertToCode(FigmaNode currentNode, FigmaCodeRendererService rendererService) { return("var [NAME] = new Button();"); }
protected override StringBuilder OnConvertToCode(FigmaCodeNode currentNode, FigmaCodeNode parentNode, FigmaCodeRendererService rendererService) { var code = new StringBuilder(); string name = FigmaSharp.Resources.Ids.Conversion.NameIdentifier; var frame = (FigmaFrame)currentNode.Node; currentNode.Node.TryGetNativeControlType(out NativeControlType controlType); currentNode.Node.TryGetNativeControlVariant(out NativeControlVariant controlVariant); if (rendererService.NeedsRenderConstructor(currentNode, parentNode)) { code.WriteConstructor(name, GetControlType(currentNode.Node), rendererService.NodeRendersVar(currentNode, parentNode)); } if (controlType == NativeControlType.Separator) { code.WriteEquality(name, nameof(NSBox.BoxType), NSBoxType.NSBoxSeparator); } if (controlType == NativeControlType.BoxCustom) { code.WriteEquality(name, nameof(NSBox.BoxType), NSBoxType.NSBoxCustom); bool borderSet = false; FigmaVectorEntity rectangle = frame.children .OfType <FigmaVectorEntity>() .FirstOrDefault(); foreach (var styleMap in rectangle?.styles) { if ((rendererService.figmaProvider as FigmaFileProvider).TryGetStyle(styleMap.Value, out FigmaStyle style)) { if (styleMap.Key == "fill") { code.WriteEquality(name, nameof(NSBox.FillColor), CocoaCodeHelpers.GetNSColorString(style.name)); } if (styleMap.Key == "stroke") { code.WriteEquality(name, nameof(NSBox.BorderColor), CocoaCodeHelpers.GetNSColorString(style.name)); code.WriteEquality(name, nameof(NSBox.BorderWidth), rectangle.strokeWeight.ToString()); borderSet = true; } } } if (!borderSet) { code.WriteEquality(name, nameof(NSBox.BorderWidth), "0"); } } FigmaText text = frame.children .OfType <FigmaText>() .FirstOrDefault(s => (s.name == ComponentString.TITLE && s.visible)); if (text != null) { string stringTitle = NativeControlHelper.GetTranslatableString(text.characters, rendererService.CurrentRendererOptions.TranslateLabels); code.WriteEquality(name, nameof(NSBox.Title), stringTitle, inQuotes: !rendererService.CurrentRendererOptions.TranslateLabels); } else { code.WriteEquality(name, nameof(NSBox.Title), "", inQuotes: true); } return(code); }
public void Generate(FigmaCodeRendererService codeRendererService, bool writePublicClassIfExists = true, string namesSpace = null, bool translateStrings = false) { Generate(bundle.ViewsDirectoryPath, codeRendererService, writePublicClassIfExists, namesSpace, translateStrings); }
protected abstract void OnGetPartialDesignerClass(FigmaPartialDesignerClass partialDesignerClass, FigmaCodeRendererService codeRendererService, bool translateStrings);
protected override StringBuilder OnConvertToCode(FigmaCodeNode currentNode, FigmaCodeNode parentNode, FigmaCodeRendererService rendererService) { var code = new StringBuilder(); string name = FigmaSharp.Resources.Ids.Conversion.NameIdentifier; var frame = (FigmaFrame)currentNode.Node; currentNode.Node.TryGetNativeControlType(out NativeControlType 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.WriteEquality(name, nameof(NSTextField.Editable), false); code.WriteEquality(name, nameof(NSTextField.Bordered), false); code.WriteEquality(name, nameof(NSTextField.DrawsBackground), false); code.WriteEquality(name, nameof(NSTextField.PreferredMaxLayoutWidth), "1"); var labelComponent = NativeControlHelper.GetTranslatableString(text.characters, rendererService.CurrentRendererOptions.TranslateLabels); code.WriteEquality(name, nameof(NSTextField.StringValue), labelComponent, inQuotes: !rendererService.CurrentRendererOptions.TranslateLabels); if (text != null) { code.WriteEquality(name, nameof(NSTextField.Alignment), CocoaCodeHelpers.GetNSTextAlignmentString(text).ToString()); } if (controlType == NativeControlType.LabelHeader) { code.WriteEquality(name, nameof(NSTextField.Font), $"{ typeof(NSFont) }.{ nameof(NSFont.SystemFontOfSize) }({ headerFontSize }, { CocoaCodeHelpers.GetNSFontWeightString(text) })"); } else { code.WriteEquality(name, nameof(NSTextField.Font), CocoaCodeHelpers.GetNSFontString(controlVariant, text)); } foreach (var styleMap in text?.styles) { if ((rendererService.figmaProvider as FigmaFileProvider).TryGetStyle(styleMap.Value, out FigmaStyle style)) { if (styleMap.Key == "fill") { code.WriteEquality(name, nameof(NSTextField.TextColor), CocoaCodeHelpers.GetNSColorString(style.name)); } } } return(code); }
protected override StringBuilder OnConvertToCode(FigmaCodeNode currentNode, FigmaCodeNode parentNode, FigmaCodeRendererService 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.WriteEquality(name, nameof(NSButton.ControlSize), CocoaHelpers.GetNSControlSize(controlVariant)); code.WriteEquality(name, nameof(NSSegmentedControl.Font), CocoaCodeHelpers.GetNSFontString(controlVariant)); FigmaNode items = frame.FirstChild(s => s.name == ComponentString.ITEMS); if (items != null) { code.WriteEquality(name, nameof(NSSegmentedControl.SegmentCount), "" + items.GetChildren(t => t.visible).Count()); code.WriteEquality(name, nameof(NSSegmentedControl.SegmentDistribution), NSSegmentDistribution.FillEqually); code.WriteEquality(name, nameof(NSSegmentedControl.SegmentStyle), NSSegmentStyle.Rounded); code.WriteEquality(name, nameof(NSSegmentedControl.SelectedSegment), "0"); code.WriteEquality(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); }
public override string ConvertToCode(FigmaNode currentNode, FigmaCodeRendererService rendererService) => string.Empty;
protected override StringBuilder OnConvertToCode(FigmaCodeNode currentNode, FigmaCodeNode parentNode, FigmaCodeRendererService rendererService) { return(new StringBuilder()); }
protected override StringBuilder OnConvertToCode(FigmaCodeNode currentNode, FigmaCodeNode parentNode, FigmaCodeRendererService 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 abstract string ConvertToCode(FigmaNode currentNode, FigmaCodeRendererService rendererService);
public override string ConvertToCode(FigmaCodeNode currentNode, FigmaCodeNode parentNode, FigmaCodeRendererService rendererService) { var builder = new StringBuilder(); if (rendererService.NeedsRenderConstructor(currentNode, parentNode)) { builder.WriteConstructor(currentNode.Name, GetControlType(currentNode.Node), rendererService.NodeRendersVar(currentNode, parentNode)); } builder.Configure((FigmaVectorEntity)currentNode.Node, Resources.Ids.Conversion.NameIdentifier); return(builder.ToString()); }
protected override StringBuilder OnConvertToCode(FigmaCodeNode currentNode, FigmaCodeNode parentNode, FigmaCodeRendererService rendererService) { StringBuilder code = base.OnConvertToCode(currentNode, parentNode, rendererService); string name = FigmaSharp.Resources.Ids.Conversion.NameIdentifier; code.WriteEquality(name, nameof(NSProgressIndicator.Style), NSProgressIndicatorStyle.Spinning); return(code); }
public override string ConvertToCode(string propertyName, FigmaCodeNode currentNode, FigmaCodeNode parentNode, FigmaCodeRendererService 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); }