ShapeStyle+LinearGradient

// 2022.02.08 + .vertical(), .horizontal(), .diagonal(), .diagonal2()

// -------------------
//     ShapeStyle+
// -------------------

import SwiftUI

extension ShapeStyle where Self == LinearGradient {
    
    /// vertical linear gradient (โ†“)
    /// ```
    /// (ShapeStyle).vertical(.green, .blue)
    /// ```
    public static func vertical(_ colors: Color...) -> LinearGradient {
        linearGradient(colors: colors, startPoint: .top, endPoint: .bottom)
    }
    
    /// horizontal linear gradient (โ†’)
    /// ```
    /// (ShapeStyle).horizontal(.green, .blue)
    /// ```
    public static func horizontal(_ colors: Color...) -> LinearGradient {
        linearGradient(colors: colors, startPoint: .leading, endPoint: .trailing)
    }
    
    /// (major) diagonal linear gradient (โ†˜๏ธŽ)
    /// ```
    /// (ShapeStyle).diagonal(.green, .blue)
    /// ```
    public static func diagonal(_ colors: Color...) -> LinearGradient {
        linearGradient(colors: colors, startPoint: .topLeading, endPoint: .bottomTrailing)
    }
    
    /// (minor) diagonal linear gradient (โ†—๏ธŽ)
    /// ```
    /// (ShapeStyle).diagonal2(.green, .blue)
    /// ```
    public static func diagonal2(_ colors: Color...) -> LinearGradient {
        linearGradient(colors: colors, startPoint: .bottomLeading, endPoint: .topTrailing)
    }
}

Last updated