- briksoftware Blog - https://briksoftware.com/blog -

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.

sample project [1]