aboutsummaryrefslogtreecommitdiff
path: root/AppKit
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-08-26 16:30:24 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-08-26 16:30:24 +0000
commit7f764065e4d7a0801ecf13741054c6e7fa1e71eb (patch)
tree3723b80815bed6df48aa0f118ed2a4096c7f95d2 /AppKit
parente6dabdd700a9c4b76e66bb6e7cc8beca3bd1aeeb (diff)
[Author: thomasvl]
Add an api for autosizing TextFields but keeping the width fixed. This needs a test in the future, but need it at the moment for chrome. R=stuartmorgan DELTA=18 (17 added, 1 deleted, 0 changed)
Diffstat (limited to 'AppKit')
-rw-r--r--AppKit/GTMUILocalizerAndLayoutTweaker.h8
-rw-r--r--AppKit/GTMUILocalizerAndLayoutTweaker.m10
2 files changed, 17 insertions, 1 deletions
diff --git a/AppKit/GTMUILocalizerAndLayoutTweaker.h b/AppKit/GTMUILocalizerAndLayoutTweaker.h
index 2d6e0a4..6562243 100644
--- a/AppKit/GTMUILocalizerAndLayoutTweaker.h
+++ b/AppKit/GTMUILocalizerAndLayoutTweaker.h
@@ -17,6 +17,7 @@
//
#import <Cocoa/Cocoa.h>
+#import "GTMDefines.h"
@class GTMUILocalizer;
@@ -38,6 +39,13 @@
// where sizeToFit doesn't product a view that meets UI guidelines.
// Returns the amount the view changed in size.
+ (NSSize)sizeToFitView:(NSView *)view;
+
+// If you call sizeToFit on a NSTextField it will try not to word wrap, so it
+// can get really wide. This method will keep the width fixed, but figure out
+// how tall the textfield needs to be to fit its text.
+// Returns the amount the field changed height.
++ (NSUInteger)sizeToFitFixedWidthTextField:(NSTextField *)textField;
+
@end
// This is a Tweaker that will call sizeToFit on everything within it (that
diff --git a/AppKit/GTMUILocalizerAndLayoutTweaker.m b/AppKit/GTMUILocalizerAndLayoutTweaker.m
index 4f94835..525b424 100644
--- a/AppKit/GTMUILocalizerAndLayoutTweaker.m
+++ b/AppKit/GTMUILocalizerAndLayoutTweaker.m
@@ -16,7 +16,6 @@
// the License.
//
-#import "GTMDefines.h"
#import "GTMUILocalizerAndLayoutTweaker.h"
#import "GTMUILocalizer.h"
@@ -91,6 +90,15 @@ static BOOL IsRightAnchored(NSView *view);
return SizeToFit(view, NSZeroPoint);
}
++ (NSUInteger)sizeToFitFixedWidthTextField:(NSTextField *)textField {
+ NSRect initialFrame = [textField frame];
+ NSSize newSize = [[textField cell] cellSizeForBounds:initialFrame];
+ NSRect newFrame = initialFrame;
+ newFrame.size.height = newSize.height;
+ [textField setFrame:newFrame];
+ return initialFrame.size.height - newSize.height;
+}
+
@end
@implementation GTMWidthBasedTweaker