# Made some cool tooltips

**URL:** <https://forum.babylonjs.com/t/made-some-cool-tooltips/38516>\
**Category:** Demos and projects\
**Created:** [February 25, 2023, 1:59pm UTC](https://forum.babylonjs.com/t/made-some-cool-tooltips/38516 "2023-02-25T13:59:01Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [February 25, 2023, 1:59pm UTC](https://forum.babylonjs.com/t/made-some-cool-tooltips/38516/1 "2023-02-25T13:59:01Z")

</div>

Made a cool tooltip class for my current project, utilizing the BABYLON GUI.

_Edit_  
I finally got around to it and simplified it a bit, removed hard-coded things, made stats dynamic (with a setup function)  
All included in the PG;

> **[Babylon.js Playground](https://playground.babylonjs.com/#VQW85K)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

The tooltip class should be the last gui element added to the ADT to always be on top.  
Read the code 🙏, play around with it, I hope the naming explains the majority.

> tooltip.setupStats( [“A”, “B”, “C”] ); // needed once after tooltip creation.  
> tooltip.update(name, quality, iconUrl, itemCategory, itemType, stats, gold, description, footNote)  
> tooltip.show( x, y); // pixel positions of upper left corner of the tooltip.  
> tooltip.hide();

> In the update function, the “stats” argument is an array that matches the setupStats  
> [“value of A”, “value of B”, “value of C”], they can be numbers or strings, null or 0 will make that stat not display.

_Original_  
No PG as it’s all tied up in hard-coded stat and item types, aswell as static values i use within in my project.

But maybe it’ll cause some inspiration, i’d love feedback too!

Slightly(_cough_) inspired by a popular MMORPG.

Populated with dummy values 😃 and the icon will be changed ofc

 ![ToolTipsDraft01](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/9/0/90a74a1ccf0dda94b3e1aa2d0df77a0d780c3bd2.png)

---

<div class="post-metadata">

**Author:** ![brianzinn](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brianzinn/32/28013_2.png) [@brianzinn](https://forum.babylonjs.com/u/brianzinn)\
**Post date:** [February 26, 2023, 4:15pm UTC](https://forum.babylonjs.com/t/made-some-cool-tooltips/38516/2 "2023-02-26T16:15:56Z")

</div>

Looks good - how did you get the potion description to go down a line since it would overlap with “consumable” - did you measure the text or is there another way?

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [February 26, 2023, 4:57pm UTC](https://forum.babylonjs.com/t/made-some-cool-tooltips/38516/3 "2023-02-26T16:57:10Z")

</div>

Hi @brianzinn  
I actually used nested StackPanels

The item type on left ( cloth, etc ) and equipment/use type on the right, is a horizontal StackPanel nested within a vertical StackPanel for stats, which again is nested within a main vertical StackPanel that includes a top container for the icon & title and at the bottom the description, gold value and the footnote are added to the main StackPanel.

Anything that isn’t used for a given item is hidden with `control.notRenderable = true;`

---

<div class="post-metadata">

**Author:** ![oriongu](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/oriongu/32/40402_2.png) [@oriongu](https://forum.babylonjs.com/u/oriongu)\
**Post date:** [February 27, 2023, 12:21am UTC](https://forum.babylonjs.com/t/made-some-cool-tooltips/38516/4 "2023-02-27T00:21:44Z")

</div>

Looks great, I’m actually in the process of integrating items into my project also. It would be invaluable help if you would/could share your project 🙂

Feedback wise, there is not too much to say as it mostly looks pretty tidy and hierarchy is respected:

- one thing is unclear, is what does 12 constitution mean for example, is it a cost? is it an effect?

In all cases, great job!

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [February 27, 2023, 11:41am UTC](https://forum.babylonjs.com/t/made-some-cool-tooltips/38516/5 "2023-02-27T11:41:09Z")

</div>

> [@aWeirdo](#):
>
> a horizontal StackPanel nested within a vertical StackPanel for stats, which again is nested within a main vertical StackPanel that includes a top container

Yes 👍, …you could also have used grids inside your stackpanels. But overall this imbrication of containers is (in my opinion) basically the way you build a complex responsive and dynamic GUI with the BJS 2D GUI. May I add here that I also found that the ‘Editor’ is a pretty good tool to use to better understand this sort of ‘imbrication’.  
GJ,

---

<div class="post-metadata">

**Author:** ![Takemura](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/takemura/32/25836_2.png) [@Takemura](https://forum.babylonjs.com/u/Takemura)\
**Post date:** [February 28, 2023, 10:54am UTC](https://forum.babylonjs.com/t/made-some-cool-tooltips/38516/6 "2023-02-28T10:54:23Z")

</div>

The style remembers me of many games I played from RTS to RPGs. But how do you solve the issue with positioning? Do you calculate absolute left and top (+offset) at i.e. hovered button? My old project used this tooltip design:

> **[How To Create Tooltips](https://www.w3schools.com/howto/howto_css_tooltip.asp)**
>
> W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

But it causes issues, because it needs to wrap around hovered button and z-index can be problematic with other tooltips/hovereds.

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [February 28, 2023, 6:26pm UTC](https://forum.babylonjs.com/t/made-some-cool-tooltips/38516/7 "2023-02-28T18:26:00Z")

</div>

@Takemura  
Exactly, when a button is hovered.

```
//on gui button (el) hover
tooltip.update(...); // item data
tooltip.show(el._currentMeasure.left, el._currentMeasure.top, el._currentMeasure.width, el._currentMeasure.height);

...
show(x = 0, y = 0, offsetX = 0, offsetY = 0){
    if(this.icon.isLoaded){
        this.container.isVisible = true;
		this.setPosition(x,y,offsetX,offsetY);
    }
    else {
        let _this = this;
        this.icon.onImageLoadedObservable.addOnce(() => {
            _this.container.isVisible = true;
			_this.setPosition(x,y,offsetX,offsetY);
        });
    }
}
setPosition currently waits one render and before updating the left & top properties 
(Needs to measure the new height)

```

I sorted the z-indexing by adding the tooltip directly (and last) on advancedDynamicTexture, other UI parts are separated in simular sub-containers, (lobbyUi, gameUi, tooltipUi)

( Messed up the design for now, excuse that 🙂 )  
 ![tooltipHover](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/2/32940385895f66c866f4f3c4b26f12fb1028c1e8.png)

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [February 28, 2023, 6:37pm UTC](https://forum.babylonjs.com/t/made-some-cool-tooltips/38516/8 "2023-02-28T18:37:18Z")

</div>

Thanks!  
In my case, constitution is just a health stat 🙂

I won’t be sharing it at the moment, but i might do it in the near('ish) future if i get the time.  
i simply don’t have the time to update it to be dynamic right now nor supply support for confusing parts of the code

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [March 3, 2023, 3:45pm UTC](https://forum.babylonjs.com/t/made-some-cool-tooltips/38516/9 "2023-03-03T15:45:09Z")

</div>

Looking great! 😃

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [August 26, 2023, 11:30am UTC](https://forum.babylonjs.com/t/made-some-cool-tooltips/38516/10 "2023-08-26T11:30:54Z")

</div>

Update; Included PG with tooltips!
