Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > NSTabViewItem subclass & displaying an icon..

NSTabViewItem subclass & displaying an icon..
Thread Tools
Senior User
Join Date: Nov 2000
Status: Offline
Reply With Quote
Sep 18, 2002, 10:20 PM
 
I wrote an NSTabViewItem subclass and attempted to use NSBrowserCell to do the drawing but I couldn't get it to draw correctly...

Then I figured out that I was blind and found the solution...
[removed question/wasted space]
(Last edited by IamBob; Sep 20, 2002 at 09:20 PM. )
     
IamBob  (op)
Senior User
Join Date: Nov 2000
Status: Offline
Reply With Quote
Sep 19, 2002, 02:38 PM
 
After doing some more testing I replied to myself with more code to look at...still blind here.
(Last edited by IamBob; Sep 20, 2002 at 09:22 PM. )
     
IamBob  (op)
Senior User
Join Date: Nov 2000
Status: Offline
Reply With Quote
Sep 19, 2002, 03:07 PM
 
I came, I saw...

I figured out that I should've just added a little width to the "tabRect" so the cell could keep drawing instead of getting clipped for no reason. I can't believe it took me so long to see it...grr..

My simple NSTabViewItem subclass (minus image getter&setter)..

Code:
- (void)dealloc { [tabCell release]; [super dealloc]; } - (id)initWithCoder:(NSCoder *)decoder { [super initWithCoder:decoder]; tabCell = [[NSBrowserCell alloc] initImageCell:[NSImage imageNamed:@"yourImage"]]; [tabCell setLeaf:YES]; [tabCell setFont:[[self tabView] font]]; [tabCell setStringValue: [self label]]; return self; } - (void)drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect { { // modify the rect a tad so the cell draws properly.. tabRect.origin.y += 2; tabRect.size.width += 16; } [tabCell drawWithFrame:tabRect inView:[self tabView]]; } - (NSSize)sizeOfLabel:(BOOL)shouldTruncateLabel { NSSize superSize = [super sizeOfLabel:shouldTruncateLabel]; NSImage *icon = [tabCell image]; superSize.width += [icon size].width-4; return superSize; }
I'll keep working on it since it won't work for left/right facing tabs and may not feel right for small tabs...

At least it's a start though.
[typo squashing]
(Last edited by IamBob; Sep 20, 2002 at 09:40 PM. )
     
IamBob  (op)
Senior User
Join Date: Nov 2000
Status: Offline
Reply With Quote
Sep 22, 2002, 02:36 PM
 
I've been trying to get it to draw properly for left/right facing tabs and I've run into some trouble using the code above with minor/unimportant mods...

According to the NSBrowserCell docs:
"[the image is] vertically centered on the left edge of the browser cell"

However, when it's drawn vertically (left-facing: bottom to top, right-facing: top to bottom) this isn't holding true.

For left-facing it's putting the icon off to the right -- not "vertically centered" but it is on the "left edge". For right-facing it's putting the icon off the top -- "vertically centered" but not on the "left edge".

I hope that makes sense to someone. It only "sort of" makes sense to me!

Here's some crappy screenshots to make it clearer..


Is this a bug in NSBrowserCell or am I asking too much of it? Should I give up and manage 2 cells instead of trying to get the NSBrowserCell to do it all?

As soon as I get this all working properly I hope to make it a palette for easy use. Anyone have links/info on doing that? Maybe I can get a jump on that..
(Last edited by IamBob; Sep 22, 2002 at 10:51 PM. )
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:48 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2