diff --git a/Frameworks/DesktopKit/NXTTabView.m b/Frameworks/DesktopKit/NXTTabView.m index d27983bc..41350102 100644 --- a/Frameworks/DesktopKit/NXTTabView.m +++ b/Frameworks/DesktopKit/NXTTabView.m @@ -19,8 +19,8 @@ // Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. // +#import #import "NXTTabView.h" -#include "Foundation/NSObjCRuntime.h" #define TAB_OFFSET 6 @@ -155,18 +155,23 @@ - (void)drawTabTitle:(NSString *)title { NSPoint titlePosition; NSDictionary *titleAttributes; + NSString *label = title; // Fill text background [background set]; NSRectFill(titleRect); if (title) { + // TODO: `_trancated_label` is weird name. Use `_allowsTrancatedLabels` instead. + if (_truncated_label != NO) { + label = NXTShortenString(title, titleRect.size.width, _font, NXSymbolElement, NXTDotsAtRight); + } titlePosition = NSMakePoint( - titleRect.origin.x + (titleRect.size.width - [_font widthOfString:title]) / 2, + titleRect.origin.x + (titleRect.size.width - [_font widthOfString:label]) / 2, titleRect.origin.y + floorf((titleRect.size.height - [_font defaultLineHeightForFont]) / 2)); titleAttributes = @{NSForegroundColorAttributeName : foreground, NSFontAttributeName : _font}; - [title drawAtPoint:titlePosition withAttributes:titleAttributes]; + [label drawAtPoint:titlePosition withAttributes:titleAttributes]; } } diff --git a/Tests/DesktopKit/TabViewTest.m b/Tests/DesktopKit/TabViewTest.m index 2d2f872b..c0f586c9 100644 --- a/Tests/DesktopKit/TabViewTest.m +++ b/Tests/DesktopKit/TabViewTest.m @@ -19,6 +19,7 @@ */ #import +#include "AppKit/NSTextField.h" #import #import "TabViewTest.h" @@ -41,31 +42,36 @@ - (id)init NXTTabView *tabView = [[NXTTabView alloc] initWithFrame:NSMakeRect(-1, -2, 359, 242)]; tabView.unselectedBackgroundColor = [NSColor grayColor]; tabView.selectedBackgroundColor = [NSColor lightGrayColor]; + // [tabView setFont:[NSFont boldSystemFontOfSize:12]]; + [tabView setAllowsTruncatedLabels:YES]; [tabView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; NXTTabViewItem *item; - item = [[NXTTabViewItem alloc] initWithIdentifier:@"Model"]; - item.label = @"Model"; + item = [[NXTTabViewItem alloc] initWithIdentifier:@"0"]; + item.label = @"Instances"; + NSTextField *subview = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 100, (359 - 40), 21)]; + [item setView:subview]; + [subview release]; [tabView addTabViewItem:item]; - item = [[NXTTabViewItem alloc] initWithIdentifier:@"Repeat"]; - item.label = @"Repeat"; + item = [[NXTTabViewItem alloc] initWithIdentifier:@"1"]; + item.label = @"Classes"; [tabView addTabViewItem:item]; - item = [[NXTTabViewItem alloc] initWithIdentifier:@"Layouts"]; - item.label = @"Layouts"; + item = [[NXTTabViewItem alloc] initWithIdentifier:@"2"]; + item.label = @"Images"; [tabView addTabViewItem:item]; - item = [[NXTTabViewItem alloc] initWithIdentifier:@"Shortcuts"]; - item.label = @"Shortcuts"; + item = [[NXTTabViewItem alloc] initWithIdentifier:@"3"]; + item.label = @"Sounds"; [tabView addTabViewItem:item]; - item = [[NXTTabViewItem alloc] initWithIdentifier:@"Keypad"]; - item.label = @"Keypad"; + item = [[NXTTabViewItem alloc] initWithIdentifier:@"4"]; + item.label = @"LogngTitle"; [tabView addTabViewItem:item]; - item = [[NXTTabViewItem alloc] initWithIdentifier:@"Modifiers"]; - item.label = @"Modifiers"; + item = [[NXTTabViewItem alloc] initWithIdentifier:@"5"]; + item.label = @"VeryLogngTitle"; [tabView addTabViewItem:item]; [[window contentView] addSubview:tabView];