Exemplo n.º 1
0
        public ExampleViewManager(IScrollView scrollView, FigmaViewConverter[] converters)
        {
            fileProvider    = new FigmaRemoteFileProvider();
            RendererService = new FigmaFileRendererService(fileProvider, converters);

            var options = new FigmaViewRendererServiceOptions()
            {
                ScanChildrenFromFigmaInstances = false
            };

            RendererService.Start(fileName, scrollView.ContentView, options);

            distributionService = new FigmaViewRendererDistributionService(RendererService);
            distributionService.Start();

            //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;
            }


            scrollView.AdjustToContent();
        }
Exemplo n.º 2
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 FigmaFileRendererService(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();

            //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();
        }
Exemplo n.º 3
0
        //NSProgressIndicator progressIndicator;

        void Load(string version_id, string page_id)
        {
            if (string.IsNullOrEmpty(Link_ID))
            {
                return;
            }
            windowController.Title = string.Format("Opening “{0}”…", Link_ID);

            ToggleSpinnerState(toggle_on: true);
            windowController.EnableButtons(false);

            scrollview.ClearSubviews();

            new Thread(() => {
                this.InvokeOnMainThread(() => {
                    AppContext.Current.SetAccessToken(Token);

                    var converters = AppContext.Current.GetFigmaConverters();

                    Console.WriteLine("TOKEN: " + Token);

                    var fileProvider    = new FigmaRemoteFileProvider();
                    var rendererService = new FigmaFileRendererService(fileProvider, converters);

                    rendererService.Start(Link_ID, scrollview);

                    var distributionService = new FigmaViewRendererDistributionService(rendererService);
                    distributionService.Start();

                    fileProvider.ImageLinksProcessed += (s, e) =>
                    {
                        // done
                    };

                    //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();

                    windowController.Title = Link_ID;

                    windowController.UpdateVersionMenu();
                    windowController.UpdatePagesPopupButton();
                    windowController.EnableButtons(true);

                    ToggleSpinnerState(toggle_on: false);
                });
            }).Start();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Reload the specified includeImages.
 /// </summary>
 public void Reload()
 {
     Console.WriteLine($"Loading views..");
     try
     {
         FigmaImages.Clear();
         fileService.Start(file, ContentView);
         rendererService.Start();
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Error reading resource");
         Console.WriteLine(ex);
     }
 }
Exemplo n.º 5
0
        public void Reload(IViewWrapper contentView, string file, FigmaViewRendererServiceOptions options)
        {
            try
            {
                rendererService.Start(file, contentView, options);
                distributionService.Start();

                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);
            }
        }
        void Load(string version_id, string page_id)
        {
            Title = string.Format("Opening “{0}”…", Link_ID);

            (Window.ContentViewController as DocumentViewController).ToggleSpinnerState(toggle_on: true);
            RefreshButton.Enabled = false;
            CodeButton.Enabled    = false;

            AppContext.Current.SetAccessToken(Token);
            var converters = AppContext.Current.GetFigmaConverters();

            my_scroll_view = new NSScrollView();
            ScrollViewWrapper wrapper = new ScrollViewWrapper(my_scroll_view);



            new Thread(() => {
                this.InvokeOnMainThread(() =>
                {
                    fileProvider        = new FigmaRemoteFileProvider();
                    var rendererService = new FigmaFileRendererService(fileProvider, converters);

                    rendererService.Start(Link_ID, wrapper);
                    var distributionService = new FigmaViewRendererDistributionService(rendererService);
                    distributionService.Start();

                    fileProvider.ImageLinksProcessed += (s, e) => {
                        this.InvokeOnMainThread(() =>
                        {
                            Console.WriteLine("LOADING DONE");



                            if (fileProvider.Response == null)
                            {
                                (Window.ContentViewController as DocumentViewController).ToggleSpinnerState(toggle_on: false);
                                ShowError();
                                return;
                            }

                            FigmaCanvas canvas;

                            if (!string.IsNullOrEmpty(page_id))
                            {
                                canvas = (FigmaCanvas)fileProvider.Nodes.First(x => x.name == page_id);
                            }
                            else
                            {
                                canvas = (FigmaCanvas)fileProvider.Nodes.OfType <FigmaCanvas>().FirstOrDefault();
                            }

                            wrapper.BackgroundColor = canvas.backgroundColor;
                            wrapper.AdjustToContent();
                            // TODO: scroll to middle


                            var scroll                = (NSScrollView)wrapper.NativeObject;
                            scroll.ScrollerStyle      = NSScrollerStyle.Overlay;
                            scroll.AutohidesScrollers = true;
                            Window.ContentView.AddSubview(scroll);
                            scroll.Frame = Window.ContentView.Bounds;

                            Title        = fileProvider.Response.name;
                            Window.Title = fileProvider.Response.name;

                            UpdateVersionMenu();
                            UpdatePagesPopupButton();

                            RefreshButton.Enabled   = true;
                            CodeButton.Enabled      = true;
                            PagePopUpButton.Enabled = true;

                            (Window.ContentViewController as DocumentViewController).ToggleSpinnerState(toggle_on: false);
                        });
                    };
                });
            }).Start();
        }