Skip to content
This repository was archived by the owner on Nov 19, 2019. It is now read-only.

Commit 315ddb4

Browse files
author
Frank Dowsett
committed
AdiumTabStyle: fix the title overlapping the icon.
Cleaned up -titleRectForBounds's variables that were used in both horizontal and vertical calculations.
1 parent 8160e88 commit 315ddb4

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

Source/PSMAdiumTabStyle.m

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ - (NSRect)iconRectForBounds:(NSRect)theRect ofTabCell:(PSMTabBarCell *)cell {
343343

344344
- (NSRect)titleRectForBounds:(NSRect)theRect ofTabCell:(PSMTabBarCell *)cell {
345345

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+
346351
PSMTabBarControl *tabBarControl = [cell controlView];
347352
PSMTabBarOrientation orientation = [tabBarControl orientation];
348353

@@ -361,37 +366,35 @@ - (NSRect)titleRectForBounds:(NSRect)theRect ofTabCell:(PSMTabBarCell *)cell {
361366
constrainedDrawingRect.size.width -= kPSMAdiumImageWidth + kPSMTabBarCellPadding;
362367
}
363368

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));
364373
if (orientation == PSMTabBarHorizontalOrientation) {
365374

366-
NSRect closeButtonRect = [cell closeButtonRectForBounds:theRect];
367-
NSRect iconRect = [cell iconRectForBounds:theRect];
368-
369375
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;
372378
}
373379

374-
NSRect counterBadgeRect = [cell objectCounterRectForBounds:theRect];
375380
if (!NSEqualRects(counterBadgeRect, NSZeroRect)) {
376381
constrainedDrawingRect.size.width -= NSWidth(counterBadgeRect) + kPSMTabBarCellPadding;
377382
}
378383
} else {
379384

380-
NSRect closeButtonRect = [cell closeButtonRectForBounds:theRect];
381-
NSRect counterBadgeRect = [cell objectCounterRectForBounds:theRect];
382-
383385
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+
}
386388
}
387389

390+
//Don't show a title if there's only enough space for a character
388391
if (constrainedDrawingRect.size.width <= 2)
389392
return NSZeroRect;
390393

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+
395398
NSSize stringSize = [attrString size];
396399

397400
NSRect result = NSMakeRect(constrainedDrawingRect.origin.x, drawingRect.origin.y+ceil((drawingRect.size.height-stringSize.height)/2), constrainedDrawingRect.size.width, stringSize.height);

0 commit comments

Comments
 (0)