コード例 #1
0
        protected override void OnGetPartialDesignerClass(FigmaPartialDesignerClass partialDesignerClass, CodeRenderService codeRendererService, bool translateLabels)
        {
            if (FigmaNode == null)
            {
                return;
            }

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

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

            builder.WritePropertyEquality(Members.This, nameof(AppKit.NSView.TranslatesAutoresizingMaskIntoConstraints), false);

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

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

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

            partialDesignerClass.InitializeComponentContent = builder.ToString();
        }
コード例 #2
0
ファイル: ViewController.cs プロジェクト: kblok/FigmaSharp
        void OutlinePanel_RaiseFirstResponder(object sender, FigmaNode e)
        {
            codeRenderer.Clear();
            currentSelectedNode = e;
            var builder = new StringBuilder();
            var options = new CodeRenderServiceOptions()
            {
                TranslateLabels = openUrlButton.State == NSCellStateValue.On
            };

            codeRenderer.GetCode(builder, new CodeNode(e, null), null, options);
            CopyToLogView(builder.ToString());
        }
コード例 #3
0
        protected override void OnGetPartialDesignerClass(FigmaPartialDesignerClass partialDesignerClass, CodeRenderService 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 CodeRenderServiceOptions()
            {
                TranslateLabels = translateLabels
            };

            codeRendererService.GetCode(builder, new CodeNode(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)
                                                 ));
            }
        }