floats in AppKit
Recently I wanted to automatically center a NSView inside a window. But the buttons inside this view were displayed pretty strange:
You can see, the buttons and the textfield are drawn blurred and the buttons have a stripe on both sides of their label.
It took me quite some hours to figure out what was going wrong, but then I found the bug: floats with a fraction portion.
AppKit uses floats all over the place, but it seems those floats have to be truncated in order to draw the view properly. After using truncf(aFloat) everything was displayed as one could expect it:
I attached a sample project to this post, so you can have a look yourself.
May 17th, 2007 at 12:42
I’ve also had trouble with weird rendering bugs in WebView when NSViews in NSSplitView were floats. So I guess as a general rule its good to round off all your view demensions.
June 20th, 2007 at 12:59
Hmm, that really does look strange…
Rather than use truncf I would try NSIntegralRect(). It might even be designed just for these kinds of situations?
June 20th, 2007 at 13:16
thx a lot for the hint Patrick, I didn’t see that function 😉