Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] redraw RoughUIView when the options are changed #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Sources/RoughSwift/Engine/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
14 changes: 13 additions & 1 deletion Sources/RoughSwift/RoughUIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down