[aView setToolTip:@"huhu\nhihi"];
@"01234567890ABCDEF\n01234567890ABCDEF\n01234"
@"01234567890ABCDEF\n01234567890ABCDEF\n012345"
+ (CGSize)computeCorrectSize:(CGSize)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;
return [aToolTipSize, textFrameSize];
}
var newWidth = aToolTipSize.width + ((parseInt(textFrameSize.height - 100) / _CPToolTipHeight) * _CPToolTipHeight);
textFrameSize = [aText sizeWithFont:font inWidth:newWidth - 4];
aToolTipSize.width = newWidth + 2;
aToolTipSize.height = textFrameSize.height + 4;
return [aToolTipSize, textFrameSize];
}
// 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.width = textFrameSizeSingleLine.width + inset.left + inset.right;
aToolTipSize.width = textFrameSize.width;
}