From cba40d9e2e1cc1d078e855b43f21c82bb0d7d275 Mon Sep 17 00:00:00 2001 From: "gtm.daemon" Date: Mon, 24 Jun 2013 18:30:10 +0000 Subject: Ensure +[GTMUILocalizerAndLayoutTweaker sizeToFitFixedHeightTextField:] sets an integral size. When resizing labels it's possible to get fractional sizes. This CL fixes the problem by using integral values. DELTA=17 (17 added, 0 deleted, 0 changed) --- AppKit/GTMUILocalizerAndLayoutTweaker.m | 3 +++ AppKit/GTMUILocalizerAndLayoutTweakerTest.m | 14 ++++++++++++++ 2 files changed, 17 insertions(+) (limited to 'AppKit') diff --git a/AppKit/GTMUILocalizerAndLayoutTweaker.m b/AppKit/GTMUILocalizerAndLayoutTweaker.m index 27a4649..d2ff80c 100644 --- a/AppKit/GTMUILocalizerAndLayoutTweaker.m +++ b/AppKit/GTMUILocalizerAndLayoutTweaker.m @@ -313,6 +313,9 @@ static const CGFloat kWrapperStringSlop = 0.9; if (minWidth > fixedSize.width) { finalSize.width = minWidth; } + // Make integral. + finalSize.width = ceil(fixedSize.width); + finalSize.height = ceil(fixedSize.height); if (!NSEqualSizes(fixedSize, finalSize)) { [textField setFrameSize:finalSize]; } diff --git a/AppKit/GTMUILocalizerAndLayoutTweakerTest.m b/AppKit/GTMUILocalizerAndLayoutTweakerTest.m index d5b111c..8905e82 100644 --- a/AppKit/GTMUILocalizerAndLayoutTweakerTest.m +++ b/AppKit/GTMUILocalizerAndLayoutTweakerTest.m @@ -212,6 +212,7 @@ static NSUInteger gTestPass = 0; } #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 + - (void)testSizeToFitFixedHeightTextField { struct { const char *name; @@ -266,6 +267,19 @@ static NSUInteger gTestPass = 0; } } } + +- (void)testSizeToFitFixedHeightTextFieldIntegral { + NSTextField* textField = + [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 50)]; + [textField setBezeled:NO]; + [textField setStringValue:@"The quick brown fox jumps over the lazy dog."]; + [GTMUILocalizerAndLayoutTweaker sizeToFitFixedHeightTextField:textField]; + STAssertTrue( + NSEqualRects([textField bounds], NSIntegralRect([textField bounds])), + nil); + [textField release]; +} + #endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 @end -- cgit v1.2.3