Re: Determining width of a cell in an NSOutlineView
Re: Determining width of a cell in an NSOutlineView
- Subject: Re: Determining width of a cell in an NSOutlineView
- From: Corbin Dunn <email@hidden>
- Date: Mon, 05 Jan 2009 09:37:50 -0800
On Jan 5, 2009, at 8:56 AM, Eric Gorr wrote:
On Dec 19, 2008, at 6:03 PM, Corbin Dunn wrote:
On Dec 19, 2008, at 2:30 PM, Eric Gorr wrote:
I just need to know the width so I base the height on the width.
For that, you want to use -cellSizeForBounds: -- pass in a large
height, but a constrained width. Use a width that is equal to the
[tableColumn width] minus indentation * (level + 1) ---- although,
the actual value that outlineview uses for indentation is dependent
on some internal logic (ie: if you are using "group rows", or the
"source list highlighting style"). But, this should give you a
value that is fairly close to what you want.
I guess I spoke to soon. This doesn't actually seem to work.
I have the following code in my -outlineView:heightOfRowByItem:
method:
NSTableColumn *column = [outlineView outlineTableColumn];
NSUInteger nItems = [item count];
CGFloat indentation = [outlineView indentationPerLevel];
NSInteger level = [outlineView levelForItem:item];
NSRect bounds = NSMakeRect(0, 0, [column width],
10000);
NSCell *tableCell = [column dataCell];
CGFloat totalOffset = ( indentation * ( level + 1 ) );
NSSize cellSize = [tableCell
cellSizeForBounds:bounds];
NSUInteger nItemsPerRow = ( cellSize.width - totalOffset ) /
80;
Thanks for logging the bug (re: other response).
Your code has some problems; it is asking for the cellSize before
accounting for the indentation. You probably want:
...
CGFloat totalOffset = ( indentation * ( level + 1 ) );
bounds.size.width -= totalOffset; // corbin
NSSize cellSize = [tableCell cellSizeForBounds:bounds];
At this point, cellSize.height should give you a good height to return
from the -heightForRow: method.
Now here:
NSUInteger nItemsPerRow = ( cellSize.width - totalOffset ) /
80;
I'm confused what this is trying to do; maybe your ultimate goal is
different than what I think it is. I figure you are trying to find the
appropriate row height for a given cell so it won't get clipped
(something like what Console on Leopard does).
corbin
The width of the column is 711. However, cellSize.width is just
42.xx when it should be around 700 as well.
Any thoughts?
_______________________________________________
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