Example #1
0
        protected override void OnGetPartialDesignerClass(FigmaPartialDesignerClass partialDesignerClass, FigmaCodeRendererService codeRendererService, bool translateLabels)
        {
            if (FigmaNode == null)
            {
                return;
            }

            partialDesignerClass.Usings.Add(nameof(AppKit));

            //restore this state
            var builder = new System.Text.StringBuilder();

            builder.WriteEquality(CodeGenerationHelpers.This, nameof(AppKit.NSView.TranslatesAutoresizingMaskIntoConstraints), false);

            var options = new FigmaCodeRendererServiceOptions()
            {
                TranslateLabels = translateLabels
            };

            codeRendererService.GetCode(builder, new FigmaCodeNode(FigmaNode, null), null, options);

            if (codeRendererService is NativeViewCodeService nativeViewCodeService)
            {
                partialDesignerClass.PrivateMembers.Clear();
                partialDesignerClass.PrivateMembers.AddRange(nativeViewCodeService.PrivateMembers);
            }

            partialDesignerClass.InitializeComponentContent = builder.ToString();
        }
Example #2
0
        public FigmaPartialDesignerClass GetFigmaPartialDesignerClass(CodeRenderService codeRendererService, string namesSpace = null, bool translateStrings = false)
        {
            var partialDesignerClass = new FigmaPartialDesignerClass();

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

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

            OnGetPartialDesignerClass(partialDesignerClass, codeRendererService, translateStrings);

            return(partialDesignerClass);
        }
Example #3
0
        protected override void OnGetPartialDesignerClass(FigmaPartialDesignerClass partialDesignerClass, FigmaCodeRendererService codeRendererService, bool translateLabels)
        {
            if (FigmaNode == null)
            {
                return;
            }

            partialDesignerClass.Usings.Add(nameof(AppKit));

            //restore this state
            var builder = new System.Text.StringBuilder();
            //builder.AppendLine ("//HACK: Temporal Window Frame Size");

            bool centers = false;

            var windowComponent = FigmaNode.GetDialogInstanceFromParentContainer();

            if (windowComponent != null)
            {
                if (windowComponent.Options() is IFigmaNodeContainer figmaNodeContainer)
                {
                    var title = ((FigmaNode)figmaNodeContainer)
                                .FirstChild(s => s.name == "title" && s.visible) as FigmaText;

                    if (title != null)
                    {
                        builder.WriteEquality(CodeGenerationHelpers.This, nameof(AppKit.NSWindow.Title), title.characters ?? "", inQuotes: true);
                    }

                    if (figmaNodeContainer.HasChildrenVisible("resize"))
                    {
                        builder.AppendLine(string.Format("{0}.{1} |= {2};",
                                                         CodeGenerationHelpers.This,
                                                         nameof(AppKit.NSWindow.StyleMask),
                                                         AppKit.NSWindowStyle.Resizable.GetFullName()
                                                         ));
                    }

                    if (figmaNodeContainer.HasChildrenVisible("close"))
                    {
                        builder.AppendLine(string.Format("{0}.{1} |= {2};",
                                                         CodeGenerationHelpers.This,
                                                         nameof(AppKit.NSWindow.StyleMask),
                                                         AppKit.NSWindowStyle.Closable.GetFullName()
                                                         ));
                    }

                    if (figmaNodeContainer.HasChildrenVisible("min"))
                    {
                        builder.AppendLine(string.Format("{0}.{1} |= {2};",
                                                         CodeGenerationHelpers.This,
                                                         nameof(AppKit.NSWindow.StyleMask),
                                                         AppKit.NSWindowStyle.Miniaturizable.GetFullName()
                                                         ));
                    }

                    if (figmaNodeContainer.HasChildrenVisible("max") == false)
                    {
                        builder.AppendLine(string.Format("{0}.{1} ({2}).{3} = {4};",
                                                         CodeGenerationHelpers.This,
                                                         nameof(NSWindow.StandardWindowButton),
                                                         NSWindowButton.ZoomButton.GetFullName(),
                                                         nameof(NSControl.Enabled),
                                                         bool.FalseString.ToLower()
                                                         ));
                    }
                }
            }

            //Window Frame
            if (FigmaNode is IAbsoluteBoundingBox box && box.absoluteBoundingBox != null)
            {
                builder.AppendLine();
                builder.WriteEquality(frameEntity, null, nameof(AppKit.NSWindow.Frame), instanciate: true);

                string instance = typeof(CoreGraphics.CGSize).
                                  GetConstructor(new string[] {
                    box.absoluteBoundingBox.Width.ToDesignerString(),
                    box.absoluteBoundingBox.Height.ToDesignerString()
                });
                builder.WriteEquality(frameEntity, nameof(AppKit.NSWindow.Frame.Size), instance, instanciate: false);

                string parameters = $"{frameEntity}, {true.ToDesignerString ()}";

                builder.WriteMethod(CodeGenerationHelpers.This, nameof(AppKit.NSWindow.SetFrame), parameters);
                builder.WriteEquality(CodeGenerationHelpers.This, nameof(AppKit.NSWindow.ContentMinSize), "this.ContentView.Frame.Size");
            }

            var options = new FigmaCodeRendererServiceOptions()
            {
                TranslateLabels = translateLabels
            };

            codeRendererService.GetCode(builder, new FigmaCodeNode(FigmaNode, null), null, options);
            partialDesignerClass.InitializeComponentContent = builder.ToString();

            if (codeRendererService is NativeViewCodeService nativeViewCodeService)
            {
                partialDesignerClass.PrivateMembers.Clear();
                partialDesignerClass.PrivateMembers.AddRange(nativeViewCodeService.PrivateMembers);
            }

            if (centers)
            {
                builder.AppendLine(string.Format("{0}.{1}();",
                                                 CodeGenerationHelpers.This,
                                                 nameof(AppKit.NSWindow.Center)
                                                 ));
            }
        }
Example #4
0
 protected abstract void OnGetPartialDesignerClass(FigmaPartialDesignerClass partialDesignerClass, CodeRenderService codeRendererService, bool translateStrings);