in FigmaSharp.Controls/FigmaSharp.Controls.Cocoa/Converters/Controls/OutlineViewConverter.cs [174:259]
protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService rendererService)
{
var code = new StringBuilder();
// TODO: Get name from generator
var name = currentNode.Name + "ScrollView";
string outlineViewName = currentNode.Name;
currentNode.Name = name;
var frame = (FigmaFrame)currentNode.Node;
code.WriteConstructor(name, typeof(NSScrollView));
code.WritePropertyEquality(name, nameof(NSScrollView.AutoresizingMask),
$"{nameof(NSViewResizingMask)}.{nameof(NSViewResizingMask.WidthSizable)} | " +
$"{nameof(NSViewResizingMask)}.{nameof(NSViewResizingMask.HeightSizable)}");
code.WritePropertyEquality(name, nameof(NSScrollView.BorderType), NSBorderType.BezelBorder);
code.WritePropertyEquality(name, nameof(NSScrollView.DrawsBackground), true);
code.AppendLine();
if (rendererService.NeedsRenderConstructor(currentNode, parentNode))
code.WriteConstructor(outlineViewName, typeof(NSOutlineView), rendererService.NodeRendersVar(currentNode, parentNode));
code.WritePropertyEquality(outlineViewName, nameof(NSOutlineView.Frame),
string.Format("new {0} ({1}, {2}, {3}, {4})",
typeof(CoreGraphics.CGRect), 0, 0, name + ".ContentSize.Width", name + ".ContentSize.Height"));
var columnNodes = frame.FirstChild(s => s.name == ComponentString.COLUMNS && s.visible);
// TODO: Parse options layers
code.WritePropertyEquality(outlineViewName, nameof(NSOutlineView.UsesAlternatingRowBackgroundColors), false);
code.WritePropertyEquality(outlineViewName, nameof(NSOutlineView.AllowsMultipleSelection), false);
code.WritePropertyEquality(outlineViewName, nameof(NSOutlineView.AllowsColumnResizing), true);
code.WritePropertyEquality(outlineViewName, nameof(NSOutlineView.AllowsColumnReordering), false);
code.WritePropertyEquality(outlineViewName, nameof(NSOutlineView.AllowsEmptySelection), false);
code.AppendLine();
int columnCount = 1;
foreach (FigmaNode tableColumNode in columnNodes.GetChildren(t => t.visible))
{
FigmaText text = tableColumNode.FirstChild(s => s.name == ComponentString.TITLE) as FigmaText;
if (text == null)
continue;
string columnId = "OutlineColumn" + columnCount;
code.WriteConstructor(columnId, typeof(NSTableColumn));
code.WritePropertyEquality(columnId,
$"{nameof(NSTableColumn.HeaderCell)}.{nameof(NSTableColumn.HeaderCell.Alignment)}",
Helpers.CodeHelper.GetNSTextAlignmentString(text));
code.WritePropertyEquality(columnId, nameof(NSTableColumn.Identifier), columnId, inQuotes: true);
code.WritePropertyEquality(columnId, nameof(NSTableColumn.Title), rendererService.GetTranslatedText(text), inQuotes: true);
code.WritePropertyEquality(columnId, nameof(NSTableColumn.Width), text.absoluteBoundingBox.Width.ToString(), inQuotes: false);
code.WriteMethod(outlineViewName, nameof(NSOutlineView.AddColumn), columnId);
code.AppendLine();
if (columnCount == 1)
code.WritePropertyEquality(outlineViewName, nameof(NSOutlineView.OutlineTableColumn), columnId);
columnCount++;
}
code.WritePropertyEquality(name, nameof(NSScrollView.DocumentView), outlineViewName, inQuotes: false);
code.AppendLine();
var rectangle = (RectangleVector)frame.FirstChild(s => s.name == ComponentString.BACKGROUND && s.visible);
if (rectangle != null)
{
foreach (var styleMap in rectangle.styles)
{
if (rendererService.NodeProvider.TryGetStyle(styleMap.Value, out FigmaStyle style) &&
styleMap.Key == "fill")
{
code.WritePropertyEquality(outlineViewName, nameof(NSOutlineView.BackgroundColor), ColorService.GetNSColorString(style.name));
}
}
}
return code;
}