public static void Configure(this Xamarin.Forms.View view, RectangleVector child) { Configure(view, (FigmaVectorEntity)child); //if (child.HasFills && child.fills[0].color != null) //{ // view.BackgroundColor = child.fills[0].color.ToFormsColor(); //} }
public static void Configure(this NSView view, RectangleVector child) { Configure(view, (FigmaVectorEntity)child); //var shapeLayer = new CAShapeLayer //{ // Path = NSBezierPath.FromRect(view.Bounds).ToCGPath(), // Frame = view.Layer.Frame //}; //view.Layer = shapeLayer; //var fill = child.fills?.FirstOrDefault(); //if (fill != null && fill.visible && fill.color != null) //{ // shapeLayer.FillColor = fill.color.MixOpacity (fill.opacity).ToNSColor().CGColor; //} else //{ // shapeLayer.FillColor = NSColor.Clear.CGColor; //} //if (child.strokeDashes != null) //{ // var number = new NSNumber[child.strokeDashes.Length]; // for (int i = 0; i < child.strokeDashes.Length; i++) // { // number[i] = child.strokeDashes[i]; // } // shapeLayer.LineDashPattern = number; //} ////shapeLayer.BackgroundColor = child.col //shapeLayer.LineWidth = child.strokeWeight * 2; //var strokes = child.strokes.FirstOrDefault(); //if (strokes != null && strokes.visible) //{ // if (strokes.color != null) // { // shapeLayer.StrokeColor = strokes.color.MixOpacity (strokes.opacity).ToNSColor().CGColor; // if (shapeLayer.LineWidth == 0) // { // shapeLayer.LineWidth = 1f; // } // } //} //shapeLayer.CornerRadius = child.cornerRadius; //view.AlphaValue = child.opacity; }
public static void Configure(this FrameworkElement view, RectangleVector child) { Configure(view, (FigmaVectorEntity)child); //view.Layer.CornerRadius = child.cornerRadius; }
public static void Configure(this StringBuilder builder, string name, RectangleVector child) { Configure(builder, name, (FigmaVectorEntity)child); builder.AppendLine(string.Format("{0}.Layer.CornerRadius = {1};", name, child.cornerRadius.ToDesignerString())); }
protected override IView OnConvertToView(FigmaNode currentNode, ViewNode parentNode, ViewRenderService rendererService) { var frame = (FigmaFrame)currentNode; var box = new NSBox(); currentNode.TryGetNativeControlType(out FigmaControlType controlType); if (controlType == FigmaControlType.Separator) { box.BoxType = NSBoxType.NSBoxSeparator; } if (controlType == FigmaControlType.BoxCustom) { box.BoxType = NSBoxType.NSBoxCustom; box.BorderWidth = 0; RectangleVector rectangle = frame.children .OfType <RectangleVector>() .FirstOrDefault(); if (rectangle != null) { if (rectangle.styles != null) { foreach (var styleMap in rectangle.styles) { if (rendererService.NodeProvider.TryGetStyle(styleMap.Value, out FigmaStyle style)) { if (styleMap.Key == "fill") { box.FillColor = ColorService.GetNSColor(style.name); } if (styleMap.Key == "stroke") { box.BorderColor = ColorService.GetNSColor(style.name); box.BorderWidth = rectangle.strokeWeight; } } } } box.CornerRadius = rectangle.cornerRadius; } } if (controlType == FigmaControlType.Box) { FigmaText text = frame.children .OfType <FigmaText>() .FirstOrDefault(s => (s.name == ComponentString.TITLE && s.visible)); if (text != null) { box.Title = rendererService.GetTranslatedText(text); } else { box.Title = string.Empty; } } return(new View(box)); }
protected override StringBuilder OnConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService rendererService) { var code = new StringBuilder(); var frame = (FigmaFrame)currentNode.Node; currentNode.Node.TryGetNativeControlType(out FigmaControlType controlType); currentNode.Node.TryGetNativeControlVariant(out NativeControlVariant controlVariant); if (rendererService.NeedsRenderConstructor(currentNode, parentNode)) { code.WriteConstructor(currentNode.Name, GetControlType(currentNode.Node), rendererService.NodeRendersVar(currentNode, parentNode)); } if (controlType == FigmaControlType.Separator) { code.WritePropertyEquality(currentNode.Name, nameof(NSBox.BoxType), NSBoxType.NSBoxSeparator); } if (controlType == FigmaControlType.BoxCustom) { code.WritePropertyEquality(currentNode.Name, nameof(NSBox.BoxType), NSBoxType.NSBoxCustom); RectangleVector rectangle = frame.children .OfType <RectangleVector>() .FirstOrDefault(); if (rectangle != null) { if (rectangle.styles != null) { bool borderSet = false; foreach (var styleMap in rectangle.styles) { if ((rendererService.NodeProvider is NodeProvider nodeProvider) && nodeProvider.TryGetStyle(styleMap.Value, out FigmaStyle style)) { if (styleMap.Key == "fill") { code.WritePropertyEquality(currentNode.Name, nameof(NSBox.FillColor), ColorService.GetNSColorString(style.name)); } if (styleMap.Key == "stroke") { code.WritePropertyEquality(currentNode.Name, nameof(NSBox.BorderColor), ColorService.GetNSColorString(style.name)); code.WritePropertyEquality(currentNode.Name, nameof(NSBox.BorderWidth), rectangle.strokeWeight.ToString()); borderSet = true; } } } if (!borderSet) { code.WritePropertyEquality(currentNode.Name, nameof(NSBox.BorderWidth), "0"); } } code.WritePropertyEquality(currentNode.Name, nameof(NSBox.CornerRadius), rectangle.cornerRadius.ToString()); } } FigmaText text = null; if (frame.children != null) { text = frame.children .OfType <FigmaText>() .FirstOrDefault(s => (s.name == ComponentString.TITLE && s.visible)); } if (text != null) { code.WriteTranslatedEquality(currentNode.Name, nameof(NSBox.Title), text.characters, rendererService); } else { code.WritePropertyEquality(currentNode.Name, nameof(NSBox.Title), string.Empty, inQuotes: true); } return(code); }