Untitled - MARKUP 1.65 KB
                                
                                    if let figure = selectedFigure {
                ShapePreview(figure: figure, fillColor: fillColor, widthText: widthText, heightText: heightText, showBorder: showBorder)
                    .padding()
            }

// ShapePreview.swift

import SwiftUI

struct ShapePreview: View {
    var figure: FigurePickerElement
    var fillColor: Color
    var widthText: String
    var heightText: String
    var showBorder: Bool
    
    var body: some View {
        VStack {
            switch figure.name {
            case "Circle":
                Circle()
                    .fill(fillColor)
                    .frame(width: CGFloat(dataForView.stringToCGFloat(widthText)), height: CGFloat(dataForView.stringToCGFloat(heightText)))
                    .overlay(showBorder ? Circle().stroke(Color.black, lineWidth: 2) : nil)
            case "Square":
                Rectangle()
                    .fill(fillColor)
                    .frame(width: CGFloat(dataForView.stringToCGFloat(widthText)), height: CGFloat(dataForView.stringToCGFloat(heightText)))
                    .overlay(showBorder ? Rectangle().stroke(Color.black, lineWidth: 2) : nil)
            case "Ellipse":
                Ellipse()
                    .fill(fillColor)
                    .frame(width: CGFloat(dataForView.stringToCGFloat(widthText)), height: CGFloat(dataForView.stringToCGFloat(heightText)))
                    .overlay(showBorder ? Ellipse().stroke(Color.black, lineWidth: 2) : nil)
            default:
                Text("Invalid figure")
            }
        }
    }
}
                                
                            

Paste Hosted With By Wklejamy.pl