# GUI control inline alignment

**URL:** <https://forum.babylonjs.com/t/gui-control-inline-alignment/22662>\
**Category:** Questions\
**Created:** [July 28, 2021, 6:13pm UTC](https://forum.babylonjs.com/t/gui-control-inline-alignment/22662 "2021-07-28T18:13:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mercurio](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mercurio/32/23383_2.png) [@Mercurio](https://forum.babylonjs.com/u/Mercurio)\
**Post date:** [July 28, 2021, 6:13pm UTC](https://forum.babylonjs.com/t/gui-control-inline-alignment/22662/1 "2021-07-28T18:13:57Z")

</div>

HI there,  
i’m facing problems to align some GUI control.  
In my project i have a grid with some row. In some row i have to align a TextBlock with an input: the goal is to use the TextBlock as a label for the input control, so the input control has to be aligned after the textBlock.  
This is my PG:[Babylon.js Playground](https://playground.babylonjs.com/#L3L73N)

I try to calculate the width of the text block and then placing the input using `leftInPixels`, but it seems not to work.  
What’s the best practice to do that?  
Thank’s in advance 😉

EDIT: i’ve added some logs: [https://playground.babylonjs.com/#L3L73N#1](https://playground.babylonjs.com/#L3L73N#1)  
Why in the logged object `width` and `widthInPixels` has the right value but i read always zero?

---

<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:** [July 28, 2021, 11:00pm UTC](https://forum.babylonjs.com/t/gui-control-inline-alignment/22662/2 "2021-07-28T23:00:14Z")

</div>

Hi @Mercurio, maybe @msDestiny14 can help on this UI question.

---

<div class="post-metadata">

**Author:** ![msDestiny14](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/msdestiny14/32/9572_2.png) [@msDestiny14](https://forum.babylonjs.com/u/msDestiny14)\
**Post date:** [July 29, 2021, 2:03am UTC](https://forum.babylonjs.com/t/gui-control-inline-alignment/22662/3 "2021-07-29T02:03:13Z")

</div>

Sorry I’m having a slighty hard time figuring out what specifically you want it to look like.

If I’m interpreting it wrong please let me know! How I think you want is it some label with then the input box next to it. [https://playground.babylonjs.com/#L3L73N#2](https://playground.babylonjs.com/#L3L73N#2) I noticed you had 2 rows and 2 columns. I changed it to 1 row with 2 columns and aligned the input on the left in the second column.

---

<div class="post-metadata">

**Author:** ![Mercurio](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mercurio/32/23383_2.png) [@Mercurio](https://forum.babylonjs.com/u/Mercurio)\
**Post date:** [July 29, 2021, 7:17am UTC](https://forum.babylonjs.com/t/gui-control-inline-alignment/22662/4 "2021-07-29T07:17:37Z")

</div>

Thank you @msDestiny14 ,

> [@msDestiny14](#):
>
> How I think you want is it some label with then the input box next to it.

Yes it’s exactly what i want.  
So i’ve always to use grid for alignment? I thought to play with widthInPixels but it reads always zero.

> [@Mercurio](#):
>
> Why in the logged object `width` and `widthInPixels` has the right value but i read always zero?

Is it a bug?  
Thank you.

---

<div class="post-metadata">

**Author:** ![msDestiny14](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/msdestiny14/32/9572_2.png) [@msDestiny14](https://forum.babylonjs.com/u/msDestiny14)\
**Post date:** [July 30, 2021, 3:42am UTC](https://forum.babylonjs.com/t/gui-control-inline-alignment/22662/5 "2021-07-30T03:42:33Z")

</div>

Where are you looking for width and widthInPixels? Don’t quite understand.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/5/f/5fc340e30a93d9ce8ac63aa567654d8c0c5dc46a.png)

looks correct in the inspector.

---

<div class="post-metadata">

**Author:** ![Mercurio](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mercurio/32/23383_2.png) [@Mercurio](https://forum.babylonjs.com/u/Mercurio)\
**Post date:** [July 30, 2021, 8:59am UTC](https://forum.babylonjs.com/t/gui-control-inline-alignment/22662/6 "2021-07-30T08:59:47Z")

</div>

Programmatically if you try to read `label.widthInPixels` it reads always zero.  
You can try also in the last PG you have published.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [July 30, 2021, 2:06pm UTC](https://forum.babylonjs.com/t/gui-control-inline-alignment/22662/7 "2021-07-30T14:06:15Z")

</div>

Assigned @msDestiny14 on July 30, 2021, 2:06pm UTC



---

<div class="post-metadata">

**Author:** ![msDestiny14](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/msdestiny14/32/9572_2.png) [@msDestiny14](https://forum.babylonjs.com/u/msDestiny14)\
**Post date:** [July 30, 2021, 3:59pm UTC](https://forum.babylonjs.com/t/gui-control-inline-alignment/22662/8 "2021-07-30T15:59:40Z")

</div>

Ah yes! Now I understand what you’re asking. The reason is because of text and resizeToFit. This will not be calculated until render time.

[https://playground.babylonjs.com/#L3L73N#3](https://playground.babylonjs.com/#L3L73N#3)

Modified this example to show on the engine loop gives the correct size because now it has been rendered.

---

<div class="post-metadata">

**Author:** ![Mercurio](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mercurio/32/23383_2.png) [@Mercurio](https://forum.babylonjs.com/u/Mercurio)\
**Post date:** [August 2, 2021, 7:06am UTC](https://forum.babylonjs.com/t/gui-control-inline-alignment/22662/9 "2021-08-02T07:06:42Z")

</div>

Thakyou @msDestiny14 😉

---

<div class="post-metadata">

**Author:** ![msDestiny14](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/msdestiny14/32/9572_2.png) [@msDestiny14](https://forum.babylonjs.com/u/msDestiny14)\
**Post date:** [August 9, 2021, 4:30pm UTC](https://forum.babylonjs.com/t/gui-control-inline-alignment/22662/10 "2021-08-09T16:30:38Z")

</div>

Unassigned @msDestiny14 on August 9, 2021, 4:30pm UTC


