/// <summary>
        /// Gets current FigmaNode children WITHOUT the FigmaInstance
        /// </summary>
        /// <param name="figmaNode"></param>
        /// <param name="func"></param>
        /// <param name="reverseChildren"></param>
        /// <returns></returns>
        public static IEnumerable <FigmaNode> GetChildren(this FigmaNode figmaNode, Func <FigmaNode, bool> func = null, bool reverseChildren = false)
        {
            if ((figmaNode.GetWindowContent() ?? figmaNode) is IFigmaNodeContainer container)
            {
                var figmaInstance = figmaNode.GetDialogInstanceFromParentContainer();
                IEnumerable <FigmaNode> children = container.children;
                if (reverseChildren)
                {
                    children = children.Reverse();
                }

                foreach (var item in children)
                {
                    if (item == figmaInstance)
                    {
                        continue;
                    }

                    if (func == null || (func != null && func.Invoke(item)))
                    {
                        yield return(item);
                    }
                }
            }
        }
示例#2
0
        public static FigmaInstance GetBaseComponentNode(this NodeProvider fileProvider, FigmaNode node)
        {
            var figmaInstance = node.GetDialogInstanceFromParentContainer();

            if (figmaInstance != null)
            {
                foreach (var item in fileProvider.GetMainLayers())
                {
                    var instance = item.GetDialogInstanceFromParentContainer();
                    if (instance != null && instance.id == figmaInstance.id)
                    {
                        return(instance);
                    }
                }
            }
            return(null);
        }
        public override void RenderInWindow(IWindow mainWindow, FigmaNode node, ViewRenderServiceOptions options = null)
        {
            if (node is IAbsoluteBoundingBox bounNode)
            {
                mainWindow.Size = new Size(bounNode.absoluteBoundingBox.Width, bounNode.absoluteBoundingBox.Height);
            }

            if (options == null)
            {
                options = new ViewRenderServiceOptions()
                {
                    GenerateMainView = false
                };
            }

            SetOptions(options);

            var content = node.GetWindowContent() ?? node;

            ProcessFromNode(content, mainWindow.Content, options);
            var processedNode = FindProcessedNodeById(content.id);

            RecursivelyConfigureViews(processedNode, options);

            var windowComponent = node.GetDialogInstanceFromParentContainer();

            if (windowComponent != null)
            {
                var optionsNode = windowComponent.Options();
                if (optionsNode is IFigmaNodeContainer figmaNodeContainer)
                {
                    mainWindow.IsClosable            = figmaNodeContainer.HasChildrenVisible("close");
                    mainWindow.Resizable             = figmaNodeContainer.HasChildrenVisible("resize");
                    mainWindow.ShowMiniaturizeButton = figmaNodeContainer.HasChildrenVisible("min");
                    mainWindow.ShowZoomButton        = figmaNodeContainer.HasChildrenVisible("max");
                }

                var titleText = optionsNode.FirstChild(s => s.name == "title" && s.visible) as FigmaText;
                if (titleText != null)
                {
                    mainWindow.Title = titleText.characters;
                }
            }
        }
        public override IView ConvertToView(FigmaNode currentNode, ViewNode parentNode, ViewRenderService rendererService)
        {
            string title = "";
            var    frame = (FigmaFrame)currentNode;

            var nativeView = new FakeWindowView(title);

            nativeView.LiveButtonAlwaysVisible = LiveButtonAlwaysVisible;
            nativeView.Configure(currentNode);

            var view = new View(nativeView);

            var windowComponent = currentNode.GetDialogInstanceFromParentContainer();

            if (windowComponent != null)
            {
                var optionsNode = windowComponent.Options();
                if (optionsNode is IFigmaNodeContainer figmaNodeContainer)
                {
                    nativeView.CloseButtonHidden = (figmaNodeContainer.HasChildrenVisible("close") == false);
                    nativeView.MinButtonHidden   = (figmaNodeContainer.HasChildrenVisible("min") == false);
                    nativeView.MaxButtonHidden   = (figmaNodeContainer.HasChildrenVisible("max") == false);

                    var titleText = (FigmaText)optionsNode.GetChildren().FirstOrDefault(s => s.name == "title" && s.visible);

                    if (titleText != null)
                    {
                        nativeView.Title = titleText.characters;
                    }
                }
            }

            nativeView.LiveButton.Activated += async(s, e) => {
                var window = new Window(view.Allocation);

                LivePreviewLoading?.Invoke(this, EventArgs.Empty);

                await newWindowProvider.LoadAsync(rendererService.NodeProvider.File);

                var secondaryRender = new ControlViewRenderingService(newWindowProvider);

                var options = new ViewRenderServiceOptions()
                {
                    GenerateMainView = false
                };
                secondaryRender.RenderInWindow(window, currentNode, options);

                var mainNodes = currentNode.GetChildren()
                                .ToArray();

                ViewNode[] processedNodes = secondaryRender.GetProcessedNodes(mainNodes);

                var layoutManager = new StoryboardLayoutManager()
                {
                    UsesConstraints = true
                };
                layoutManager.Run(processedNodes, window.Content, secondaryRender);

                var nativeWindow = (NSWindow)window.NativeObject;
                nativeWindow.Appearance     = nativeView.EffectiveAppearance;
                nativeWindow.ContentMinSize = nativeWindow.ContentView.Frame.Size;

                nativeWindow.Center();
                nativeWindow.MakeKeyAndOrderFront(null);

                LivePreviewLoaded?.Invoke(this, EventArgs.Empty);
            };

            return(view);
        }