Exemplo n.º 1
0
        public static void LoadFigma(this NSView contentView, FigmaFrameEntityResponse frameEntityResponse, List <FigmaImageView> figmaImageViews = null)
        {
            //clean views from current container
            var views = contentView.Subviews;

            foreach (var item in views)
            {
                item.RemoveFromSuperview();
            }
            contentView.RemoveConstraints(contentView.Constraints);

            //Figma doesn't calculate the bounds of our first level
            frameEntityResponse.FigmaMainNode.CalculateBounds();

            contentView.WantsLayer = true;
            var backgroundColor = frameEntityResponse.FigmaMainNode.backgroundColor.ToNSColor();

            contentView.Layer.BackgroundColor = backgroundColor.CGColor;

            var figmaView = frameEntityResponse.FigmaMainNode as FigmaNode;
            var mainView  = figmaView.ToNSView(contentView, figmaView, figmaImageViews);

            if (mainView != null)
            {
                contentView.AddSubview(mainView);
            }
        }
Exemplo n.º 2
0
        void ConstrainSubviewToSuperview(NSView subview, NSView superview)
        {
            subview.TranslatesAutoresizingMaskIntoConstraints = false;

            NSLayoutConstraint[] constraints;

            if (ownedConstraints.TryGetValue(superview, out constraints))
            {
                superview.RemoveConstraints(constraints);
            }

            ownedConstraints.Add(superview, constraints = new [] {
                NSLayoutConstraint.Create(
                    subview, NSLayoutAttribute.Width,
                    NSLayoutRelation.Equal,
                    superview, NSLayoutAttribute.Width,
                    1,
                    0),

                NSLayoutConstraint.Create(
                    subview, NSLayoutAttribute.Height,
                    NSLayoutRelation.Equal,
                    superview, NSLayoutAttribute.Height,
                    1,
                    0)
            });

            superview.AddConstraints(constraints);
        }
Exemplo n.º 3
0
 public void RemoveFromSuperview()
 {
     if (view != null)
     {
         var constraints = view.Constraints;
         view.RemoveConstraints(constraints);
     }
 }
        public static void SwapSubView(this NSView containerView, NSView targetView)
        {
            // we could add spacing to this

            while (containerView.Subviews.Any())
            {
                containerView.Subviews[0].RemoveFromSuperview();
            }
            containerView.RemoveConstraints(containerView.Constraints);

            targetView.TranslatesAutoresizingMaskIntoConstraints = false;
            containerView.AddSubview(targetView);
            NSDictionary views = NSDictionary.FromObjectAndKey(targetView, new NSString("target"));

            containerView.AddConstraints(NSLayoutConstraint.FromVisualFormat(
                                             "H:|[target]|", NSLayoutFormatOptions.None, null, views));
            containerView.AddConstraints(NSLayoutConstraint.FromVisualFormat(
                                             "V:|[target]|", NSLayoutFormatOptions.None, null, views));
        }