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)); } FigmaVectorEntity rectangle = frame.children .OfType <FigmaVectorEntity>() .FirstOrDefault(s => s.name == ComponentString.VALUE); foreach (var styleMap in rectangle?.styles) { if ((rendererService.figmaProvider as FigmaFileProvider).TryGetStyle(styleMap.Value, out FigmaStyle style)) { if (styleMap.Key == "fill") { code.WriteEquality(name, nameof(NSColorWell.Color), CocoaCodeHelpers.GetNSColorString(style.name)); } } } return(code); }
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); }
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); }
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)); } FigmaNode optionsGroup = frame.Options(); FigmaNode passwordNode = optionsGroup?.GetChildren() .OfType <FigmaNode>() .FirstOrDefault(s => s.name == ComponentString.PASSWORD && s.visible); if (passwordNode != null) { code.WriteEquality(name, nameof(NSSecureTextField.StringValue), ComponentString.PASSWORD, inQuotes: true); } FigmaText placeholderText = optionsGroup?.GetChildren(). OfType <FigmaText>(). FirstOrDefault(s => s.name == ComponentString.PLACEHOLDER && s.visible); if (placeholderText != null && !placeholderText.characters.Equals(ComponentString.PLACEHOLDER, StringComparison.InvariantCultureIgnoreCase)) { var stringLabel = NativeControlHelper.GetTranslatableString(placeholderText.characters, rendererService.CurrentRendererOptions.TranslateLabels); code.WriteEquality(name, nameof(NSTextField.PlaceholderString), stringLabel, true); } FigmaText text = frame.children. OfType <FigmaText> (). FirstOrDefault(s => s.name == ComponentString.TITLE && s.visible); if (text != null) { code.WriteEquality(name, nameof(NSTextField.Font), CocoaCodeHelpers.GetNSFontString(controlVariant, text, withWeight: false)); var stringLabel = NativeControlHelper.GetTranslatableString(text.characters, rendererService.CurrentRendererOptions.TranslateLabels); code.WriteEquality(name, nameof(NSTextField.StringValue), stringLabel, inQuotes: !rendererService.CurrentRendererOptions.TranslateLabels); } return(code); }
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; frame.TryGetNativeControlType(out var controlType); frame.TryGetNativeControlVariant(out var controlVariant); if (rendererService.NeedsRenderConstructor(currentNode, parentNode)) { code.WriteConstructor(name, GetControlType(currentNode.Node), rendererService.NodeRendersVar(currentNode, parentNode)); } code.WriteEquality(name, nameof(NSButton.ControlSize), CocoaHelpers.GetNSControlSize(controlVariant)); code.WriteEquality(name, nameof(NSSegmentedControl.Font), CocoaCodeHelpers.GetNSFontString(controlVariant)); FigmaNode items = frame.FirstChild(s => s.name == ComponentString.ITEMS); if (items != null) { code.WriteEquality(name, nameof(NSSegmentedControl.SegmentCount), "" + items.GetChildren(t => t.visible).Count()); code.WriteEquality(name, nameof(NSSegmentedControl.SegmentDistribution), NSSegmentDistribution.FillEqually); code.WriteEquality(name, nameof(NSSegmentedControl.SegmentStyle), NSSegmentStyle.Rounded); code.WriteEquality(name, nameof(NSSegmentedControl.SelectedSegment), "0"); code.WriteEquality(name, nameof(NSSegmentedControl.TrackingMode), NSSegmentSwitchTracking.SelectOne); code.AppendLine(); int i = 0; foreach (FigmaNode button in items.GetChildren(t => t.visible)) { FigmaNode state = button.FirstChild(s => s.visible && s.name.In(ComponentString.STATE_REGULAR, ComponentString.STATE_SELECTED)); if (state == null) { continue; } var text = (FigmaText)state.FirstChild(s => s.name == ComponentString.TITLE); code.WriteMethod(name, nameof(NSSegmentedControl.SetLabel), $"\"{ text.characters }\", { i }"); i++; } code.AppendLine(); } return(code); }
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.WriteEquality(name, nameof(NSButton.BezelStyle), NSBezelStyle.Rounded); if (controlType == NativeControlType.PopUpButtonPullDown) { code.WriteEquality(name, nameof(NSPopUpButton.PullsDown), true); } 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(s => s.name == ComponentString.TITLE); if (text != null && !string.IsNullOrEmpty(text.characters)) { var stringLabel = NativeControlHelper.GetTranslatableString(text.characters, rendererService.CurrentRendererOptions.TranslateLabels); code.WriteMethod(name, nameof(NSPopUpButton.AddItem), stringLabel, inQuotes: !rendererService.CurrentRendererOptions.TranslateLabels); } return(code); }
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.WriteEquality(name, nameof(NSButton.ControlSize), CocoaHelpers.GetNSControlSize(controlVariant)); code.WriteEquality(name, nameof(NSSegmentedControl.Font), CocoaCodeHelpers.GetNSFontString(controlVariant)); FigmaText text = frame.children .OfType <FigmaText> () .FirstOrDefault(s => s.name == ComponentString.TITLE); if (text != null && !string.IsNullOrEmpty(text.characters)) { code.WriteEquality(name, nameof(NSButton.StringValue), text.characters, inQuotes: true); //string textLabel = NativeControlHelper.GetTranslatableString(text.characters, rendererService.CurrentRendererOptions.TranslateLabels); //if (!rendererService.CurrentRendererOptions.TranslateLabels) // textLabel = $"\"{textLabel}\""; //string nsstringcontructor = typeof (Foundation.NSString).GetConstructor (new[] { textLabel }); //code.WriteMethod (name, nameof (NSComboBox.Add), nsstringcontructor); } return(code); }
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)); } if (controlType == NativeControlType.Separator) { code.WriteEquality(name, nameof(NSBox.BoxType), NSBoxType.NSBoxSeparator); } if (controlType == NativeControlType.BoxCustom) { code.WriteEquality(name, nameof(NSBox.BoxType), NSBoxType.NSBoxCustom); bool borderSet = false; FigmaVectorEntity rectangle = frame.children .OfType <FigmaVectorEntity>() .FirstOrDefault(); foreach (var styleMap in rectangle?.styles) { if ((rendererService.figmaProvider as FigmaFileProvider).TryGetStyle(styleMap.Value, out FigmaStyle style)) { if (styleMap.Key == "fill") { code.WriteEquality(name, nameof(NSBox.FillColor), CocoaCodeHelpers.GetNSColorString(style.name)); } if (styleMap.Key == "stroke") { code.WriteEquality(name, nameof(NSBox.BorderColor), CocoaCodeHelpers.GetNSColorString(style.name)); code.WriteEquality(name, nameof(NSBox.BorderWidth), rectangle.strokeWeight.ToString()); borderSet = true; } } } if (!borderSet) { code.WriteEquality(name, nameof(NSBox.BorderWidth), "0"); } } FigmaText text = frame.children .OfType <FigmaText>() .FirstOrDefault(s => (s.name == ComponentString.TITLE && s.visible)); if (text != null) { string stringTitle = NativeControlHelper.GetTranslatableString(text.characters, rendererService.CurrentRendererOptions.TranslateLabels); code.WriteEquality(name, nameof(NSBox.Title), stringTitle, inQuotes: !rendererService.CurrentRendererOptions.TranslateLabels); } else { code.WriteEquality(name, nameof(NSBox.Title), "", inQuotes: true); } return(code); }
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)); } FigmaText text = (FigmaText)frame.children .OfType <FigmaText>() .FirstOrDefault(s => s.name == ComponentString.TITLE); if (text == null) { return(null); } code.WriteEquality(name, nameof(NSTextField.Editable), false); code.WriteEquality(name, nameof(NSTextField.Bordered), false); code.WriteEquality(name, nameof(NSTextField.DrawsBackground), false); code.WriteEquality(name, nameof(NSTextField.PreferredMaxLayoutWidth), "1"); var labelComponent = NativeControlHelper.GetTranslatableString(text.characters, rendererService.CurrentRendererOptions.TranslateLabels); code.WriteEquality(name, nameof(NSTextField.StringValue), labelComponent, inQuotes: !rendererService.CurrentRendererOptions.TranslateLabels); if (text != null) { code.WriteEquality(name, nameof(NSTextField.Alignment), CocoaCodeHelpers.GetNSTextAlignmentString(text).ToString()); } if (controlType == NativeControlType.LabelHeader) { code.WriteEquality(name, nameof(NSTextField.Font), $"{ typeof(NSFont) }.{ nameof(NSFont.SystemFontOfSize) }({ headerFontSize }, { CocoaCodeHelpers.GetNSFontWeightString(text) })"); } else { code.WriteEquality(name, nameof(NSTextField.Font), CocoaCodeHelpers.GetNSFontString(controlVariant, text)); } foreach (var styleMap in text?.styles) { if ((rendererService.figmaProvider as FigmaFileProvider).TryGetStyle(styleMap.Value, out FigmaStyle style)) { if (styleMap.Key == "fill") { code.WriteEquality(name, nameof(NSTextField.TextColor), CocoaCodeHelpers.GetNSColorString(style.name)); } } } return(code); }