protected override IView OnConvertToView(FigmaNode currentNode, ProcessedNode parentNode, FigmaRendererService rendererService) { var slider = new NSSlider(); var frame = (FigmaFrame)currentNode; frame.TryGetNativeControlType(out var controlType); frame.TryGetNativeControlVariant(out var controlVariant); slider.ControlSize = CocoaHelpers.GetNSControlSize(controlVariant); slider.MinValue = 0; slider.MaxValue = 1; if (controlType == NativeControlType.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)); }
protected override IView OnConvertToView(FigmaNode currentNode, ProcessedNode parentNode, FigmaRendererService rendererService) { var frame = (FigmaFrame)currentNode; var progressIndicator = new NSProgressIndicator(); progressIndicator.Configure(frame); frame.TryGetNativeControlType(out var controlType); frame.TryGetNativeControlVariant(out var controlVariant); progressIndicator.ControlSize = CocoaHelpers.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)); }
public static string GetNSFontString(NativeControlVariant controlVariant, FigmaText text, bool withWeight = true) { var fontWeight = CocoaHelpers.GetNSFontWeight(text); if (controlVariant == NativeControlVariant.Regular) { // The system default Medium is slightly different, so let Cocoa handle that if (fontWeight == NSFontWeight.Medium || !withWeight) { return($"{ typeof(NSFont) }.{ nameof(NSFont.SystemFontOfSize) }({ GetNSFontSizeString(controlVariant) })"); } } if (controlVariant == NativeControlVariant.Small) { // The system default Medium is slightly different, so let Cocoa handle that if (fontWeight == NSFontWeight.Medium || !withWeight) { return($"{ typeof(NSFont) }.{ nameof(NSFont.SystemFontOfSize) }({ GetNSFontSizeString(controlVariant) })"); } else { return($"{ typeof(NSFont) }.{ nameof(NSFont.SystemFontOfSize) }({ GetNSFontSizeString(controlVariant) }, { GetNSFontWeightString(text) })"); } } if (withWeight) { return($"{ typeof(NSFont) }.{ nameof(NSFont.SystemFontOfSize) }({ GetNSFontSizeString(controlVariant) }, { GetNSFontWeightString(text) })"); } else { return($"{ typeof(NSFont) }.{ nameof(NSFont.SystemFontOfSize) }({ GetNSFontSizeString(controlVariant) })"); } }
protected override IView OnConvertToView(FigmaNode currentNode, ProcessedNode parentNode, FigmaRendererService rendererService) { var frame = (FigmaFrame)currentNode; frame.TryGetNativeControlVariant(out var controlVariant); frame.TryGetNativeControlType(out var controlType); var popUp = new NSPopUpButton(); if (controlType == NativeControlType.PopUpButtonPullDown) { popUp.PullsDown = true; } popUp.ControlSize = CocoaHelpers.GetNSControlSize(controlVariant); popUp.Font = CocoaHelpers.GetNSFont(controlVariant); FigmaText text = frame.children .OfType <FigmaText>() .FirstOrDefault(s => s.name == ComponentString.TITLE); if (text != null) { popUp.AddItem(text.characters); } return(new View(popUp)); }
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 IView OnConvertToView(FigmaNode currentNode, ProcessedNode parentNode, FigmaRendererService rendererService) { var frame = (FigmaFrame)currentNode; var box = new NSBox(); currentNode.TryGetNativeControlType(out NativeControlType controlType); if (controlType == NativeControlType.Separator) { box.BoxType = NSBoxType.NSBoxSeparator; } if (controlType == NativeControlType.BoxCustom) { box.BoxType = NSBoxType.NSBoxCustom; box.BorderWidth = 0; FigmaVectorEntity rectangle = frame.children .OfType <FigmaVectorEntity>() .FirstOrDefault(); foreach (var styleMap in rectangle?.styles) { if (rendererService.FileProvider.TryGetStyle(styleMap.Value, out FigmaStyle style)) { if (styleMap.Key == "fill") { box.FillColor = CocoaHelpers.GetNSColor(style.name); } if (styleMap.Key == "stroke") { box.BorderColor = CocoaHelpers.GetNSColor(style.name); box.BorderWidth = rectangle.strokeWeight; } } } } if (controlType == NativeControlType.Box) { FigmaText text = frame.children .OfType <FigmaText>() .FirstOrDefault(s => (s.name == ComponentString.TITLE && s.visible)); if (text != null) { box.Title = text.characters; } else { box.Title = ""; } } return(new View(box)); }
protected override IView OnConvertToView(FigmaNode currentNode, ProcessedNode parentNode, FigmaRendererService rendererService) { var textField = new NSTextField(); var frame = (FigmaFrame)currentNode; frame.TryGetNativeControlType(out var controlType); frame.TryGetNativeControlVariant(out var controlVariant); if (controlType == NativeControlType.SearchField) { textField = new NSSearchField(); } FigmaNode optionsGroup = frame.Options(); FigmaNode passwordNode = optionsGroup?.GetChildren() .OfType <FigmaNode>() .FirstOrDefault(s => s.name == ComponentString.PASSWORD && s.visible); if (passwordNode != null) { textField = new NSSecureTextField(); textField.StringValue = "Password"; } FigmaText placeholderText = optionsGroup?.GetChildren() .OfType <FigmaText>() .FirstOrDefault(s => s.name == ComponentString.PLACEHOLDER && s.visible); if (placeholderText != null && !placeholderText.characters.Equals(ComponentString.PLACEHOLDER, StringComparison.InvariantCultureIgnoreCase)) { textField.PlaceholderString = placeholderText.characters; } FigmaText text = frame.children .OfType <FigmaText> () .FirstOrDefault(s => s.name == ComponentString.TITLE && s.visible); if (text != null) { textField.Alignment = CocoaHelpers.GetNSTextAlignment(text); textField.StringValue = text.characters; } textField.ControlSize = CocoaHelpers.GetNSControlSize(controlVariant); textField.Font = CocoaHelpers.GetNSFont(controlVariant); return(new View(textField)); }
protected override IView OnConvertToView(FigmaNode currentNode, ProcessedNode parentNode, FigmaRendererService rendererService) { var stepper = new NSStepper(); var frame = (FigmaFrame)currentNode; frame.TryGetNativeControlVariant(out var controlVariant); stepper.ControlSize = CocoaHelpers.GetNSControlSize(controlVariant); return(new View(stepper)); }
protected override IView OnConvertToView(FigmaNode currentNode, ProcessedNode parentNode, FigmaRendererService rendererService) { var button = new NSButton(); var frame = (FigmaFrame)currentNode; frame.TryGetNativeControlType(out var controlType); frame.TryGetNativeControlVariant(out var controlVariant); switch (controlType) { case NativeControlType.Button: button.BezelStyle = NSBezelStyle.Rounded; break; case NativeControlType.ButtonHelp: button.BezelStyle = NSBezelStyle.HelpButton; button.Title = string.Empty; break; } button.ControlSize = CocoaHelpers.GetNSControlSize(controlVariant); button.Font = CocoaHelpers.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 != NativeControlType.ButtonHelp) { button.Title = text.characters; } if (group.name == ComponentString.STATE_DISABLED) { button.Enabled = false; } if (group.name == ComponentString.STATE_DEFAULT) { button.KeyEquivalent = "\r"; } } return(new View(button)); }
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 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)); }
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)); return(code); }
protected override IView OnConvertToView(FigmaNode currentNode, ProcessedNode parentNode, FigmaRendererService rendererService) { var segmentedControl = new NSSegmentedControl(); var frame = (FigmaFrame)currentNode; frame.TryGetNativeControlType(out var controlType); frame.TryGetNativeControlVariant(out var controlVariant); segmentedControl.ControlSize = CocoaHelpers.GetNSControlSize(controlVariant); segmentedControl.Font = CocoaHelpers.GetNSFont(controlVariant); FigmaNode items = frame.FirstChild(s => s.name == ComponentString.ITEMS); if (items != null) { segmentedControl.SegmentCount = items.GetChildren(t => t.visible).Count(); segmentedControl.SegmentDistribution = NSSegmentDistribution.FillEqually; segmentedControl.SegmentStyle = NSSegmentStyle.Rounded; segmentedControl.SelectedSegment = 0; 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); segmentedControl.SetLabel(text.characters, i); i++; } } segmentedControl.TrackingMode = NSSegmentSwitchTracking.SelectOne; return(new View(segmentedControl)); }
protected override IView OnConvertToView(FigmaNode currentNode, ProcessedNode parentNode, FigmaRendererService rendererService) { var label = new NSTextField(); label.Editable = false; label.DrawsBackground = false; label.Bordered = false; label.PreferredMaxLayoutWidth = 1; var frame = (FigmaFrame)currentNode; FigmaText text = frame.children .OfType <FigmaText>() .FirstOrDefault(s => s.name == ComponentString.TITLE); currentNode.TryGetNativeControlType(out NativeControlType controlType); currentNode.TryGetNativeControlVariant(out NativeControlVariant controlVariant); if (text != null) { label.StringValue = text.characters; label.Alignment = CocoaHelpers.GetNSTextAlignment(text); label.Font = CocoaHelpers.GetNSFont(controlVariant, text); } if (controlType == NativeControlType.LabelHeader) { label.Font = NSFont.SystemFontOfSize(headerFontSize, CocoaHelpers.GetNSFontWeight(text)); } foreach (var styleMap in text?.styles) { if (rendererService.FileProvider.TryGetStyle(styleMap.Value, out FigmaStyle style)) { if (styleMap.Key == "fill") { label.TextColor = CocoaHelpers.GetNSColor(style.name); } } } return(new View(label)); }
protected override IView OnConvertToView(FigmaNode currentNode, ProcessedNode parentNode, FigmaRendererService 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 = CocoaHelpers.GetNSControlSize(controlVariant); radio.Font = CocoaHelpers.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)); }
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 IView OnConvertToView(FigmaNode currentNode, ProcessedNode parentNode, FigmaRendererService rendererService) { var colorWell = new NSColorWell(); var frame = (FigmaFrame)currentNode; FigmaVectorEntity rectangle = frame.children .OfType <FigmaVectorEntity>() .FirstOrDefault(s => s.name == ComponentString.VALUE); foreach (var styleMap in rectangle?.styles) { if (rendererService.FileProvider.TryGetStyle(styleMap.Value, out FigmaStyle style)) { if (styleMap.Key == "fill") { colorWell.Color = CocoaHelpers.GetNSColor(style.name); } } } return(new View(colorWell)); }
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)); 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.WriteEquality(name, nameof(NSProgressIndicator.Indeterminate), false); code.WriteEquality(name, nameof(NSProgressIndicator.MinValue), "0"); code.WriteEquality(name, nameof(NSProgressIndicator.MaxValue), "1"); code.WriteEquality(name, nameof(NSProgressIndicator.DoubleValue), "0.618"); } if (group.name == ComponentString.STYLE_INDETERMINATE) { code.WriteEquality(name, nameof(NSProgressIndicator.Indeterminate), true); } } return(code); }
protected override IView OnConvertToView(FigmaNode currentNode, ProcessedNode parentNode, FigmaRendererService rendererService) { var combobox = new NSComboBox(); var frame = (FigmaFrame)currentNode; frame.TryGetNativeControlVariant(out var controlVariant); combobox.ControlSize = CocoaHelpers.GetNSControlSize(controlVariant); combobox.Font = CocoaHelpers.GetNSFont(controlVariant); FigmaText text = frame.children .OfType <FigmaText> () .FirstOrDefault(s => s.name == ComponentString.TITLE); if (text != null && !string.IsNullOrEmpty(text.characters)) { combobox.StringValue = text.characters; } return(new View(combobox)); }
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); }
public static string GetNSTextAlignmentString(FigmaText text) { return($"{nameof(NSTextAlignment)}.{CocoaHelpers.GetNSTextAlignment(text)}"); }