Beispiel #1
0
 public static bool TryGetFigmaNode(this ProjectFile sender, FigmaFileProvider fileProvider, out FigmaNode figmaNode)
 {
     if (sender.IsFigmaDesignerFile() && TryGetNodeName(sender, out var figmaName))
     {
         figmaNode = fileProvider.FindById(figmaName);
         return(figmaNode != null);
     }
     figmaNode = null;
     return(false);
 }
Beispiel #2
0
        public static FigmaInstance GetBaseComponentNode(this FigmaFileProvider 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);
        }
        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();
        }