From cad5cf79329085a88aa62331c0342e15b6b7b847 Mon Sep 17 00:00:00 2001 From: Mark Sibly Date: Mon, 5 Oct 2015 11:16:55 +1300 Subject: [PATCH] Vertically aligned text in tree view cells for el capitan --- .../cocoamaxgui.mod/cocoa.macos_tiger.m | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/mod/maxgui.mod/cocoamaxgui.mod/cocoa.macos_tiger.m b/mod/maxgui.mod/cocoamaxgui.mod/cocoa.macos_tiger.m index 18616e5..b3a1faf 100644 --- a/mod/maxgui.mod/cocoamaxgui.mod/cocoa.macos_tiger.m +++ b/mod/maxgui.mod/cocoamaxgui.mod/cocoa.macos_tiger.m @@ -131,6 +131,30 @@ struct nsgadget{ int intFontStyle; }; +// From S.O. for vertically text in cells... +// +@interface VerticallyAlignedTextFieldCell : NSBrowserCell{ //NSTextFieldCell { + +} + +@end + +@implementation VerticallyAlignedTextFieldCell + +- (NSRect)titleRectForBounds:(NSRect)theRect { + NSRect titleFrame = [super titleRectForBounds:theRect]; + NSSize titleSize = [[self attributedStringValue] size]; + titleFrame.origin.y = theRect.origin.y - .5 + (theRect.size.height - titleSize.height) / 2.0; + titleFrame.origin.x += (theRect.size.height - titleSize.height) / 2.0; + return titleFrame; +} + +- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { + NSRect titleRect = [self titleRectForBounds:cellFrame]; + [[self attributedStringValue] drawInRect:titleRect]; +} + +@end // prototypes void NSClearItems(nsgadget *gadget); @@ -1205,13 +1229,21 @@ tableColumn:(NSTableColumn *)aTableColumn row:(int)row mouseLocation:(NSPoint)mo column=[[NSTableColumn alloc] init]; [outline addTableColumn:column]; [outline setOutlineTableColumn:column]; - cell=[[NSBrowserCell alloc] init]; - [cell setLeaf:YES]; - [cell setScrollable:YES]; - [column setDataCell:cell]; + +// cell=[[NSBrowserCell alloc] init]; +// [cell setLeaf:YES]; +// [cell setScrollable:YES]; +// [column setDataCell:cell]; + + cell=[[VerticallyAlignedTextFieldCell alloc] init]; + [column setDataCell:cell]; + + [self setDocumentView:outline]; [outline sizeLastColumnToFit]; + + return self; } -(void)dealloc{ -- 2.30.2