# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1301620920 0 # Node ID 80a88c91ccf6643dc6c31faf4ee4c7713d3e97fc # Parent 80f3e108fa432f646ae1a81046c574d2ce8decf7 Implemented vertical centering on text fields. diff -r 80f3e108fa43 -r 80a88c91ccf6 dw.h --- a/dw.h Thu Mar 31 23:34:12 2011 +0000 +++ b/dw.h Fri Apr 01 01:22:00 2011 +0000 @@ -323,7 +323,7 @@ #define DW_DT_CENTER 2 /* NSCenterTextAlignment */ #define DW_DT_RIGHT 1 /* NSRightTextAlignment */ #define DW_DT_TOP 0 -#define DW_DT_VCENTER 0 +#define DW_DT_VCENTER (1 << 10) #define DW_DT_BOTTOM 0 #define DW_DT_HALFTONE 0 #define DW_DT_MNEMONIC 0 diff -r 80f3e108fa43 -r 80a88c91ccf6 mac/dw.m --- a/mac/dw.m Thu Mar 31 23:34:12 2011 +0000 +++ b/mac/dw.m Fri Apr 01 01:22:00 2011 +0000 @@ -715,6 +715,41 @@ -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } @end +/* Subclass for a textfield that supports vertical centering */ +@interface DWTextFieldCell : NSTextFieldCell +{ + BOOL vcenter; +} +-(NSRect)drawingRectForBounds:(NSRect)theRect; +-(void)setVCenter:(BOOL)input; +@end + +@implementation DWTextFieldCell +-(NSRect)drawingRectForBounds:(NSRect)theRect +{ + /* Get the parent's idea of where we should draw */ + NSRect newRect = [super drawingRectForBounds:theRect]; + + /* If we are being vertically centered */ + if(vcenter) + { + /* Get our ideal size for current text */ + NSSize textSize = [self cellSizeForBounds:theRect]; + + /* Center that in the proposed rect */ + float heightDelta = newRect.size.height - textSize.height; + if (heightDelta > 0) + { + newRect.size.height -= heightDelta; + newRect.origin.y += (heightDelta / 2); + } + } + + return newRect; +} +-(void)setVCenter:(BOOL)input { vcenter = input; } +@end + /* Subclass for a entryfield type */ @interface DWEntryField : NSTextField { @@ -6482,8 +6517,11 @@ { NSTextField *tf = object; - /* TODO: See if we need to switch to a bitmask */ - [[tf cell] setAlignment:style]; + [[tf cell] setAlignment:(style & 0xF)]; + if(style & DW_DT_VCENTER) + { + [[tf cell] setVCenter:YES]; + } } else if([object isMemberOfClass:[NSTextView class]]) { @@ -8219,6 +8257,7 @@ NSThread *thread = [[ NSThread alloc] initWithTarget:DWObj selector:@selector(uselessThread:) object:nil]; [thread start]; [thread release]; + [NSTextField setCellClass:[DWTextFieldCell class]]; return 0; }