diff --git a/Sources/RoughSwift/Engine/Options.swift b/Sources/RoughSwift/Engine/Options.swift index 3d6ec26..fcd9a7e 100644 --- a/Sources/RoughSwift/Engine/Options.swift +++ b/Sources/RoughSwift/Engine/Options.swift @@ -72,3 +72,27 @@ public extension Options { fill <-? (dictionary["fill"] as? String).map(UIColor.init(hex:)) } } + +extension Options: Hashable { + public static func == (lhs: Options, rhs: Options) -> Bool { + lhs.hashValue == rhs.hashValue + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(maxRandomnessOffset) + hasher.combine(roughness) + hasher.combine(bowing) + hasher.combine(fill) + hasher.combine(stroke) + hasher.combine(strokeWidth) + hasher.combine(curveTightness) + hasher.combine(curveStepCount) + hasher.combine(fillStyle) + hasher.combine(fillWeight) + hasher.combine(hachureAngle) + hasher.combine(hachureGap) + hasher.combine(dashOffset) + hasher.combine(dashGap) + hasher.combine(zigzagOffset) + } +} diff --git a/Sources/RoughSwift/RoughUIView.swift b/Sources/RoughSwift/RoughUIView.swift index 99a8add..3505c6c 100644 --- a/Sources/RoughSwift/RoughUIView.swift +++ b/Sources/RoughSwift/RoughUIView.swift @@ -10,7 +10,19 @@ import UIKit final class RoughUIView: UIView { var drawbles: [Drawable]? - var options: Options? + + var options: Options? { + didSet { + guard options != oldValue else { + return + } + guard let drawbles, let options else { + return + } + update(drawables: drawbles, options: options) + } + } + var previousBounds: CGRect = .zero override func layoutSubviews() {