+1 vote

This is apparently harder than it might seem at first. This repo has my current attempt -- obviously there's something obvious I'm missing, but I can't quite figure out how the margins interact with the various containers.

Cut and paste from the README.md:

Requirements:

  1. Box remains at fixed width
  2. Text can be arbitrarily long (within reason; not pasting the text of Moby Dick in there)
  3. InfoBox resizes itself to accommodate longer text
  4. InfoBox has a colored background
  5. Text is set away from edges of the box by margins.

1-3 are accomplished by putting the label inside a VBoxContainer. Alas, VBoxContainers cannot themselves be styled, so I put it inside of a PanelContainer to give the colored background, satisfying 4.

Number 5 is where I run into problems. I cannot figure out the logic of what margins are allowed to be set and which are fixed. If I try to change the margins on the VBoxContainer, they snap back. At one point I had the margins set up properly but they went back to zero once the text changed. (I can't reproduce this at the moment.)

Screenshot of current setup

in Engine by (24 points)

1 Answer

+1 vote
Best answer

Solved this with some help from Reddit.

The answer is the MarginContainer, as I had hoped, but the trick is noting that the part of MarginContainer that works its magic is in the Custom Constants, not the regular margins.

by (24 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.