Is there a way to autosize the width of hotspot textfield?

  • Hi,

    I need to put tooltip hotspots with background. It seems that I need to write down
    width and height for every single tooltip hotspot. Since the width of every tooltip hotspot
    is different from one another, it is really a time consuming task for finding out
    right size..

    I wonder if there is a way to autosize the width of hotspot textfield.
    Or is there a way for workaround?

    This would be a really convenient feature!

    Best Regards,
    Hyung

  • Well, I thought on that issue before and just now I've created something like that, I suppose *smile*

    Try adding this action

    Code
    <action name="show_tooltip">
    	txtadd(tooltip_width_search, 'get(tooltip)','_countstart');
    	indexoftxt(number_of_characters,get(tooltip_width_search),_countstart,0);
    	mul(text_width, number_of_characters, 8);
    	copy(layer[tooltip].width, text_width);
    	copy(layer[tooltip].html, tooltip);
    	set(layer[tooltip].visible, true);
    	tween(layer[tooltip].alpha, 1.0, 0.5);
    	asyncloop(hovering, copy(layer[tooltip].x,mouse.stagex); copy(layer[tooltip].y,mouse.stagey); );
    	</action>

    to the onover attribute in the style of your hotspots. I've just tested it quickly and it seems to work.

    The value "8" in this line

    Code
    mul(text_width, number_of_characters, 8);

    Comes from my thought and my quick practical test that the font Arial 12 has optimal "width" of 8 px. If I set more than 8, the textfield becomes a bit long on the edges, if I state less than 8, textfield sometimes becomes "cut'. So if you are using other fonts, then state some other character width value.

    Or maybe is there some connection between font height and font width in lower and upper cases? I don't know that, unfortunately...

    P.S. note that there must be tooltip="your_tooltip" attributes in your hotspots for the above action to retrieve these tooltips.

    Regards,

    Alexey

  • Brilliant Alexey!

    I haven't tried it myself yet but I believe this would work! I was thinking something
    similar (getting the size of the tooltip on the fly) but I thought there is no krpano action
    that would do this but "indexoftxt" would do the trick.

    I will try the code later and share the result :)

    Thanks!

    Hyung

  • This is how I applied based on the code Alexey has provided


    I found out that the length of one character is not always the same.. This could be worse
    when using non alphabetic language characters. So I set the basic width for one character
    and when there are many characters I subtract certain pixels. (In the code above I subtract
    10 pixels of width when there are more than 5 characters)

    if(number_of_characters GT 5, sub(text_width, 10));

    Of course the value would differ depending on the language, font size, font style etc..

    And I tried to apply this action to all the tooltips hotspots at one time but I don't know this
    could be done with pure krpano actions. So I have added "onloaded" event to each tooltip
    hotspot.

    Lastly, automatic width calculation action is performed only when there the value of "width"
    is 0. First I have removed the width and tried to give condition "when there is no width
    specified" in the "calc_tooltip_width" action but I didn't succeed.

    I tried something like

    if(hotspot[%1].width != null

    if(hotspot[%1].width !== null

    ifnot(hotspot[%1].width == null

    ifnot(hotspot[%1].width === null


    if(get(hotspot[%1].width) != null

    if(get(hotspot[%1].width) !== null

    ifnot(get(hotspot[%1].width) == null

    ifnot(get(hotspot[%1].width) === null

    but none of them worked. It's probably because the width is NOT null but I don't know
    what condition I should do the job.

    So if you specify the width value more than 0, then that value will be applied and otherwise
    the width will be calculated automatically.

    Thanks again to Alexey for giving guides.
    Hope this helps others too :)

    Best Regards,
    Hyung

  • I've had another try just now with this code:

    And it seems to calculate the width of the tooltip, if I increase the tooltip phrase, the tolltip textfield grows in length.

    Has anybody else tried this yet?

    Regards,

    Alexey

  • Just tried your code.

    Really, if don't specify "width" of the hotspot, I get both hotspots at 400 px in width.
    If I specify some other value other than "0", I got this value as textfield width. *confused*

    Yes I also get 400px if I don't specify the width. Seems that 400px is the default width used
    inside krpano. Do you still get 400px even give value other than "0"? Strange, because the codes
    works for me, which means if I give 100 as width for example, the action is ignored and the
    width becomes 100. Maybe it could be different krpano version, or you might want to delete
    browser cache and check again.

    I have modified the code a bit as below so that in order to differentiate mobile from desktop

    Again, the right size if the width would depends on the language, font size, style etc..

    I believe the code in your last post should work :)

    Best Regards,
    Hyung

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!