GUI Tooltip - Linked to mouse

Hi everyone,

Another tooltip thread, as I dont seem to have found any suitable answers.

I’m trying to have a global tooltip that shows upon hovering certain gui elements (abilities, items in inventory, etc)

I’d like to have the tooltip to the left, right, top bottom but never under the mouse cursor.

Any idea how I could achieve, I have a small tooltip class if you want to see where I’m up to

Everything is working except the position of the tooltip who is all over the place, I cannot make it follow the cursor.

Hopefully, this is not too much of a dumb question :slight_smile:

Cheers,
Orion

Adding @carolhmj our GUI guru

It would be easier to know what’s going on with a playground reproduction, but I saw that you add the tooltipContainer in something called _playerUI, and if that’s not the top level ADT, your tooltip’s coordinates will be offset by whatever _playerUI is offset. If that’s the case, you’ll have to apply the inverse of this offset to your tooltip.

2 Likes

Hi,

Thanks Carol, to simplify this, I’ve did a quick playground to show what I mean,

I would like the tooltip to follow my mouse as I hover over any of the black boxes, or alternatively use the gui element provided in the showTooltip function to position the tooltip to any side of that provided gui element.

Make sense?

I have a mouse following example here: GUI Tooltip example | Babylon.js Playground (babylonjs.com)

2 Likes

Thanks Carol,

I feel so dumb!

All the issues I was having with ui & placement that’s been plaguing me since I started with Babylon is to do with this line…

this._playerUI.idealHeight = 720;

As soon as I removed it, everyhting is working perfectly and positionning itself as you would expect.

Can you explain?

Updated playground with what I was trying to achieve: https://playground.babylonjs.com/#NEF5HL#73

Not quite sure why the adaptHeightToChildren is not working on PG?

1 Like

I think it’s because it should read ‘adaptHeightToChild’ in case of a textBlock. It doesn’t seem to be able to recalculate from ‘stacked’ tb. Usually what I do is that either I use a grid OR if the container needs to dynamically change size (like if sometimes there is no description and it needs to adapt), I use a stackpanel with no height as the parent container. It will change height from the children containers (other stackpanels or rectangles). Then, I would constrain each textBlock I want to stack inside a container.
But then, if you have only tiltle and description, you could also just make a string, like:

var tbtext = “Item Title\n” +
“Item Description”;

If you have only one textBlock then you will not need the container to stack it.

Edit: Something like that:

Edit1: Sorry rushed it a little. I had to go for some shopping :sweat_smile: Now I’m back and quickly made a more suitable version I believe. Here it will resize no matter if there is a description or not and no matter the length of the description.

Hope this helps,

1 Like

There’s a good explanation here on the docs

Ok, thanks Mawa, make sense,

I’ve updated the playground to reflect a more detailled tooltip for anyone stumbling onto this topic: https://playground.babylonjs.com/#NEF5HL#101

@carolhmj thanks, i’ll have a read on that now

2 Likes

Cool. Thanks a lot for this effort. :hugs: I know I sometimes don’t take enough time for the polishing :face_with_hand_over_mouth: I’m sure this will come handy for others. Have a great day :sunglasses:

2 Likes

Hey @carolhmj

To answer original post correctly, I need a little more help,

I’ve read the docs mutliple times, and it seems to me like I need to add a multiplier or something to my tooltip position to cater for the adaptive scaling that is done automatically by babylon. (if I understand correctly, that is why everything is out of whack)

If I added a ideal width and height of 1024x768 to the PG, any idea how I would correct the position of the tooltip?

Many thanks,

I have a question/issue similar to this. I also still do not fully understand how ideal width and height works just exactly. It seems to be desync from the resize. I’m not trying to place tooltips but I’m using ‘delegatePickingToChildren’ and ‘detectPointerOnOpaqueOnly’ which obviously calls on the image/pixels coordinates. And although visually, my image shows correctly, depending on how the canvas is scaled the pointer is detected or not. It also seems to work ‘eratically’, don’t know how to explain it. There’s something I either don’t understand or happening under the hood that might just not be always what one would expect (or as I said I don’t understand it - despite from all the hours I already spent on it an then despite from reading the docs I don’t know how many times).

Hmm I experimented a bit on my example, and it seems you can correct the mouse position by the ratio between the current width/height and ideal width/height: GUI Tooltip example | Babylon.js Playground (babylonjs.com)

Huh, sorry but that’s not what I see (SS below). But then I don’t know about @oriongu but on my side, I was pretty much willing not to bother the Team today and let you focus on the launch :rocket:
My popcorn :popcorn: :popcorn: is ready and so am I :nerd_face: :child:



My two cents: I’m curious, because I would have expected any positions to be updated automatically when using adaptive scaling. What’s the point of having position values thats does not reflect whats on the screen? If I understand correctly, everytime I would like to find/use a position of a GUI element, I would need to apply some sort of ratio fix to get the “real” position. I’m probably missing something completely obvious, and apologize if that’s the case. :smiley:

In the sake of reducing complexity on my project, I will avoid adaptive scaling for the moment.

… and focus on this very exciting new version! GO BABYLON V6! :slight_smile: please share the popcorn @mawa :popcorn: :popcorn: :popcorn: :popcorn: :popcorn: :popcorn: :popcorn: :popcorn:

Yes, same here. I just can’t figure it. :grimacing:
I don’t want to ‘pollute’ your topic but I sort of feel this must be related (sry, if I’m wrong).

Here’s a link to my sketchy wheely type GUI case scenario.
Click on the top icon to the bottom right to show the wheel menu. Click on the right ‘walk’ or ‘run’ icons to expand. These all use picking from the image and detect pointer on opaque. Next, enlarge the window or click on the full-screen button (bottom right) and eventually be able or not to click on the ‘walk’ or ‘run’ expanded buttons. I tried n versions of setting or not an ideal size, coupled with scaleTo and whatever I know options do exist but no, I just can’t get this one setting that would fit all.

Ooh, thanks for checking, I think this is related to the screen size :o Does this version work for you? GUI Tooltip example | Babylon.js Playground (babylonjs.com)

Not really, sry. But then I’m not sure what is the expected output. May be to make this easier to check, let’s pretend the tooltip should always show in the center of the hovered square.


Where is your mouse pointer in these images?

LOL. good question. It doesn’t capture the pointer :grin:
Basically, I’m hovering towards the center of the squares. Reason why I suggested to make the tooltip appear either on the center of the hovered square… but now that I think of it, it should may be for a start simply appear in the center of the pointer. Currently, it’s offseted from the pointer either above or below AND at various position from the pointer depending on window size/ratio.

Edit: Actually (sry again @oriongu for polluting your post), Actually… may be you could start by explaining to me (to us) why we need this in the before render function to detect whether the pointer is hovering a texture or not:

const widthRatio = gui.idealWidth / engine.getRenderWidth();
const heightRatio = gui.idealHeight / engine.getRenderHeight();