Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        public void Reload(IView contentView, string file, FigmaViewRendererServiceOptions 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);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reload the specified includeImages.
        /// </summary>
        public void Reload()
        {
            Console.WriteLine($"Loading views..");
            try
            {
                FigmaImages.Clear();
                rendererService.Start(file, ContentView);

                var mainNodes = rendererService.NodesProcessed
                                .Where(s => s.ParentView == null)
                                .ToArray();

                new StoryboardLayoutManager().Run(ContentView, rendererService);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error reading resource");
                Console.WriteLine(ex);
            }
        }
Ejemplo n.º 4
0
        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();
        }