Пример #1
0
        protected override IView OnConvertToView(FigmaNode currentNode, ViewNode parentNode, ViewRenderService rendererService)
        {
            var slider = new NSSlider();

            var frame = (FigmaFrame)currentNode;

            frame.TryGetNativeControlType(out var controlType);
            frame.TryGetNativeControlVariant(out var controlVariant);

            slider.ControlSize = ViewHelper.GetNSControlSize(controlVariant);

            slider.MinValue = 0;
            slider.MaxValue = 1;

            if (controlType == FigmaControlType.SliderLinear)
            {
                slider.DoubleValue = 0.618;
            }

            FigmaGroup group = frame.children
                               .OfType <FigmaGroup>()
                               .FirstOrDefault(s => s.visible);

            if (group?.name == ComponentString.STATE_DISABLED)
            {
                slider.Enabled = false;
            }

            return(new View(slider));
        }
Пример #2
0
        protected override IView OnConvertToView(FigmaNode currentNode, ViewNode parentNode, ViewRenderService rendererService)
        {
            var frame         = (FigmaFrame)currentNode;
            var switchControl = new NSSwitch();

            frame.TryGetNativeControlVariant(out var controlVariant);
            switchControl.ControlSize = NSControlSize.Regular;

            FigmaGroup group = frame.children
                               .OfType <FigmaGroup>()
                               .FirstOrDefault(s => (s.name == ComponentString.STATE_ON || s.name == ComponentString.STATE_OFF) && s.visible);

            if (group != null)
            {
                if (group.name == ComponentString.STATE_ON)
                {
                    switchControl.State = 1;
                }

                if (group.name == ComponentString.STATE_OFF)
                {
                    switchControl.State = 0;
                }
            }

            return(new View(switchControl));
        }
        protected override IView OnConvertToView(FigmaNode currentNode, ViewNode parentNode, ViewRenderService rendererService)
        {
            var frame = (FigmaFrame)currentNode;

            var progressIndicator = new NSProgressIndicator();

            progressIndicator.Configure(frame);

            frame.TryGetNativeControlType(out var controlType);
            frame.TryGetNativeControlVariant(out var controlVariant);

            progressIndicator.ControlSize = ViewHelper.GetNSControlSize(controlVariant);

            FigmaGroup group = frame.children
                               .OfType <FigmaGroup>()
                               .FirstOrDefault(s => (s.name == ComponentString.STYLE_DETERMINATE || s.name == ComponentString.STYLE_INDETERMINATE) && s.visible);

            if (group?.name == ComponentString.STYLE_DETERMINATE)
            {
                progressIndicator.Indeterminate = false;
                progressIndicator.MinValue      = 0;
                progressIndicator.MaxValue      = 1;
                progressIndicator.DoubleValue   = 0.618;
            }

            if (group.name == ComponentString.STYLE_INDETERMINATE)
            {
                progressIndicator.Indeterminate = true;
            }

            return(new View(progressIndicator));
        }
Пример #4
0
        protected override StringBuilder OnConvertToCode(FigmaCodeNode currentNode, FigmaCodeNode parentNode, FigmaCodeRendererService rendererService)
        {
            var    code = new StringBuilder();
            string name = FigmaSharp.Resources.Ids.Conversion.NameIdentifier;

            var frame = (FigmaFrame)currentNode.Node;

            currentNode.Node.TryGetNativeControlType(out NativeControlType controlType);
            currentNode.Node.TryGetNativeControlVariant(out NativeControlVariant controlVariant);

            if (rendererService.NeedsRenderConstructor(currentNode, parentNode))
            {
                code.WriteConstructor(name, GetControlType(currentNode.Node), rendererService.NodeRendersVar(currentNode, parentNode));
            }

            code.WriteMethod(name, nameof(NSButton.SetButtonType), NSButtonType.Switch);

            code.WriteEquality(name, nameof(NSButton.ControlSize), CocoaHelpers.GetNSControlSize(controlVariant));
            code.WriteEquality(name, nameof(NSSegmentedControl.Font), CocoaCodeHelpers.GetNSFontString(controlVariant));

            FigmaText text = frame.children
                             .OfType <FigmaText> ()
                             .FirstOrDefault();

            if (text != null)
            {
                var labelTranslated = NativeControlHelper.GetTranslatableString(text.characters, rendererService.CurrentRendererOptions.TranslateLabels);

                code.WriteEquality(name, nameof(NSButton.Title), labelTranslated,
                                   inQuotes: !rendererService.CurrentRendererOptions.TranslateLabels);
            }

            FigmaGroup group = frame.children
                               .OfType <FigmaGroup> ()
                               .FirstOrDefault(s => s.name.In(ComponentString.STATE_ON,
                                                              ComponentString.STATE_OFF,
                                                              ComponentString.STATE_MIXED) && s.visible);

            if (group != null)
            {
                if (group.name == ComponentString.STATE_ON)
                {
                    code.WriteEquality(name, nameof(NSButton.State), NSCellStateValue.On);
                }

                if (group.name == ComponentString.STATE_OFF)
                {
                    code.WriteEquality(name, nameof(NSButton.State), NSCellStateValue.Off);
                }

                if (group.name == ComponentString.STATE_MIXED)
                {
                    code.WriteEquality(name, nameof(NSButton.AllowsMixedState), true);
                    code.WriteEquality(name, nameof(NSButton.State), NSCellStateValue.Mixed);
                }
            }

            return(code);
        }
