# GUI Button width not still computed inside stackpanel

**URL:** <https://forum.babylonjs.com/t/gui-button-width-not-still-computed-inside-stackpanel/22941>\
**Category:** Questions\
**Tags:** gui\
**Created:** [August 9, 2021, 7:27pm UTC](https://forum.babylonjs.com/t/gui-button-width-not-still-computed-inside-stackpanel/22941 "2021-08-09T19:27:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nanney54](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nanney54/32/4831_2.png) [@nanney54](https://forum.babylonjs.com/u/nanney54)\
**Post date:** [August 9, 2021, 7:27pm UTC](https://forum.babylonjs.com/t/gui-button-width-not-still-computed-inside-stackpanel/22941/1 "2021-08-09T19:27:55Z")

</div>

Hello,

I try to make a simple context menu which will open at the pointer position on longpress event.

If pointer position is near the bounding screen (advanced full texture) i check if the pointer position + context menu size is outside bounding screen if true i recompute the position to put the context menu inside screen.

The problem is when the first long press is triggered the width of my context menu seems to be equals to 100% of the screen width instead of the real size.

After that the second long press open the context menu at the good position because size of context menu has been recomputed correctly.

I’ve tried to play with makeDirty methods… with no success.

Is there a way to wait next frame or call a method to force the computation or better solution ?

See methods \_compute… inside method showAt()  
/!\ Don’t forget to press any key to fill the contextmenu  
[https://playground.babylonjs.com/#XCPP9Y#8475](https://playground.babylonjs.com/#XCPP9Y#8475)

Bonus question:  
I guess it is the same kind of problem but the buttons width do not use 100% of the parent. If I use original TextWrapping.WordWrap options the stackpanel take 100% of the screen.

How to have children taking 100% of stackpanel ?

Thanks.

---

<div class="post-metadata">

**Author:** ![thomlucc](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/thomlucc/32/4046_2.png) [@thomlucc](https://forum.babylonjs.com/u/thomlucc)\
**Post date:** [August 10, 2021, 2:07am UTC](https://forum.babylonjs.com/t/gui-button-width-not-still-computed-inside-stackpanel/22941/2 "2021-08-10T02:07:45Z")

</div>

Hi @nanney54 , pinging @msDestiny14 to see if she has an idea.

---

<div class="post-metadata">

**Author:** ![nanney54](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nanney54/32/4831_2.png) [@nanney54](https://forum.babylonjs.com/u/nanney54)\
**Post date:** [August 10, 2021, 9:26am UTC](https://forum.babylonjs.com/t/gui-button-width-not-still-computed-inside-stackpanel/22941/3 "2021-08-10T09:26:21Z")

</div>

I’ve fixed the problem with a temporary ugly piece of code.

[https://playground.babylonjs.com/#XCPP9Y#8486](https://playground.babylonjs.com/#XCPP9Y#8486)

Better approaches are always welcome 🙂
