How to make text windows (labels) ignore changes in aspect ratio.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bobnew

I am on the learning curve for Godot. I am developing a simple graphics game and so far the graphics perform like I expect.

However, one of the screens in the app is a list of objects, each object has 2 or 3 text entries that give various values for each object. When I dummy-up an example this, I use the following node structure:

- Node2D
  - PanelContainer
    - Scroll Container
       - VBoxContainer
          - Label with text
          - Label with long text that will make the text wrap
          - Label with text, etc.

The intended use this app is for a phone with vertical (portrait) orientation, but to allow the user to use horizontal (landscape) if they desire.

When I start this from the Editor, the list of labels looks fine. When I export it to Android and run on a phone in portrait, there is a small difference in the aspect ratio of the phone, so the text boxes are a different aspect ratio and the text contained in them is stretched per the change in aspect ratio. When I rotate the phone to landscape, the aspect stretch in the text is much more severe: enough to be annoying.

Note: I want this to run with out black bars around the screen, so setting the project setting for stretch aspect to Keep is not really a viable solution.

In the Godot editor, there are many text fields that do not suffer from this stretching effect. For example, when the main screen is not full screen and the Inspector is open to show values for a node, the various text boxes maintain the aspect ratio of the font characters. By stretching/shrinking the main window, the size of the text boxes changes, but the font aspect remains unchanged. Most of the text boxes are single-line-only so they don’t wrap. But a few of the text boxes are wrapping and when the width of a box changes far enough the wrapping points in the text will change.


  • Is there a way in a Godot project to set text boxes so they ignore the aspect changes when the window size changes?
  • Is the fixed font aspect in the Inspector available in a normal Godot app?
  • I notice that everything in the Godot Editor is c++, does this mean that it is all custom code – specific to the editor and not available to the normal app?

Thank You.

:bust_in_silhouette: Reply From: aXu_AP

The ui nodes are a bit hard to wrap one’s head around, but they are flexible - to answer your last question, the editor uses the same ui nodes that are available to you in engine (you can even poke around it via tool/plugin scripts). Godot 4 aims to make the process of learning them a bit less confusing.

I think you may have set some anchors in your PanelContainer the wrong way. Anchors move always proportionally to window size, so they could be the culprit. Set them all to the same value, for example 0. Margins are used to set sizes in pixels.

This is a bit guesswork from my side, it could be something else entirely but I go with my intuition :slight_smile:
If you can’t solve it, could you make some pics of the nodes and their settings (especially PanelContainer’s).

OK. Thanks for the help. I think I was able to get what I need.

bobnew | 2022-10-07 17:29