Multiline tooltip problem

29 views
Skip to first unread message

Rosch

unread,
Jul 20, 2017, 1:14:15 PM7/20/17
to Cappuccino & Objective-J
Hi...

After a bigger pause I started again to intensively code using Cappuccino. All beside of thing presently runs very well.

I have updated to all new shiny Cappuccino 0.9.10.

I have a view and I add a very silly tooltip.

[aView setToolTip:@"huhu\nhihi"];

It is silly 2 line. But it is clipped to one line and some top pixels of the second line on hover.
Checked this using current Chrome,FF and IE on windows.

Any clue to get this going?

In another place I do have a big 8 line tooltip that works just nicely.

Thanks for your help,

Roland

daboe01

unread,
Jul 21, 2017, 1:22:57 AM7/21/17
to Cappuccino & Objective-J
what happens when you replace the two-line text with the one from the 8 line tooltip?

Rosch

unread,
Jul 21, 2017, 4:26:30 AM7/21/17
to Cappuccino & Objective-J
Good morning Daniel,

Thanks for your reply.

That simply works... It is fully visible.

I played around last evening. It appears to be a length issue.

@"01234567890ABCDEF\n01234567890ABCDEF\n01234"

as string for a tooltip does not work. It brings the clipped of tooltip just showing the content of the first line. But

@"01234567890ABCDEF\n01234567890ABCDEF\n012345"

gives a 3 lines tooltip. It is just ein byte more than the previous example.

Roland

daboe01

unread,
Jul 21, 2017, 5:31:41 AM7/21/17
to Cappuccino & Objective-J
thank you.
could you please open an issue on github with you example below?

Rosch

unread,
Jul 21, 2017, 5:36:17 AM7/21/17
to Cappuccino & Objective-J
Hi...

So maybe I find a solution. CPToolTip checks whether if needs to resize its frame in width. But there it also changes its height to single line height.

From AppKit/_CPToolTip.j:
+ (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];
}



I changed the first if to only touch the width not the height:

    // 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;
   
}


This seems to solve my problem. I do not know whether it is the really generic correct solution but it solves my problem.

Roland



Am Donnerstag, 20. Juli 2017 19:14:15 UTC+2 schrieb Rosch:
Reply all
Reply to author
Forward
0 new messages