-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDE_TextFieldCell.m
More file actions
70 lines (48 loc) · 2.11 KB
/
Copy pathDE_TextFieldCell.m
File metadata and controls
70 lines (48 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// DE_TextFieldCell.m
// custom_controls
//
// Created by David Palmer on 6/22/15.
// Copyright (c) 2015 discode enterprises. All rights reserved.
//
#import "DE_TextFieldCell.h"
#import "DE_Drawing.h"
@implementation DE_TextFieldCell
- (void) awakeFromNib {
// Was thinking about setting up stuff when in a .xib like highlightcolor
}
-(NSColor *)highlightColorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
// Was thinking about drawing some custom highlight colors
return nil;
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
// Draw textBox background
[DE_Drawing drawTextBoxBackgroundCanvasWithTextBoxFrame:self.controlView.bounds textBoxCornerRadius:2 textBoxStrokeWidth:1];
if (self.isEditable) {
[self setBackgroundColor:[NSColor darkGrayColor]];
[self drawInteriorWithFrame:cellFrame inView:controlView];
}
if (self.isEnabled) {
[self setBackgroundColor:[DE_Drawing textBoxFillColor]];
}
}
-(void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
NSAttributedString *attrString = self.attributedStringValue;
[attrString drawWithRect: [self titleRectForBounds:cellFrame]
options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin];
}
- (NSRect)titleRectForBounds:(NSRect)theRect {
NSRect titleFrame = [super titleRectForBounds:theRect];
// Moving over the text origin to get it away from the edege of the frame
titleFrame.origin.x = 4;
NSAttributedString *attrString = self.attributedStringValue;
NSRect textRect = [attrString boundingRectWithSize: titleFrame.size
options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin ];
if (textRect.size.height < titleFrame.size.height) {
// Center Stuff
titleFrame.origin.y = theRect.origin.y + (theRect.size.height - textRect.size.height) / 2.0;
titleFrame.size.height = textRect.size.height;
}
return titleFrame;
}
@end