Skip to content

Gradient stop percentage #1

@Amzd

Description

@Amzd

A gradients stops can have a percentage to specify where the color starts.

For example, these are the same:

linear-gradient(red, orange, yellow, green, blue); 
linear-gradient(red 0%, orange 25%, yellow 50%, green 75%, blue 100%);

Currently the gradient cases on Color only receive [Color] as stops.

I think there should be a Color case that looks something like:

case linearGradient(_ direction: LinearGradient.Direction, _ stops: [(Color, Int)])

or:

case linearGradient(_ direction: LinearGradient.Direction, _ stops: [ColorStop])

// ...

public struct ColorStop: CustomStringConvertible {
    let color: Color
    let positions: [Int]

    public var description: String {
        color.description + positions.map { String($0) + "%" } .joined(separator: " ")
    }

    public static func color(_ color: Color, at percentages: Int...) -> ColorStop {
        return ColorStop(color: color, positions: percentages)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions