# Not sure how to support different screen resolutions with GUI

**URL:** <https://forum.babylonjs.com/t/not-sure-how-to-support-different-screen-resolutions-with-gui/965>\
**Category:** Questions\
**Tags:** gui\
**Created:** [January 26, 2019, 6:15pm UTC](https://forum.babylonjs.com/t/not-sure-how-to-support-different-screen-resolutions-with-gui/965 "2019-01-26T18:15:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zephos](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/zephos/32/50_2.png) [@Zephos](https://forum.babylonjs.com/u/Zephos)\
**Post date:** [January 26, 2019, 6:15pm UTC](https://forum.babylonjs.com/t/not-sure-how-to-support-different-screen-resolutions-with-gui/965/1 "2019-01-26T18:15:29Z")

</div>

I am making a non trivial full screen gui with Babylon GUI and I am having a graphic designer make images to use as the background on all the components. The one concern I have though is that I don’t understand how babylon gui behaves on different resolutions or if it is even possible to make it responsive, etc.

Right now I am defining the dimensions of all my outer components in pixels and putting them in a full screen GUI layer.

I guess I need to know:

If I define them as percentages, how should I define children controls?  
Can I set a minimum value for width and height?  
Can I set a maximum value?  
How does the fixed resolution feature work? The docs didn’t help me understand what that feature does, exactly.

Any examples would be great too. THanks!

EDIT: So I did find the section on adaptive scaling in the docs (for some reason it didn’t make sense before but now it does) and that might do what I need, but in playing with it I am not sure how it handles text. Some text seems to scale while other text doesn’t. Is this because the controls the text are in are not always sized in pixels?

Thanks.

---

<div class="post-metadata">

**Author:** ![Rah](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rah/32/201_2.png) [@Rah](https://forum.babylonjs.com/u/Rah)\
**Post date:** [January 28, 2019, 1:09pm UTC](https://forum.babylonjs.com/t/not-sure-how-to-support-different-screen-resolutions-with-gui/965/2 "2019-01-28T13:09:31Z")

</div>

try using canvis.height and canvis.width as your units. They return pixels i believe, then for example you could just use 50% of the width, so 0.5\*canvis.width

---

<div class="post-metadata">

**Author:** ![Wingnut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wingnut/32/53_2.png) [@Wingnut](https://forum.babylonjs.com/u/Wingnut)\
**Post date:** [January 28, 2019, 2:17pm UTC](https://forum.babylonjs.com/t/not-sure-how-to-support-different-screen-resolutions-with-gui/965/3 "2019-01-28T14:17:49Z")

</div>

Hi guys.

[perhaps some info here.](https://forum.babylonjs.com/t/help-recover-my-gui-after-canvas-resize-plus-more/602)

I was working with a diagram that needed to survive canvas resize, and sebavan helped me out… with some resize observers.

I think… you can simulate different resolutions… by drag-resizing your browser window.

For testing, I opened my f12 dev-tools and dragged its horizontal divider… up/down. And I dragged the divider between playground editor and canvas… as another test. This allows for full-power in-playground resolution-testing, I think.

Also, you might wish to research _idealWidth_ and _idealHeight_. I’m not sure what they are used-for, but they sure have interesting names. 🙂

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [January 28, 2019, 4:21pm UTC](https://forum.babylonjs.com/t/not-sure-how-to-support-different-screen-resolutions-with-gui/965/4 "2019-01-28T16:21:17Z")

</div>

Other option is to only deal with percentage and never use pixels

---

<div class="post-metadata">

**Author:** ![Zephos](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/zephos/32/50_2.png) [@Zephos](https://forum.babylonjs.com/u/Zephos)\
**Post date:** [January 30, 2019, 3:22am UTC](https://forum.babylonjs.com/t/not-sure-how-to-support-different-screen-resolutions-with-gui/965/5 "2019-01-30T03:22:47Z")

</div>

What is the best way to scale text in buttons and text blocks appropriately, whether I am doing the adaptive scaling or using percentages? From what I have seen and done so far, text never scales with everything else.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [January 30, 2019, 3:58pm UTC](https://forum.babylonjs.com/t/not-sure-how-to-support-different-screen-resolutions-with-gui/965/6 "2019-01-30T15:58:15Z")

</div>

Font can also be expressed using percentage 🙂

---

<div class="post-metadata">

**Author:** ![Zephos](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/zephos/32/50_2.png) [@Zephos](https://forum.babylonjs.com/u/Zephos)\
**Post date:** [January 31, 2019, 9:23pm UTC](https://forum.babylonjs.com/t/not-sure-how-to-support-different-screen-resolutions-with-gui/965/7 "2019-01-31T21:23:15Z")

</div>

I did not know that. Thanks!

---

<div class="post-metadata">

**Author:** ![j-te](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/j-te/32/37194_2.png) [@j-te](https://forum.babylonjs.com/u/j-te)\
**Post date:** [August 17, 2020, 8:30pm UTC](https://forum.babylonjs.com/t/not-sure-how-to-support-different-screen-resolutions-with-gui/965/8 "2020-08-17T20:30:58Z")

</div>

In my case I just needed to resize two aligned images if canvas width \< 480px. I did this by setting the .width and .height properties in a custom function using `.onBeforeDrawObservable.add()`

I added a bool state check to only resize if the canvas width has changed - not profiled this but may help.

Only one observable is required if resizing multiple controls but note ref dependencies. It’s probably a better idea to resize a parent container (or rectangle) where the children scale accordingly.

```auto
const myImageOnlyButton = new GUI.Button.CreateImageOnlyButton("myImageOnlyButton", "https://path.to.image.png");

myImageOnlyButton.onBeforeDrawObservable.add(() => resizeControl(myImageOnlyButton, 256, 80));

let previousCanvasWidth = canvasRef.width;

function resizeControl(control, desiredWidth, desiredHeight) {
  const newCanvasWidth = canvasRef.width;
  const hasWidthChanged = previousCanvasWidth !== newCanvasWidth;
  if (hasWidthChanged && canvasRef.width < 480) {
    control.widthInPixels = desiredWidth / 1.5;
    control.heightInPixels = desiredHeight / 1.5;
  } else if (hasWidthChanged) {
    control.widthInPixels = desiredWidth;
    control.heightInPixels = desiredHeight;
  }
  previousCanvasWidth = newCanvasWidth; // Need to reset
}

```