Пример #5
0
        protected override StringBuilder OnConvertToCode(FigmaCodeNode currentNode, FigmaCodeNode parentNode, FigmaCodeRendererService rendererService)
        {
            var    code = new StringBuilder();
            string name = FigmaSharp.Resources.Ids.Conversion.NameIdentifier;

            var frame = (FigmaFrame)currentNode.Node;

            currentNode.Node.TryGetNativeControlType(out NativeControlType controlType);
            currentNode.Node.TryGetNativeControlVariant(out NativeControlVariant controlVariant);

            if (rendererService.NeedsRenderConstructor(currentNode, parentNode))
            {
                code.WriteConstructor(name, GetControlType(currentNode.Node).FullName, rendererService.NodeRendersVar(currentNode, parentNode));
            }

            switch (controlType)
            {
            case NativeControlType.Button:
                code.WriteEquality(name, nameof(NSButton.BezelStyle), NSBezelStyle.Rounded);
                break;

            case NativeControlType.ButtonHelp:
                code.WriteEquality(name, nameof(NSButton.BezelStyle), NSBezelStyle.HelpButton);
                code.WriteEquality(name, nameof(NSButton.Title), string.Empty, inQuotes: true);
                break;
            }

            code.WriteEquality(name, nameof(NSButton.ControlSize), CocoaHelpers.GetNSControlSize(controlVariant));
            code.WriteEquality(name, nameof(NSSegmentedControl.Font), CocoaCodeHelpers.GetNSFontString(controlVariant));

            FigmaGroup group = frame.children
                               .OfType <FigmaGroup> ()
                               .FirstOrDefault(s => s.visible);

            if (group != null)
            {
                FigmaText text = group.children
                                 .OfType <FigmaText> ()
                                 .FirstOrDefault(s => s.name == ComponentString.TITLE);

                if (text != null && controlType != NativeControlType.ButtonHelp)
                {
                    string labelTranslated = NativeControlHelper.GetTranslatableString(text.characters, rendererService.CurrentRendererOptions.TranslateLabels);
                    code.WriteEquality(name, nameof(NSButton.Title), labelTranslated, inQuotes: !rendererService.CurrentRendererOptions.TranslateLabels);
                }

                if (group.name == ComponentString.STATE_DISABLED)
                {
                    code.WriteEquality(name, nameof(NSButton.Enabled), false);
                }

                if (group.name == ComponentString.STATE_DEFAULT)
                {
                    code.WriteEquality(name, nameof(NSButton.KeyEquivalent), "\\r", true);
                }
            }

            return(code);
        }
Пример #6
0
        protected override IView OnConvertToView(FigmaNode currentNode, ViewNode parentNode, ViewRenderService rendererService)
        {
            var button = new NSButton();

            var frame = (FigmaFrame)currentNode;

            frame.TryGetNativeControlType(out var controlType);
            frame.TryGetNativeControlVariant(out var controlVariant);

            switch (controlType)
            {
            case FigmaControlType.Button:
                button.BezelStyle = NSBezelStyle.Rounded;
                break;

            case FigmaControlType.ButtonRoundRect:
                button.BezelStyle = NSBezelStyle.RoundRect;
                break;

            case FigmaControlType.ButtonHelp:
                button.BezelStyle = NSBezelStyle.HelpButton;
                button.Title      = string.Empty;
                break;
            }

            button.ControlSize = ViewHelper.GetNSControlSize(controlVariant);
            button.Font        = ViewHelper.GetNSFont(controlVariant);

            FigmaGroup group = frame.children
                               .OfType <FigmaGroup>()
                               .FirstOrDefault(s => s.visible);

            if (group != null)
            {
                FigmaText text = group.children
                                 .OfType <FigmaText>()
                                 .FirstOrDefault(s => s.name == ComponentString.TITLE);

                if (text != null && controlType != FigmaControlType.ButtonHelp)
                {
                    button.Title = rendererService.GetTranslatedText(text);
                }

                if (group.name == ComponentString.STATE_DISABLED)
                {
                    button.Enabled = false;
                }

                if (group.name == ComponentString.STATE_DEFAULT)
                {
                    button.KeyEquivalent = "\r";
                }
            }

            return(new View(button));
        }
