2008 05 26Zero Opacity Trick
- draw whatever kind of control you want in Photoshop
- overlay a zero opacity control over it
- then your custom control will behave like the one you're styling : the browser handles mouse clicks for transparent elements just as if they were fully visible.
And, we can do the same in Cocoa ! Namely, put a transparent control over a custom view and have the custom view behave as that transparent control.
In that case, I wanted to have that context menu pop exactly underneath that gray view. Couldn't figure out how to do it, tried the CSS zero opacity trick, and … it almost worked, trailing some repainted trash behind. After enabling Core Animation for the gray view, everything worked OK.
There must be some better way of doing that :), but it's pretty amazing to see how well JS+CSS concepts are close to Cocoa's.Ah yes, using NSPopUpButtonCell's attachPopUpWithFrame:inView: allows you to specify a rect. I hadn't seen that. Thank you !
That is a very cool idea, but I'm torn because AppKit has never assured that overlapping views work. The Adding and Removing Views from a Hierarchy part of the View Programming Guide warns against it.
In practice, though, I've done this before too.
Yes, we need to be careful about overlapping : I had an NSTableView slightly overlapping an NSBox, it repainted over the NSBox on scroll.
Note that in this case it worked well only when Core Animation was enabled.
//
I just got back to that overlapping NSBox, enabling Core Animation removes any repainting problems too. Nice :)
I would think that the better way would be to include an NSPopupButtonCell that you don't draw but still pass mouse events to.