Re: Drawing a badge in an OutlineView column cell: but width changes on expanding
Re: Drawing a badge in an OutlineView column cell: but width changes on expanding
- Subject: Re: Drawing a badge in an OutlineView column cell: but width changes on expanding
- From: Stuart Malin <email@hidden>
- Date: Tue, 24 Feb 2009 11:44:29 -1000
On Feb 24, 2009, at 10:51 AM, Corbin Dunn wrote:
On Feb 24, 2009, at 12:38 PM, Stuart Malin wrote:
I have been reading various blogs, tried to search CocoaBuilder,
and have ben looking at the code in Apple's PhotoSearch sample, but
am not clear about the best way to handle this situation:
I have an NSOutlineView for which I have set a custom cell (sub
class of NSTextViewCell) in order to draw a badge on the right side
of the cell.
I have overridden drawInteriorWithFrame:controlView: to do my
drawing there. It seems to me that when a row that has descendent
nodes is expanded, the width of the hierarchically containing cells
(lower level value) are made wider (by the same amount as the
indentation). Both the indented cells (by their indentation) and
the higher order cells (by the increased cell width) now have their
right side pushed partway out of the viewable area of the column.
So, I can't determine the x position of the badge based upon the
width of the cell (a hierarchically outer cell with no indent has
an increased width, yet to calculate a proper x coordinate, the
cell would need to know that some other table items are expanded;
how could it "know" this?)
My best idea so far is to determine the position based on the table
column's width, and take into account the indent level. But I
suspect there are any of a number of ways to handle this, and so am
looking for guidance on a best practice from those with experience.
TIA.
You should just draw the badge in -drawInteriorWithFrame, and
everything should work provided you are right-aligning it with the
frame passed to you. What does your code look like? Maybe it has
some errors/problems.
Thanks for replying so quickly, Corbin. My code for drawing the badge
is relatively straightforward. But... to get a handle on the problem,
I am not presently drawing it. I have greatly simplified my code, and
all ll I do now is:
1) in the -init for the cell, I set -setBordered So I can see the size
of the cell.
- (id) init {
self = [super init];
if (self != nil) {
[self setLineBreakMode:NSLineBreakByTruncatingTail];
[self setBordered:YES];
2) and I have trivialized -drawInteriorWithFrame
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:
(NSView*)controlView
{
[super drawInteriorWithFrame:cellFrame inView:controlView];
return;
3) When I run, I get what I consider to be weird behavior:
a) When the app first starts and displays, the borders of the level 0
entries (none are expanded) are completely visible.
b) when I expand a level 0 item, the borders for all cells (level 0
and level 1) are no longer visible on the right side.
c) the OutlineView is in a splitter. If I move the splitter to expand
the outline view's width, when I release, the right side of the cell
borders are all visible (both level 0 and level 1 items), and are
nearly flush to the right side of the column. Nice.
d) If I then collapse the expanded item, all of the cells borders are
visible, but the cell width is noticeably smaller than the column's
width.
I've just published a blog that has screen shots of these states:
http://stuartmalin.blogspot.com/2009/02/troubles-with-cocoa-custom.html
So, what I am seeing is that the cell's width fluctuates
inconsistently with respect to the column's width, sometimes being
nicely bound to the column's right side, sometimes extending beyond,
and sometimes being too short.
I am on Leopard 10.5.6 using Xcode 3.1.1; Target: Base SDK = Mac OS 10.5
_______________________________________________
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