Beispiel #1
0
        public static void WriteTranslatedEquality(this StringBuilder builder, string viewName, string propertyName, string value, CodeRenderService codeRenderService, bool instanciate = false, bool textCondition = true)
        {
            bool   needQuotes;
            string result;

            if (textCondition && !string.IsNullOrEmpty(value))
            {
                if (codeRenderService.Options != null && codeRenderService.Options.TranslateLabels)
                {
                    result     = codeRenderService.GetTranslatedText(value);
                    needQuotes = false;
                }
                else
                {
                    result     = value;
                    needQuotes = true;
                }
            }
            else
            {
                result     = string.Empty;
                needQuotes = true;
            }
            builder.AppendLine(CodeGenerationHelpers.GetPropertyEquality(viewName, propertyName, result, inQuotes: needQuotes, instanciate: instanciate));
        }
Beispiel #2
0
        public override string ConvertToCode(CodeNode currentNode, CodeNode parentNode, CodeRenderService rendererService)
        {
            var builder = OnConvertToCode(currentNode, parentNode, rendererService);

            if (builder != null)
            {
                currentNode.Node.TryGetNativeControlType(out var nativeControlType);

                if (!currentNode.Node.visible)
                {
                    builder.WritePropertyEquality(currentNode.Name, nameof(NSView.Hidden), true);
                }

                builder.WritePropertyEquality(currentNode.Name, nameof(NSView.TranslatesAutoresizingMaskIntoConstraints), false);

                if (currentNode.Node.IsA11Enabled())
                {
                    bool hasAccessibility = false;

                    if (CanSetAccessibilityRole && currentNode.Node.IsA11Group())
                    {
                        var fullRoleName = $"{typeof(AppKit.NSAccessibilityRoles).FullName}.{nameof(AppKit.NSAccessibilityRoles.GroupRole)}";
                        builder.WritePropertyEquality(currentNode.Name, nameof(AppKit.NSView.AccessibilityRole), fullRoleName);

                        hasAccessibility = true;
                    }

                    if (CanSetAccessibilityLabel && currentNode.Node.TrySearchA11Label(out var label))
                    {
                        builder.WriteTranslatedEquality(currentNode.Name, GetAccessibilityTitle(nativeControlType), label, rendererService);
                        hasAccessibility = true;
                    }

                    if (CanSetAccessibilityHelp && currentNode.Node.TrySearchA11Help(out var help))
                    {
                        help = rendererService.GetTranslatedText(help);
                        builder.WritePropertyEquality(currentNode.Name, nameof(AppKit.NSView.AccessibilityHelp), help, inQuotes: !rendererService.Options.TranslateLabels);

                        hasAccessibility = true;
                    }

                    if (hasAccessibility)
                    {
                        builder.AppendLine();
                    }
                }

                return(builder.ToString());
            }
            return(string.Empty);
        }
Beispiel #3
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.BezelStyle), NSBezelStyle.Rounded);

            if (controlType == FigmaControlType.PopUpButtonPullDown)
            {
                code.WritePropertyEquality(name, nameof(NSPopUpButton.PullsDown), true);
            }

            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(s => s.name == ComponentString.TITLE);

            if (text != null && !string.IsNullOrEmpty(text.characters))
            {
                var stringLabel = rendererService.GetTranslatedText(text);
                code.WriteMethod(name, nameof(NSPopUpButton.AddItem), stringLabel,
                                 inQuotes: !rendererService.Options.TranslateLabels);
            }

            return(code);
        }