Prevent Horrendously Wide NSBrowserCell Tool Tips

212 views Asked by At

I am setting my NSBrowser matrix cells' tool tips with the below code:

- (void) browser:(NSBrowser *)sender willDisplayCell:(id)cell atRow:(int)row column:(int)column  {  
    NSMatrix *matrix = [sender matrixInColumn:column];
    NSLog(@"'%@'", [cell title]);
    [matrix setToolTip:[cell title] forCell:[matrix cellAtRow:row column:column]];    
}

This results in wonderful tool tips, most of the time.

When hovering some cells, however, the tool tip expands to a grotesque width, transforming an otherwise delightful experience into one that is as hideous as it is confusing. The screenshot below shows this horrible behaviour.

Wide load

The output for the cell triggering the heinous tool tip pictured above is:

'gnome-1.1-tb-linux.jar'

What could be causing these seemingly random atrocities - am I missing something obvious?

1

There are 1 answers

0
Michael Robinson On BEST ANSWER

A solution that worked for me in this case was to implement - (NSRect)expansionFrameWithFrame:(NSRect)cellFrame inView:(NSView *)view in my NSBrowserCell subclass as below:

- (NSRect)expansionFrameWithFrame:(NSRect)cellFrame inView:(NSView *)view {
    NSSize size = [self.tooltipText sizeWithAttributes:@{
                       NSFontAttributeName: [NSFont systemFontOfSize:[NSFont systemFontSize]]
                   }];
    // Expansion frame displays below and indented to the right in relation to the cellFrame
    NSRect rect = NSMakeRect(cellFrame.origin.x + 10, cellFrame.origin.y + size.height, size.width, size.height);
    return rect;
}