# UI - positioning elements on scaled root container?

**URL:** <https://forum.babylonjs.com/t/ui-positioning-elements-on-scaled-root-container/22307>\
**Category:** Questions\
**Created:** [July 11, 2021, 10:27pm UTC](https://forum.babylonjs.com/t/ui-positioning-elements-on-scaled-root-container/22307 "2021-07-11T22:27:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericre](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@ericre](https://forum.babylonjs.com/u/ericre)\
**Post date:** [July 11, 2021, 10:27pm UTC](https://forum.babylonjs.com/t/ui-positioning-elements-on-scaled-root-container/22307/1 "2021-07-11T22:27:50Z")

</div>

Hi:  
I am trying to position some controls on a GUI scaled to the window.devicePixelRatio as per the playground example [https://playground.babylonjs.com/#2ARI2W#114](https://playground.babylonjs.com/#2ARI2W#114).

```
engine.setHardwareScalingLevel(1 / window.devicePixelRatio);    
advancedTexture.rootContainer.scaleX = window.devicePixelRatio;
advancedTexture.rootContainer.scaleY = window.devicePixelRatio;

```

How can I specify the position of the upper left corner? if I specify top & left as zero, then and use alignment, the control is drawn off-canvas.

button1.top = 0;  
button1.left = 0;  
button1.verticalAlignment = BABYLON.GUI.Control.VERTICAL\_ALIGNMENT\_TOP;  
button1.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL\_ALIGNMENT\_LEFT;

Thanks,

Eric

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [July 12, 2021, 10:20am UTC](https://forum.babylonjs.com/t/ui-positioning-elements-on-scaled-root-container/22307/2 "2021-07-12T10:20:22Z")

</div>

I don’t think you should update the scaleX/scaleY properties, but I don’t have a device with devicePixelRatio != 1 so I’m not sure.

---

<div class="post-metadata">

**Author:** ![ericre](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@ericre](https://forum.babylonjs.com/u/ericre)\
**Post date:** [July 12, 2021, 4:56pm UTC](https://forum.babylonjs.com/t/ui-positioning-elements-on-scaled-root-container/22307/3 "2021-07-12T16:56:40Z")

</div>

My devicePixelRatio is 2.625. If I don’t update scaleX/scaleY, the UI elements are shrunk down drastically.

Edit: the best workaround I’ve found so far is to not set the scaleX/scaleY properties (as per Evgeni’s suggestion) and instead just manually multiply values width, height, top, left and fontSize by the devicePixelRatio. This does take some care since values such as advancedTexture.getSize().width & height are already multiplied. For example, if I want to place an element 40 px above the bottom of the screen, the calculation for top is: this.advancedTexture.getSize().height - 40 \* window.devicePixelRatio;

BTW: The playground example I am referencing is the “Crisp Text Resolution Example” referenced by the documentation at: [GUI | Babylon.js Documentation](https://doc.babylonjs.com/divingDeeper/gui)

---

<div class="post-metadata">

**Author:** ![DarraghBurke](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/darraghburke/32/10621_2.png) [@DarraghBurke](https://forum.babylonjs.com/u/DarraghBurke)\
**Post date:** [July 12, 2021, 8:48pm UTC](https://forum.babylonjs.com/t/ui-positioning-elements-on-scaled-root-container/22307/4 "2021-07-12T20:48:38Z")

</div>

Going to add our UI expert @msDestiny14 on this one

---

<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 13, 2021, 4:48pm UTC](https://forum.babylonjs.com/t/ui-positioning-elements-on-scaled-root-container/22307/5 "2021-07-13T16:48:05Z")

</div>

Don’t know if this could be what you are looking for but using  
advancedTexture.idealWidth  
advancedTexture.renderAtIdealSize

might be something to take a look at? Assuming you know the size you need.🙂

---

<div class="post-metadata">

**Author:** ![tibotiber](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tibotiber/32/26735_2.png) [@tibotiber](https://forum.babylonjs.com/u/tibotiber)\
**Post date:** [August 13, 2021, 10:46am UTC](https://forum.babylonjs.com/t/ui-positioning-elements-on-scaled-root-container/22307/6 "2021-08-13T10:46:06Z")

</div>

Hi @ericre, I’m having the same issue and found this thread very informative: [Proper way to support HDPI/Retina display at full resolution and scaled properly?](https://forum.babylonjs.com/t/proper-way-to-support-hdpi-retina-display-at-full-resolution-and-scaled-properly/14075). Hope it helps.

---

<div class="post-metadata">

**Author:** ![tibotiber](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tibotiber/32/26735_2.png) [@tibotiber](https://forum.babylonjs.com/u/tibotiber)\
**Post date:** [August 16, 2021, 2:26am UTC](https://forum.babylonjs.com/t/ui-positioning-elements-on-scaled-root-container/22307/7 "2021-08-16T02:26:51Z")

</div>

I’ve played with this a few days and posted something related that could help: [Billboard UI with zoom based scaling (including retina screens)](https://forum.babylonjs.com/t/billboard-ui-with-zoom-based-scaling-including-retina-screens/23094)
