Welcome to MacForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Vertically center (NSLevelIndicator) Cell?

 
   Macintosh computer (Home) -> Programmer Help RSS
Next:  gcc error  
Author Message
slashlos

External


Since: Nov 13, 2005
Posts: 111



(Msg. 1) Posted: Sat Feb 09, 2008 5:59 pm
Post subject: Vertically center (NSLevelIndicator) Cell?
Archived from groups: comp>sys>mac>programmer>help (more info?)

In the IB palette (v3.0), it shows the various cells centered both
horizontally and vertically, but when used in a tableView, my cell
appears at the top, not vertically centered. Resizing the column only
auto-resizes the level cell elements.

Can you think of a way I can get the cell itself vertically centered as
in the IB palette?
--
/los "I was a teenage net-random."

 >> Stay informed about: Vertically center (NSLevelIndicator) Cell? 
Back to top
Login to vote
slashlos

External


Since: Nov 13, 2005
Posts: 111



(Msg. 2) Posted: Sat Feb 09, 2008 7:55 pm
Post subject: Re: Vertically center (NSLevelIndicator) Cell? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

slashlos wrote:
> In the IB palette (v3.0), it shows the various cells centered both
> horizontally and vertically, but when used in a tableView, my cell
> appears at the top, not vertically centered. Resizing the column only
> auto-resizes the level cell elements.
>
> Can you think of a way I can get the cell itself vertically centered as
> in the IB palette?

OK I subclassed NSLevelIndicatorCell to VALevelIndicatorcell taking a
cue from a similar issue with NSTextFieldCell as follows:

#import <Cocoa/Cocoa.h>
@interface VALevelIndicatorCell : NSLevelIndicatorCell
{
@private
BOOL _vAlign;
}
- (BOOL)isVerticallyAligned;
- (void)setVerticalAlignment:(BOOL)value;
@end

#import "VALevelIndicatorCell.h"
@implementation VALevelIndicatorCell
- (id) init
{
if (self = [super init])
{
_vAlign = TRUE;
}
return self;
}

- (void)drawWithFrame:(NSRect)frame inView:(NSView *)controlView
{
if (_vAlign)
{
int i = (frame.size.height - [self cellSize].height)/2;
frame.origin.y += i;
frame.size.height -= i;
}
[super drawWithFrame:frame inView:controlView];
}

- (BOOL) isVerticallyAligned
{
return _vAlign;
}

- (void) setVerticalAlignment:(BOOL)value
{
_vAlign = value;
}
@end

which visually appears centered but the cell doesn't respond to user
actions (i.e., acts like it's disabled). I had set the cell's class to
my class in IB, and primed the column's cell in my table view like this

- (void)awakeFromNib
{
// Vertically align our start column control
NSTableColumn * column = [tableView tableColumnWithIdentifier:@"1"];
VALevelIndicatorCell * cell = [column dataCell];
[cell setVerticalAlignment:YES];
}

So while I visually got the results I was seeking, the column's cell
isn't responsive; what'd I miss?
--
/los "I was a teenage net-random"

 >> Stay informed about: Vertically center (NSLevelIndicator) Cell? 
Back to top
Login to vote
slashlos

External


Since: Nov 13, 2005
Posts: 111



(Msg. 3) Posted: Thu Feb 21, 2008 8:09 pm
Post subject: Re: Vertically center (NSLevelIndicator) Cell? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

No one? I notice that even though in IB I set the class for the cell to
mine it won't appear in IB so I was thinking I need to create it in IB
and there's no book / how-to yet on that.

But in my awakeFromNib code the code I'd shown does get my cell
displayed but as I said earlier I can't seem to manipulate it. The class
features NSCopying and NSCoding support but I've since been stuck.

Help! TIA!!

--
/los "I was a teenage net-random"
 >> Stay informed about: Vertically center (NSLevelIndicator) Cell? 
Back to top
Login to vote
slashlos

External


Since: Nov 13, 2005
Posts: 111



(Msg. 4) Posted: Sat Feb 23, 2008 10:55 am
Post subject: Vertically center (NSLevelIndicator) Cell? redux [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Ok, let's try again, using

http://www.mikeash.com/?page=pyblog/custom-nscells-done-right.html

as a guide and the fix suggested for nested cells, I came up with this
sub-class of a level indicator:

#import <Cocoa/Cocoa.h>
@interface VALevelIndicatorCell : NSLevelIndicatorCell {} @end
@implementation VALevelIndicatorCell

+ (Class)cellClass
{
return [VALevelIndicatorCell class];
}

- (void)drawWithFrame:(NSRect)frame inView:(NSView *)controlView
{
int i = (frame.size.height - [self cellSize].height)/2;
frame.origin.y += i;
frame.size.height -= i;

[super drawWithFrame:frame inView:controlView];
}
@end

While I find my draw method does get called, and the cell does get drawn
centered, no user interaction is possible.

This may or may not be related but I notice that the <go to counterpart>
button for my header goes nowhere, while viewing the .m sources does!

Short or rebuilding the class, is there a way to mend a counterpart's
linkage (header or source)?
--
/los "I was a teenage net-random"
 >> Stay informed about: Vertically center (NSLevelIndicator) Cell? 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
how do I flip a bezierpath vertically? - I can't find a nsaffinetransform function to do a vertical flip on a bezier path. Is there one hiding somewhere? Or is there another simple way to flip a path? It is made up of straight lines, all connected, in a closed path, if that makes it easier. ..

carbon, can't center text - Hi, I'm using Xcode to make a carbon app and trying to display some text centered in a rect which, in Windoze is so simple but so difficult on the Mac. dc-&gt;DrawText("myText", myRect, DT_CENTER); I've tried TextWidth and StringWidth b...

NSString in NSDateFormat'ed cell - Hi, can anyone suggest a quick way to show an NSString in an NSTableView cell that has been formatted as an NSDateFormat ? It's a dynamic special case scenario -- i.e., after a button press, it's possible that there will be a date upon reloading data. ....

cell data doesn't appear in my NSTableView - Hey all, I'm having trouble populating my NSTableView. I read a file in and dynamically create columns pending on the number of cols in a file, then further down add rows of data for each column. But my data doesn't appear. The correct number of columns...

Multiple cell types per tableColumn? - In presenting a row set / table for editing, rather than a single column cell type such as textcell or comboBox, could you present a different cell type per row? I.e, each rows 'value' cell for some values, allow simple textcell for list..
   Macintosh computer (Home) -> Programmer Help All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]