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: Eric Gorr <email@hidden>
- Date: Mon, 5 Jan 2009 12:59:01 -0500
On Jan 5, 2009, at 12:37 PM, Corbin Dunn wrote:
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).
Ah, I think there has been a miscommunication.
I ultimately need to be able to compute the height of the cell based
on the width. Based on your reply, it looks like I can determine the
width of the cell merely by doing:
NSTableColumn *column = [outlineView outlineTableColumn];
CGFloat totalCellWidth = [column width] - ( indentation *
( level + 1 ) );
The height of the cell should be based on that value so nItems with
nItemsPerRow can fit entirely inside of the cell. Each item I am
drawing will be 80x80 pixels.
It would seem that what I need to do does not require the use of -
cellSizeForBounds:.
_______________________________________________
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