protected override async Task OnInitialize(ModelDescriptor modelDescriptor, Properties status) { if (!(modelDescriptor is FileDescriptor fileDescriptor)) { throw new InvalidOperationException(); } if (session == null) { Owner = fileDescriptor.Owner; filePath = fileDescriptor.FilePath; DocumentTitle = fileDescriptor.FilePath.FileName; figmaDelegate = new FigmaDesignerDelegate(); var localPath = Path.Combine(filePath.ParentDirectory.FullPath, FigmaBundle.ResourcesDirectoryName); fileProvider = new ControlFileNodeProvider(localPath) { File = filePath.FullPath }; rendererService = new ControlViewRenderingService(fileProvider); //we generate a new file provider for embeded windows var tmpRemoteProvider = new FileNodeProvider(localPath) { File = filePath.FullPath }; rendererService.CustomConverters.Add(new EmbededWindowConverter(tmpRemoteProvider) { LiveButtonAlwaysVisible = false }); rendererService.CustomConverters.Add(new EmbededSheetDialogConverter(tmpRemoteProvider)); layoutManager = new StoryboardLayoutManager(); session = new FigmaDesignerSession(fileProvider, rendererService, layoutManager); //session.ModifiedChanged += HandleModifiedChanged; session.ReloadFinished += Session_ReloadFinished; surface = new FigmaDesignerSurface(figmaDelegate, session) { Session = session }; surface.FocusedViewChanged += Surface_FocusedViewChanged; var window = NSApplication.SharedApplication.MainWindow; surface.SetWindow(new WindowInternalWrapper(window)); surface.StartHoverSelection(); //IdeApp.Workbench.ActiveDocumentChanged += OnActiveDocumentChanged; IdeApp.Workbench.DocumentOpened += OnDocumentOpened; } await RefreshAll(); await base.OnInitialize(modelDescriptor, status); }
static void Main(string[] args) { FigmaApplication.Init(Environment.GetEnvironmentVariable("TOKEN")); NSApplication.Init(); NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.Regular; var stackView = new StackView() { Orientation = LayoutOrientation.Vertical }; scrollView = new ScrollView(); var mainWindow = new Window(new Rectangle(0, 0, 540, 800)) { Content = scrollView }; mainWindow.Closing += delegate { NSRunningApplication.CurrentApplication.Terminate(); }; //TIP: the render consist in 2 steps: //1) generate all the views, decorating and calculate sizes //2) with this views we generate the hierarchy and position all the views based in the //native toolkit positioning system //in this case we want use a remote file provider (figma url from our document) var fileProvider = new FigmaRemoteFileProvider(); //we initialize our renderer service, this uses all the converters passed //and generate a collection of NodesProcessed which is basically contains <FigmaModel, IView, FigmaParentModel> var rendererService = new FigmaViewRendererService(fileProvider); rendererService.Start(fileName, scrollView.ContentView); //now we have all the views processed and the relationship we can distribute all the views into the desired base view var layoutManager = new StoryboardLayoutManager(); layoutManager.Run(scrollView.ContentView, rendererService); //NOTE: some toolkits requires set the real size of the content of the scrollview before position layers scrollView.AdjustToContent(); mainWindow.Show(); //mainWindow.Title = manager.WindowTitle; NSApplication.SharedApplication.ActivateIgnoringOtherApps(true); NSApplication.SharedApplication.Run(); }
public ExampleViewManager(IScrollView scrollView) { //we get the default basic view converters from the current loaded toolkit var converters = FigmaSharp.AppContext.Current.GetFigmaConverters(); //TIP: the render consist in 2 steps: //1) generate all the views, decorating and calculate sizes //2) with this views we generate the hierarchy and position all the views based in the //native toolkit positioning system //in this case we want use a remote file provider (figma url from our document) fileProvider = new FigmaRemoteFileProvider(); //we initialize our renderer service, this uses all the converters passed //and generate a collection of NodesProcessed which is basically contains <FigmaModel, IView, FigmaParentModel> var rendererService = new FigmaViewRendererService(fileProvider, converters); rendererService.Start(fileName, scrollView); //now we have all the views processed and the relationship we can distribute all the views into the desired base view //var distributionService = new FigmaViewRendererDistributionService(rendererService); //distributionService.Start(); var layoutManager = new StoryboardLayoutManager(); layoutManager.Run(scrollView.ContentView, rendererService); //We want know the background color of the figma camvas and apply to our scrollview var canvas = fileProvider.Nodes.OfType <FigmaCanvas>().FirstOrDefault(); if (canvas != null) { scrollView.BackgroundColor = canvas.backgroundColor; } //NOTE: some toolkits requires set the real size of the content of the scrollview before position layers scrollView.AdjustToContent(); }
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); }
public FigmaDesignerSession(INodeProvider figmaFileProvider, ViewRenderService figmaViewRendererService, StoryboardLayoutManager figmaViewRendererDistributionService) { fileProvider = figmaFileProvider; rendererService = figmaViewRendererService; distributionService = figmaViewRendererDistributionService; }