Question

I'm writing a Cocoa application that displays the contents of an archive file in an NSOutlineView. I provide custom icons for an NSBrowserCell in the outline column, but I haven't been able to get the spacing quite right — the folder icon always appears too close to the disclosure triangle, as shown below. (FWIW, Versions and BetterZip both display similar data without the spacing issues.)

NSOutlineView-icon-spacing http://img.skitch.com/20090918-tgfjh9x8dhgqxqnb2su8fby4ng.jpg

Since only folder icons will have this problem, I really only care about fixing the spacing in that context. (NOTE: I'm already caching the icons for reuse, so I have no problem with manipulating the folder image if necessary, since it will only happen once anyway.) I'm not sure if there's something I can adjust in the NSBrowserCell instance, but I haven't found anything that works yet, not for lack of trying.


For the curious, JarScan is a handy (free) command-line tool for locating Java classes within JAR files.

Was it helpful?

Solution

The "outline table column" (see -[NSOutlineView outlineTableColumn]) is the NSTableColumn that draws the triangle and left padding as needed to display the hierarchy. The default cell for displaying table content is an NSTextFieldCell. To increase the spacing you see, you have to do the drawing in a custom NSTextFieldCell subclass. The spacing is achieved by drawing your image with an x offset. (The outline view will draw the disclosure triangle regardless of which NSCell subclass is used.)

Note that you may have to override the following methods to draw correctly when the cell can be typed in, selected for editing, and the tooltip:

By default your custom text rects will be ignored by the text field and these will draw oddly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top