public static void RenderInWindow(this ViewRenderService sender, IWindow mainWindow, string windowLayerName, ViewRenderServiceOptions options = null) { var windowFigmaNode = sender.FileProvider.FindByName(windowLayerName); FigmaNode content = null; if (windowFigmaNode is IFigmaNodeContainer figmaNodeContainer) { content = figmaNodeContainer.children.FirstOrDefault(s => s.IsNodeWindowContent()); var windowComponent = windowFigmaNode.GetDialogInstanceFromParentContainer(); if (options == null) { options = new ViewRenderServiceOptions(); options.AreImageProcessed = false; } options.ToIgnore = new FigmaNode[] { windowComponent }; if (windowComponent != null) { var windowLabel = windowComponent.children .OfType <FigmaText>() .FirstOrDefault(); if (windowLabel != null) { mainWindow.Title = windowLabel.characters; } } } if (windowFigmaNode is IAbsoluteBoundingBox box) { mainWindow.Size = box.absoluteBoundingBox.Size; } if (content == null) { content = windowFigmaNode; } var renderContent = sender.RenderByNode(content, mainWindow.Content, options); mainWindow.Content = renderContent; }
public void Reload(IView contentView, string file, ViewRenderServiceOptions options) { try { rendererService.Start(file, contentView, options); distributionService.Run(contentView, rendererService); ReloadFinished?.Invoke(this, EventArgs.Empty); } catch (DirectoryNotFoundException ex) { Console.WriteLine("[FIGMA.RENDERER] Resource directory not found ({0}). Images will not load", ex.Message); } catch (System.Exception ex) { Console.WriteLine(ex); } }
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 async Task ReloadAsync(IView contentView, string file, ViewRenderServiceOptions options) { try { await rendererService.StartAsync(file, contentView, options); distributionService.Run(contentView, rendererService); ReloadFinished?.Invoke(this, EventArgs.Empty); } catch (DirectoryNotFoundException ex) { LoggingService.LogInfo("[FIGMA.RENDERER] Resource directory not found ({0}). Images will not load", ex.Message); } catch (System.Exception ex) { LoggingService.LogError("[FIGMA.RENDERER] Error", ex); } }
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); }
protected override IEnumerable <FigmaNode> GetCurrentChildren(FigmaNode currentNode, FigmaNode parentNode, NodeConverter converter, ViewRenderServiceOptions options) { var windowContent = currentNode.GetWindowContent(); if (windowContent != null && windowContent is IFigmaNodeContainer nodeContainer) { return(nodeContainer.children); } return(base.GetCurrentChildren(currentNode, parentNode, converter, options)); }
protected override bool SkipsNode(FigmaNode currentNode, ViewNode parentNode, ViewRenderServiceOptions options) { if (currentNode.IsDialog()) { return(true); } return(base.SkipsNode(currentNode, parentNode, options)); }
protected override bool NodeScansChildren(FigmaNode currentNode, NodeConverter converter, ViewRenderServiceOptions options) { if (nodeProvider.RendersAsImage(currentNode)) { return(false); } return(base.NodeScansChildren(currentNode, converter, options)); }