I have lately bumped into the new Sonoma clipsToBounds
behaviour. I must be missing something obvious, but it seems to me the current documentation now is at best misleading (if not plain wrong), and also it seems to me — far as the documentation is to be trusted — there's not any easy way to implement drawRect:
anymore.
I'd be grateful is Quinn or anybody, who understands this properly, explains. Here are my problems:
- The
drawRect:
documentation, at this moment, says pretty explicitly
[dirty] rect ... The portion of the view’s bounds that needs to be updated. The first time your view is drawn, this rectangle is typically the entire visible bounds of your view. However, during subsequent drawing operations, the rectangle may specify only part of your view
This seems to me to be at odds with the Sonoma reality that the dirty rect now is allowed to extend beyond the geometry of the view itself. Do I understand it wrong?
This feels to me a documentation bug, looks like pre-Sonoma documentation which was not updated accordingly to the new behaviour, but as always, I can be wrong.
- Worse is, how do we implement
drawRect:
now (presumed we want to stick with the new clipsToBounds
behaviour)?
Let's say we want simply a coloured background, the thing which pre-Sonoma was rightly and properly implemented by
[colour set]; NSRectFill(dirtyRect);
The release notes suggest we simply replace it with [colour set]; NSRectFill(self.bounds);
— This pattern can be adjusted by filling the bounds instead of the dirty rect, but — do please correct me if I am missing something of importance — this seems to be at odds with the drawRect:
documentation, which very explicitly states (the above, and)
You should limit any drawing to the rectangle specified in the rect
parameter
Given we draw whole self.bounds
as suggested, and given the dirty rect very definitely can specify only part of our view, it seems plain wrong.
Actually, the sentence quoted above feels very strange to me. Far back as I can recall, it always used to be pretty usual to draw outside of the dirty rect (but inside of bounds).
I might have missed something of importance somewhere, but I've always though the dirty rect is just an optimising tool, which allow us to simplify complex drawing skipping anything which does not intersect it; but we should draw all parts which do intersect the dirty rect even if they exceed it (which many of them usually do). Besides, in simple cases, we can safely ignore the dirty rect completely and just fill the bounds as need be.
Is that not so anymore in Sonoma? I cannot recall the “You should limit any drawing...” sentence quoted above in the older documentation, but I might recall it wrong. Anyway, if that sentence is really meant to be taken into account, it seems to me we should always explicitly clip all our drawing to both bounds
and dirty rect, which sometimes might be a bit non-trivial?
Thanks for any elucidation,
OC