Re: NSColorWell inside a custom NSCell
Re: NSColorWell inside a custom NSCell
- Subject: Re: NSColorWell inside a custom NSCell
- From: Graham Cox <email@hidden>
- Date: Fri, 22 Apr 2011 10:52:24 +1000
On 21/04/2011, at 4:17 PM, Bryan Hansen wrote:
> Am I on the right track with this? Is there a better way to get a bunch of movable colorwells within a custom control?
I'd say no, you're not on the right track and yes, there's a better way.
What you're attempting is probably doable, but the purpose of cells is to allow their re-use in a number of different situations - buttons, tables, matrices and so on. Since you're just making a custom control for a single purpose, using cells is just a lot of extra effort without a benefit (not to mention the extensive and ad-hoc nature of the NSCell API which invariable needs much customisation for every new situation).
I've written a gradient control similar to what you're doing, with movable colour wells inside a bar. The original implementation used cells and it was a complex, overwrought mess. I later rewrote it as a single custom NSView which reduced the amount of code by 60% or so, and it worked a lot better (a good sign that you are doing it right!). The movable wells were simply elements drawn as needed in the right places. I did need to perform some tricks to get them to interact with the usual instances of NSColorWell in terms of getting the focus of the color panel - originally I did this using swizzling but when that was deprecated I did it some other way (the details momentarily escape me, but it "played nice").
If you are interested in my implementation, I'm happy to share the code - contact me offlist. There are numerous problems you'd need to solve if you rolled your own - for example, since the movable well has some rectangular size, it's possible for two or more of these to overlap within the overall control. You need to handle that, as well as the already mentioned issue of getting Color Panel focus in conjunction with any other NSColorWell instances that exist in your app.
You can preview the design here: http://gradientpanel.com/ though that project is pretty much dead, and uses the old complex design. The revised one looks the same however.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden