@@ -343,6 +343,11 @@ - (NSRect)iconRectForBounds:(NSRect)theRect ofTabCell:(PSMTabBarCell *)cell {
343
343
344
344
- (NSRect )titleRectForBounds : (NSRect )theRect ofTabCell : (PSMTabBarCell *)cell {
345
345
346
+ // Don't bother calculating anything if we don't have a string
347
+ NSAttributedString *attrString = [cell attributedStringValue ];
348
+ if ([attrString length ] == 0 )
349
+ return NSZeroRect ;
350
+
346
351
PSMTabBarControl *tabBarControl = [cell controlView ];
347
352
PSMTabBarOrientation orientation = [tabBarControl orientation ];
348
353
@@ -361,37 +366,35 @@ - (NSRect)titleRectForBounds:(NSRect)theRect ofTabCell:(PSMTabBarCell *)cell {
361
366
constrainedDrawingRect.size .width -= kPSMAdiumImageWidth + kPSMTabBarCellPadding ;
362
367
}
363
368
369
+ NSRect closeButtonRect = [cell closeButtonRectForBounds: theRect];
370
+ NSRect counterBadgeRect = [cell objectCounterRectForBounds: theRect];
371
+ NSRect iconRect = [cell iconRectForBounds: theRect];
372
+ CGFloat maxIconOrClose = MAX (NSWidth (closeButtonRect),NSWidth (iconRect));
364
373
if (orientation == PSMTabBarHorizontalOrientation) {
365
374
366
- NSRect closeButtonRect = [cell closeButtonRectForBounds: theRect];
367
- NSRect iconRect = [cell iconRectForBounds: theRect];
368
-
369
375
if (!NSEqualRects (closeButtonRect, NSZeroRect ) || !NSEqualRects (iconRect, NSZeroRect )) {
370
- constrainedDrawingRect.origin .x += MAX ( NSWidth (closeButtonRect), NSWidth (iconRect)) + kPSMTabBarCellPadding ;
371
- constrainedDrawingRect.size .width -= MAX ( NSWidth (closeButtonRect), NSWidth (iconRect)) + kPSMTabBarCellPadding ;
376
+ constrainedDrawingRect.origin .x += maxIconOrClose + kPSMTabBarCellPadding ;
377
+ constrainedDrawingRect.size .width -= maxIconOrClose + kPSMTabBarCellPadding ;
372
378
}
373
379
374
- NSRect counterBadgeRect = [cell objectCounterRectForBounds: theRect];
375
380
if (!NSEqualRects (counterBadgeRect, NSZeroRect )) {
376
381
constrainedDrawingRect.size .width -= NSWidth (counterBadgeRect) + kPSMTabBarCellPadding ;
377
382
}
378
383
} else {
379
384
380
- NSRect closeButtonRect = [cell closeButtonRectForBounds: theRect];
381
- NSRect counterBadgeRect = [cell objectCounterRectForBounds: theRect];
382
-
383
385
if (!NSEqualRects (closeButtonRect, NSZeroRect ) || !NSEqualRects (counterBadgeRect, NSZeroRect )) {
384
- constrainedDrawingRect.size .width -= MAX (NSWidth (closeButtonRect) ,NSWidth (counterBadgeRect)) + kPSMTabBarCellPadding ;
385
- }
386
+ constrainedDrawingRect.size .width -= MAX (maxIconOrClose ,NSWidth (counterBadgeRect)) + kPSMTabBarCellPadding ;
387
+ }
386
388
}
387
389
390
+ // Don't show a title if there's only enough space for a character
388
391
if (constrainedDrawingRect.size .width <= 2 )
389
392
return NSZeroRect ;
390
393
391
- NSAttributedString *attrString = [cell attributedStringValue ];
392
- if ([attrString length ] == 0 )
393
- return NSZeroRect ;
394
-
394
+ // Make sure there's enough padding between the icon/close button and the text
395
+ if (NSMaxX (constrainedDrawingRect)- MAX ( NSMinX (iconRect), NSMinX (closeButtonRect)) <= 2 )
396
+ constrainedDrawingRect. size . width -- ;
397
+
395
398
NSSize stringSize = [attrString size ];
396
399
397
400
NSRect result = NSMakeRect (constrainedDrawingRect.origin .x , drawingRect.origin .y +ceil ((drawingRect.size .height -stringSize.height )/2 ), constrainedDrawingRect.size .width , stringSize.height );
0 commit comments