From 32fb13a9a9a6f8b5bb84e537a3a7caef2f5550a7 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Fri, 18 Jun 2010 00:27:28 -0400 Subject: [PATCH] Fixed: long titles in CPAlert buttons would be cut off. Fix is to use the standard 80 pixels width as a minimum width only. --- AppKit/CPAlert.j | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/AppKit/CPAlert.j b/AppKit/CPAlert.j index 9f935f145..9f04ec545 100644 --- a/AppKit/CPAlert.j +++ b/AppKit/CPAlert.j @@ -145,14 +145,13 @@ var CPAlertWarningImage, for(var i=0; i < count; i++) { var button = _buttons[i]; - - [button setFrameSize:CGSizeMake([button frame].size.width, (styleMask == CPHUDBackgroundWindowMask) ? 20.0 : 24.0)]; - [button setTheme:(_windowStyle === CPHUDBackgroundWindowMask) ? [CPTheme themeNamed:"Aristo-HUD"] : [CPTheme defaultTheme]]; [[_alertPanel contentView] addSubview:button]; } - + + [self _layoutButtons]; + if (!_messageLabel) { _messageLabel = [[CPTextField alloc] initWithFrame:CGRectMakeZero()]; @@ -161,6 +160,7 @@ var CPAlertWarningImage, [_messageLabel setAlignment:CPJustifiedTextAlignment]; [_messageLabel setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable]; + _alertImageView = [[CPImageView alloc] initWithFrame:CGRectMake(15.0, 12.0, 32.0, 32.0)]; _informativeLabel = [[CPTextField alloc] initWithFrame:CGRectMakeZero()]; @@ -288,8 +288,8 @@ var CPAlertWarningImage, - (void)addButtonWithTitle:(CPString)title { var bounds = [[_alertPanel contentView] bounds], - button = [[CPButton alloc] initWithFrame:CGRectMake(CGRectGetWidth(bounds) - ((_buttonCount + 1) * 90.0), CGRectGetHeight(bounds) - 34.0, 80.0, (_windowStyle == CPHUDBackgroundWindowMask) ? 20.0 : 24.0)]; - + button = [[CPButton alloc] initWithFrame:CGRectMakeZero()]; + [button setTitle:title]; [button setTarget:self]; [button setTag:_buttonCount]; @@ -309,6 +309,27 @@ var CPAlertWarningImage, _buttonCount++; [_buttons addObject:button]; + + [self _layoutButtons]; +} + +- (void)_layoutButtons +{ + var bounds = [[_alertPanel contentView] bounds], + count = [_buttons count], + offsetX = CGRectGetWidth(bounds), + offsetY = CGRectGetHeight(bounds) - 34.0; + for(var i=0; i < count; i++) + { + var button = _buttons[i]; + + [button sizeToFit]; + var buttonBounds = [button bounds], + width = MAX(80.0, CGRectGetWidth(buttonBounds)), + height = CGRectGetHeight(buttonBounds); + offsetX -= (width + 10); + [button setFrame:CGRectMake(offsetX, offsetY, width, height)]; + } } - (void)_layoutMessage