From e9cfc806b68760efe3c394cf2c7e9b57fc8ff6aa Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Sun, 15 May 2011 18:58:01 -0400 Subject: [PATCH] Refs #1264. Size to fit small tooltips to remove empty whitespace on right side. --- AppKit/_CPToolTip.j | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/AppKit/_CPToolTip.j b/AppKit/_CPToolTip.j index cae460366..4a2aacf18 100644 --- a/AppKit/_CPToolTip.j +++ b/AppKit/_CPToolTip.j @@ -60,15 +60,26 @@ var _CPToolTipHeight = 24.0, /*! Compute a cool size for the given string. - @param aToolTipSize the original wanted tool tip size + @param aToolTipSize a frame with the maximum width desired for the tooltip @param aText the wanted text @return CPArray containing the computer toolTipSize and textFrameSize */ + (CPSize)computeCorrectSize:(CPSize)aToolTipSize text:(CPString)aText { var font = [CPFont systemFontOfSize:_CPToolTipFontSize], + textFrameSizeSingleLine = [aText sizeWithFont:font], textFrameSize = [aText sizeWithFont:font inWidth:(aToolTipSize.width)]; + // If the text fully fits within the maximum width, shrink to fit. + if (textFrameSizeSingleLine.width < aToolTipSize.width) + { + var textField = [[CPTextField alloc] initWithFrame:CGRectMakeZero()], + inset = [textField currentValueForThemeAttribute:@"content-inset"] || CGInsetMakeZero(); + textFrameSize = textFrameSizeSingleLine; + textFrameSize.width += inset.left + inset.right; + aToolTipSize.width = textFrameSize.width; + } + if (textFrameSize.height < 100) { aToolTipSize.height = textFrameSize.height + 4;