Setting margins changes the Rect size

Here’s one thing I really dislike about the way Godot handles canvas elements: At 2:40, Yann sets the size of the NinePatchRect to (270, 100). Then at 3:08, he sets the top and left margins to 20. Instead of moving the NinePatchRect down and right by these margin amounts, Godot resizes the NinePatchRect. It now has a size of (250, 80) and Yann has to resize the NinePatchRect again to get the size he wanted.

Just something to keep in mind, I suppose. It’s probably best to set your margins first and then set the size.

Edit: I can see why Godot resizes the control later (at 4:45) when Yann adds a margin to the VBoxContainer. Here, simply moving the VBoxContainer would cause it to extend outside the bounds of the parent NinePathRect. So in this case, resizing the VBoxContainer to accommodate the margins makes perfect sense. While in the previous case, resizing feels wrong and undesirable.

Overall, GUI layout is fiddly, fiddly stuff. I feel like I keeping fighting unexpected behavior on the editor’s part to get my UI elements the way I want them.

Privacy & Terms