A custom Container node for Godot Egine 4.x which limits the size of child nodes.
All Control nodes have a rect_min_size
property, but they lack rect_max_size
. MaxSizeContainer addresses this issue.
About | Current Release |
---|---|
Version | 1.3 |
Date | August 9, 2023 |
Platform | Godot 4.x (tested on 4.2-dev2) |
License | MIT License |
Authors | Matthieu Huvé (Godot 3.x original) Benedikt Wicklein (Godot 4 Beta) Brom Bresenham (Godot 4.x) |
- Copy
addons/MaxSizeContainer
into your project (final path should beres://addons/MaxSizeContainer
).
- In the Godot Editor, go to Project Settings > Plugins and enable the MaxSizeContainer plugin.
To be limited in size, a Control node must be child of a MaxSizeContainer.
- From the editor, press Add a new node, and select MaxSizeContainer
Note: to add the Container from script, you must use this code:
var MaxSizeContainer = preload("res://addons/MaxSizeContainer/max_size_container.gd")
add_child(MaxSizeContainer.new())
- Add any Control node as a child of MaxSizeContainer.
Note: only one child is supported
- Select the mode, the limit (pixel size or aspect ratio, depending on the mode), and how you want the child node aligned when it reaches the maximum size. (In Pixel Size mode, -1 means no limit)
(Screenshots from older version)
- Let's start from this scene.
Scene tree | Small window | Large window |
When the window is enlarged, the main scene takes all the available space, as it is set as Expand.
- To prevent that and make the text more readable, let's add a MaxSizeContainer, child of
MainScreen (ScrollContainer)
and parent ofVBoxContainer
:
Scene tree | Parameters | Large window |
- You can also nest different MaxSizeContainers together, and have fun:
Scene tree and parameters | Large window |
If the container doesn't work, try these solutions:
- Make sure there is only one child node, and it inherits from Control
- Make sure the child node's size flag are set to Fill vertically and horizontally.
- Make sure
max_size
is bigger than the minimum possible size of the child.
See License file This README page was greatly inspired by jmb462.