Skip to content

Commit

Permalink
Window height based maximum input text field height.
Browse files Browse the repository at this point in the history
  • Loading branch information
emsquared committed Jul 23, 2012
1 parent 6c5f2b9 commit b370ab1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 19 deletions.
9 changes: 7 additions & 2 deletions Classes/Controllers/TXMasterController.m
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
#pragma mark -
#pragma mark NSWindow Delegate

- (void)windowDidResize:(NSNotification *)notification
{
[self.text resetTextFieldCellSize:YES];
}

- (void)windowDidBecomeKey:(NSNotification *)notification
{
id sel = self.world.selected;
Expand Down Expand Up @@ -1221,8 +1226,8 @@ - (void)_moveInputHistory:(BOOL)up checkScroller:(BOOL)scroll event:(NSEvent *)e
[self.text setAttributedStringValue:s];
[self.world focusInputText];

if ([self.text respondsToSelector:@selector(resetTextFieldCellSize)]) {
[self.text resetTextFieldCellSize];
if ([self.text respondsToSelector:@selector(resetTextFieldCellSize:)]) {
[self.text resetTextFieldCellSize:NO];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Headers/TVCInputTextField.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
@property (nonatomic, strong) NSAttributedString *placeholderString;

- (void)updateTextDirection;
- (void)resetTextFieldCellSize;
- (void)resetTextFieldCellSize:(BOOL)force;
- (void)redrawOriginPoints;

- (void)setReturnActionWithSelector:(SEL)selector owner:(id)owner;
Expand Down
48 changes: 34 additions & 14 deletions Classes/Views/Input Text Field/TVCInputTextField.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

#import <objc/objc-runtime.h>

#define _InputTextFiedMaxHeight 382.0
#define _InputBoxDefaultHeight 18.0
#define _InputBoxHeightMultiplier 14.0
#define _InputBoxBackgroundMaxHeight 387.0
Expand Down Expand Up @@ -136,7 +135,12 @@ - (void)updateTextDirection
}
}

- (void)resetTextFieldCellSize
- (NSInteger)backgroundViewMaximumHeight
{
return (self.window.frame.size.height - 50);
}

- (void)resetTextFieldCellSize:(BOOL)force
{
BOOL drawBezel = YES;

Expand Down Expand Up @@ -168,27 +172,43 @@ - (void)resetTextFieldCellSize
} else {
NSInteger totalLinesBase = [self numberOfLines];

if (_lastDrawnLineCount == totalLinesBase) {
if (_lastDrawnLineCount == totalLinesBase && force == NO) {
drawBezel = NO;
}

_lastDrawnLineCount = totalLinesBase;

if (drawBezel) {
NSInteger totalLinesMath = (totalLinesBase - 1);


/* Calculate unfiltered height. */
textBoxFrame.size.height = _InputBoxDefaultHeight;
backgroundFrame.size.height = _InputBoxBackgroundDefaultHeight;

textBoxFrame.size.height += (totalLinesMath * _InputBoxHeightMultiplier);
backgroundFrame.size.height += (totalLinesMath * _InputBoxBackgroundHeightMultiplier);

if (textBoxFrame.size.height > _InputTextFiedMaxHeight) {
textBoxFrame.size.height = _InputTextFiedMaxHeight;
}

if (backgroundFrame.size.height > _InputBoxBackgroundMaxHeight) {
backgroundFrame.size.height = _InputBoxBackgroundMaxHeight;

NSInteger backgroundViewMaxHeight = [self backgroundViewMaximumHeight];

/* Fix height if it exceeds are maximum. */
if (backgroundFrame.size.height > backgroundViewMaxHeight) {
for (NSInteger i = totalLinesMath; i >= 0; i--) {
NSInteger newSize = 0;

newSize = _InputBoxBackgroundDefaultHeight;
newSize += (i * _InputBoxBackgroundHeightMultiplier);

if (newSize > backgroundViewMaxHeight) {
continue;
} else {
backgroundFrame.size.height = newSize;

textBoxFrame.size.height = _InputBoxDefaultHeight;
textBoxFrame.size.height += (i * _InputBoxHeightMultiplier);

break;
}
}
}
}
}
Expand All @@ -214,7 +234,7 @@ - (void)resetTextFieldCellSize

- (void)textDidChange:(NSNotification *)aNotification
{
[self resetTextFieldCellSize];
[self resetTextFieldCellSize:NO];

if (NSObjectIsEmpty(self.stringValue)) {
[super sanitizeTextField:NO];
Expand Down Expand Up @@ -249,7 +269,7 @@ - (void)paste:(id)sender
{
[super paste:self];

[self resetTextFieldCellSize];
[self resetTextFieldCellSize:NO];
[self sanitizeTextField:YES];
}

Expand All @@ -264,7 +284,7 @@ - (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector
if (aSelector == @selector(insertNewline:)) {
objc_msgSend(self.actionTarget, self.actionSelector);

[self resetTextFieldCellSize];
[self resetTextFieldCellSize:NO];
[self sanitizeTextField:NO];

return YES;
Expand Down
4 changes: 2 additions & 2 deletions Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
<key>TXBundleBuildCodeName</key>
<string>Turtle Soup</string>
<key>TXBundleBuildNumber</key>
<string>11959</string>
<string>11976</string>
<key>TXBundleBuildReference</key>
<string>2.1.1-246-gbd7d091-appstore,llvm4.0</string>
<string>2.1.1-247-g6c5f2b9-debug,llvm4.0</string>
</dict>
</plist>

0 comments on commit b370ab1

Please sign in to comment.