[FEAT] LinearGradient, RadialGradient & AngularGradient#450
[FEAT] LinearGradient, RadialGradient & AngularGradient#450MiaKoring wants to merge 28 commits intomoreSwift:mainfrom
Conversation
|
Related issue: #427 |
|
The new commit now offers full API parity to SwiftUI on AngularGradient and correctly renders all 6 test gradients. “Correct” meaning looking like the SwiftUI rendered result. All 3 supported frameworks recieved this change and the shared screenshots were updated. |
|
Outstanding Tasks have been completed, this can now be reviewed and merged |
stackotter
left a comment
There was a problem hiding this comment.
Thanks for tackling this feature! I've reviewed all of the code now, but I haven't tested anything locally yet. I plan to construct a SwiftUI app with a bunch of edge cases that I have thought of, and then compile that with your PR and ensure that all of the edge cases act the same across platforms. It should be a useful tool to help you address some of my PR comments too. I likely won't get around to doing that today though.
# Conflicts: # Examples/Bundler.toml # Examples/Package.resolved # Examples/Package.swift # Package.resolved # Package.swift # Sources/SwiftCrossUI/Backend/AppBackend.swift
|
conflicts should be resolved now, same for all requested changes without open discussion |
stackotter
left a comment
There was a problem hiding this comment.
Thanks for applying all that feedback! I've got a few more things, but I think most of them are relatively small things this time (organisation, documentation, etc). I don't have time to test things locally right now, but I will try to do that soon, because I may be able to resolve some of my own questions and comments by testing out the edge cases that I'm worried about.
|
|
||
| #if DEBUG | ||
| if range < 0 { | ||
| logger.warning( |
There was a problem hiding this comment.
I think it's easy enough for us to support right? Because we can just automatically reverse the gradient. Use cases where it's probably most applicable would be graphical editors where the user is entering the radii with draggable handles or something similar. I assume some backends that don't use adjustedStops may already support having the radii swapped?
| ) { | ||
| let widget = widget as! GradientView | ||
| widget.setGradientLayer( | ||
| to: CAGradientLayer.angularGradientLayer( |
There was a problem hiding this comment.
I think that the stretching would also effect the angles of the radial lines of equal colour in conic gradients? My assumption is that SwiftUI doesn't do that, but maybe it does
|
GtkBackend will not support the AngularGradient type right now due to rendering inconsistencies with SwiftUI and the Apple Backends which are not easily resolvable. For future reference if needed: public func createAngularGradient() -> Widget {
Box()
}
public func updateAngularGradient(
_ widget: Widget,
gradient: AngularGradient,
withSize size: SIMD2<Int>,
in environment: EnvironmentValues
) {
let widget = widget as! Box
let adjustedStops = gradient.adjustedStops
let stops = adjustedStops.map { stop in
let resolved = stop.color.resolve(in: environment)
let red = resolved.red * 255
let green = resolved.green * 255
let blue = resolved.blue * 255
let location = stop.location * 360
return "rgba(\(red), \(green), \(blue), \(resolved.opacity)) \(location)deg”
}.joined(separator: ", “)
let startDegrees = gradient.startAngle.degrees + 90
let centerXPercent = gradient.center.x * 100
let centerYPercent = gradient.center.y * 100
widget.css.set(
property: .init(
key: “background”,
value: “””
conic-gradient(from \(startDegrees)deg \
at \(centerXPercent)% \(centerYPercent)%, \
\(stops))
“””
)
)
} |
…to feat/gradient # Conflicts: # Examples/Package.resolved
…oss-ui into feat/gradient
|
I believe I’m caught up. main is merged again too. |






Summary
Added support for 3 types of gradients to be rendered as Views:
Changes
SwiftCrossUI
AppBackendprotocol.ElementaryViewstruct for each type of gradient.Angleintended for use byAngularGradientlaterAnglefrom aUnitPointUnitPoint, meant to represent a normalized point in a view’s coordinate spaceUnitPoints are not clamped, so you can use them with arbitrary values to benefit for example fromAngle(origin:destination:)Gradient, used by all implementations of a Gradient, its a gradient type agnostic representation of a color gradientGradient.Stoprepresenting a color and its normalized position in the gradient[Color]or[Gradient.Stop]AppKitBackend, UIKitBackend
AppBackendmethodsWinUI, GtkBackend
AppBackendmethods related toLinearGradientandRadialGradientSwiftCrossUITests
Gradient[Color]Color(to make future support of addition possible and remove edgecases to check outside ofGradient)[Color]with one entryExamples
LinearGradientRadialGradientAngularGradientNotes
ShapeStylecould easily re-use the added structs tho.TODO / Status
RadialGradientsupport to WinUIBackend (pending RadialGradientBrush generation)RadialGradient