Пример #7
0
        protected override IView OnConvertToView(FigmaNode currentNode, ProcessedNode parentNode, FigmaRendererService rendererService)
        {
            var frame = (FigmaFrame)currentNode;

            var checkBox = new NSButton();

            checkBox.SetButtonType(NSButtonType.Switch);

            FigmaText text = frame.children
                             .OfType <FigmaText>()
                             .FirstOrDefault(s => s.name == ComponentString.TITLE);

            if (text != null)
            {
                checkBox.Title = text.characters;
            }

            frame.TryGetNativeControlVariant(out var controlVariant);

            checkBox.ControlSize = CocoaHelpers.GetNSControlSize(controlVariant);
            checkBox.Font        = CocoaHelpers.GetNSFont(controlVariant, text);

            FigmaGroup group = frame.children
                               .OfType <FigmaGroup>()
                               .FirstOrDefault(s => s.name.In(ComponentString.STATE_ON,
                                                              ComponentString.STATE_OFF,
                                                              ComponentString.STATE_MIXED) && s.visible);

            if (group != null)
            {
                if (group.name == ComponentString.STATE_ON)
                {
                    checkBox.State = NSCellStateValue.On;
                }

                if (group.name == ComponentString.STATE_OFF)
                {
                    checkBox.State = NSCellStateValue.Off;
                }

                if (group.name == ComponentString.STATE_MIXED)
                {
                    checkBox.AllowsMixedState = true;
                    checkBox.State            = NSCellStateValue.Mixed;
                }
            }

            return(new View(checkBox));
        }
Пример #8
0
        protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            var    code = new StringBuilder();
            string name = FigmaSharp.Resources.Ids.Conversion.NameIdentifier;

            var frame = (FigmaFrame)currentNode.Node;

            currentNode.Node.TryGetNativeControlType(out FigmaControlType controlType);
            currentNode.Node.TryGetNativeControlVariant(out NativeControlVariant controlVariant);

            if (rendererService.NeedsRenderConstructor(currentNode, parentNode))
            {
                code.WriteConstructor(name, GetControlType(currentNode.Node), rendererService.NodeRendersVar(currentNode, parentNode));
            }

            code.WriteMethod(name, nameof(NSButton.SetButtonType), NSButtonType.Radio);

            code.WritePropertyEquality(name, nameof(NSButton.ControlSize), ViewHelper.GetNSControlSize(controlVariant));
            code.WritePropertyEquality(name, nameof(NSSegmentedControl.Font), CodeHelper.GetNSFontString(controlVariant));

            FigmaText text = frame.children
                             .OfType <FigmaText>()
                             .FirstOrDefault();

            if (text != null)
            {
                code.WriteTranslatedEquality(name, nameof(NSButton.Title), text, rendererService);
            }

            FigmaGroup group = frame.children
                               .OfType <FigmaGroup>()
                               .FirstOrDefault(s => (s.name == ComponentString.STATE_ON || s.name == ComponentString.STATE_OFF) && s.visible);

            if (group != null)
            {
                if (group.name == ComponentString.STATE_ON)
                {
                    code.WritePropertyEquality(name, nameof(NSButton.State), NSCellStateValue.On);
                }

                if (group.name == ComponentString.STATE_OFF)
                {
                    code.WritePropertyEquality(name, nameof(NSButton.State), NSCellStateValue.Off);
                }
            }

            return(code);
        }
Пример #9
0
        protected override IView OnConvertToView(FigmaNode currentNode, ViewNode parentNode, ViewRenderService rendererService)
        {
            var frame = (FigmaFrame)currentNode;

            var radio = new NSButton();

            radio.SetButtonType(NSButtonType.Radio);

            FigmaText text = frame.children
                             .OfType <FigmaText>()
                             .FirstOrDefault(s => s.name == ComponentString.TITLE);

            if (text != null)
            {
                radio.Title = text.characters;
            }

            frame.TryGetNativeControlVariant(out var controlVariant);

            radio.ControlSize = ViewHelper.GetNSControlSize(controlVariant);
            radio.Font        = ViewHelper.GetNSFont(controlVariant, text);

            FigmaGroup group = frame.children
                               .OfType <FigmaGroup>()
                               .FirstOrDefault(s => (s.name == ComponentString.STATE_ON || s.name == ComponentString.STATE_OFF) && s.visible);

            if (group != null)
            {
                if (group.name == ComponentString.STATE_ON)
                {
                    radio.State = NSCellStateValue.On;
                }

                if (group.name == ComponentString.STATE_OFF)
                {
                    radio.State = NSCellStateValue.Off;
                }
            }

            return(new View(radio));
        }
Пример #10
0
        protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            var    code = new StringBuilder();
            string name = FigmaSharp.Resources.Ids.Conversion.NameIdentifier;

            var frame = (FigmaFrame)currentNode.Node;

            currentNode.Node.TryGetNativeControlType(out FigmaControlType controlType);
            currentNode.Node.TryGetNativeControlVariant(out NativeControlVariant controlVariant);

            if (rendererService.NeedsRenderConstructor(currentNode, parentNode))
            {
                code.WriteConstructor(name, GetControlType(currentNode.Node), rendererService.NodeRendersVar(currentNode, parentNode));
            }

            code.WritePropertyEquality(name, nameof(NSButton.ControlSize), ViewHelper.GetNSControlSize(controlVariant));

            FigmaGroup group = frame.children
                               .OfType <FigmaGroup>()
                               .FirstOrDefault(s => (s.name == ComponentString.STYLE_DETERMINATE || s.name == ComponentString.STYLE_INDETERMINATE) && s.visible);

            if (group != null)
            {
                if (group.name == ComponentString.STYLE_DETERMINATE)
                {
                    code.WritePropertyEquality(name, nameof(NSProgressIndicator.Indeterminate), false);
                    code.WritePropertyEquality(name, nameof(NSProgressIndicator.MinValue), "0");
                    code.WritePropertyEquality(name, nameof(NSProgressIndicator.MaxValue), "1");
                    code.WritePropertyEquality(name, nameof(NSProgressIndicator.DoubleValue), "0.618");
                }

                if (group.name == ComponentString.STYLE_INDETERMINATE)
                {
                    code.WritePropertyEquality(name, nameof(NSProgressIndicator.Indeterminate), true);
                }
            }

            return(code);
        }
Пример #11
0
        protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            var    code = new StringBuilder();
            string name = FigmaSharp.Resources.Ids.Conversion.NameIdentifier;

            var frame = (FigmaFrame)currentNode.Node;

            currentNode.Node.TryGetNativeControlType(out FigmaControlType controlType);
            currentNode.Node.TryGetNativeControlVariant(out NativeControlVariant controlVariant);

            if (rendererService.NeedsRenderConstructor(currentNode, parentNode))
            {
                code.WriteConstructor(name, GetControlType(currentNode.Node), rendererService.NodeRendersVar(currentNode, parentNode));
            }

            code.WritePropertyEquality(name, nameof(NSButton.ControlSize), NSControlSize.Regular);

            FigmaGroup group = frame.children
                               .OfType <FigmaGroup> ()
                               .FirstOrDefault(s => s.name.In(ComponentString.STATE_ON, ComponentString.STATE_OFF) && s.visible);

            if (group != null)
            {
                if (group.name == ComponentString.STATE_ON)
                {
                    code.WritePropertyEquality(name, nameof(NSSwitch.State), "1", inQuotes: false);
                }

                if (group.name == ComponentString.STATE_OFF)
                {
                    code.WritePropertyEquality(name, nameof(NSSwitch.State), "0", inQuotes: false);
                }
            }

            return(code);
        }
Пример #12
0
        protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            var    code = new StringBuilder();
            string name = FigmaSharp.Resources.Ids.Conversion.NameIdentifier;

            var frame = (FigmaFrame)currentNode.Node;

            currentNode.Node.TryGetNativeControlType(out FigmaControlType controlType);
            currentNode.Node.TryGetNativeControlVariant(out NativeControlVariant controlVariant);

            if (rendererService.NeedsRenderConstructor(currentNode, parentNode))
            {
                code.WriteConstructor(name, GetControlType(currentNode.Node), rendererService.NodeRendersVar(currentNode, parentNode));
            }

            code.WriteEquality(name, nameof(NSButton.ControlSize), ViewHelper.GetNSControlSize(controlVariant));

            code.WriteEquality(name, nameof(NSProgressIndicator.MinValue), "0");
            code.WriteEquality(name, nameof(NSProgressIndicator.MaxValue), "1");

            if (controlType == FigmaControlType.SliderLinear)
            {
                code.WriteEquality(name, nameof(NSProgressIndicator.DoubleValue), "0.618");
            }

            FigmaGroup group = frame.children
                               .OfType <FigmaGroup>()
                               .FirstOrDefault(s => s.visible);

            if (group?.name == ComponentString.STATE_DISABLED)
            {
                code.WriteEquality(name, nameof(NSSlider.Enabled), false);
            }

            return(code);
        }