Skip to content

Instantly share code, notes, and snippets.

@krzyzanowskim
Last active October 24, 2020 10:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krzyzanowskim/1ca0e13edec6fd43d235d0a344f831b8 to your computer and use it in GitHub Desktop.
Save krzyzanowskim/1ca0e13edec6fd43d235d0a344f831b8 to your computer and use it in GitHub Desktop.
FB8820682: Since when NSView.setNeedsDisplayInRect does not affects drawRect rectangle
// macOS 11.0 (20A5395g)
// Xcode 12.2 beta 3 (12B5035g)
class MyView: NSView {
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) {
let rect = NSRect(x: 10, y: 10, width: 10, height: 10)
print("setNeedsDisplay \(rect)")
self.setNeedsDisplay(rect)
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override var isOpaque: Bool {
true
}
override func draw(_ dirtyRect: NSRect) {
print("dirtyRect \(dirtyRect)")
var rects: UnsafePointer<NSRect>?
var count = Int()
getRectsBeingDrawn(&rects, count: &count)
for i in 0..<count {
print("rectBeingDrawn \(rects![i])")
}
super.draw(dirtyRect)
}
}
/*
dirtyRect (0.0, 0.0, 932.0, 640.0)
rectBeingDrawn (0.0, 0.0, 932.0, 640.0)
setNeedsDisplay (10.0, 10.0, 10.0, 10.0) <----------
dirtyRect (0.0, 0.0, 932.0, 640.0)
rectBeingDrawn (0.0, 0.0, 932.0, 640.0)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment